changeset 546:5d13fa48c275

2004-9-6 Brian Masney <masneyb@gftp.org> * lib/protocols.c lib/sshv2.c lib/sslcommon.c - cleanups to the functions that write/read to/from the network. Retry the operation if EAGAIN is returned * lib/ftps.c - return an error if the SSL session cannot be setup properly
author masneyb
date Wed, 08 Sep 2004 00:18:10 +0000
parents e850102b64be
children 34a3f10d8bae
files ChangeLog lib/ftps.c lib/protocols.c lib/sshv2.c lib/sslcommon.c
diffstat 5 files changed, 70 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Sep 07 23:30:40 2004 +0000
+++ b/ChangeLog	Wed Sep 08 00:18:10 2004 +0000
@@ -1,4 +1,11 @@
 2004-9-6 Brian Masney <masneyb@gftp.org>
+	* lib/protocols.c lib/sshv2.c lib/sslcommon.c - cleanups to the
+	functions that write/read to/from the network. Retry the operation
+	if EAGAIN is returned
+
+	* lib/ftps.c - return an error if the SSL session cannot be setup
+	properly
+
 	* autogen.sh - updated autogen.sh so that it will work with newer
 	versions of automake/autoconf
 
@@ -2794,7 +2801,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.316 2004/09/07 23:30:40 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.317 2004/09/08 00:18:09 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/lib/ftps.c	Tue Sep 07 23:30:40 2004 +0000
+++ b/lib/ftps.c	Wed Sep 08 00:18:10 2004 +0000
@@ -64,7 +64,7 @@
   if (ret < 0)
     return (ret);
   else if (ret != '2')
-    return (0);
+    return (GFTP_EFATAL);
 
   if ((ret = gftp_ssl_session_setup (request)) < 0)
     return (ret);
--- a/lib/protocols.c	Tue Sep 07 23:30:40 2004 +0000
+++ b/lib/protocols.c	Wed Sep 08 00:18:10 2004 +0000
@@ -2487,19 +2487,22 @@
   errno = 0;
   ret = 0;
 
-  while (1)
+  do
     {
       FD_ZERO (&fset);
       FD_SET (fd, &fset);
       tv.tv_sec = network_timeout;
       tv.tv_usec = 0;
       ret = select (fd + 1, &fset, NULL, NULL, &tv);
-      if (ret == -1 && errno == EINTR)
+      if (ret == -1 && (errno == EINTR || errno == EAGAIN))
         {
-          if (request && request->cancel)
-            break;
-          else
-            continue;
+          if (request != NULL && request->cancel)
+            {
+              gftp_disconnect (request);
+              return (GFTP_ERETRYABLE);
+            }
+
+          continue;
         }
       else if (ret <= 0)
         {
@@ -2510,17 +2513,21 @@
                                          request->hostname);
               gftp_disconnect (request);
             }
+
           return (GFTP_ERETRYABLE);
         }
 
       if ((ret = read (fd, ptr, size)) < 0)
         {
-          if (errno == EINTR)
+          if (errno == EINTR || errno == EAGAIN)
             {
               if (request != NULL && request->cancel)
-                break;
-              else
-                continue;
+                {
+                  gftp_disconnect (request);
+                  return (GFTP_ERETRYABLE);
+                }
+
+              continue;
             }
  
           if (request != NULL)
@@ -2530,16 +2537,13 @@
                                     g_strerror (errno));
               gftp_disconnect (request);
             }
+
           return (GFTP_ERETRYABLE);
         }
+
       break;
     }
-
-  if (errno == EINTR && request != NULL && request->cancel)
-    {
-      gftp_disconnect (request);
-      return (GFTP_ERETRYABLE);
-    }
+  while (1);
 
   return (ret);
 }
@@ -2565,12 +2569,15 @@
       tv.tv_sec = network_timeout;
       tv.tv_usec = 0;
       ret = select (fd + 1, NULL, &fset, NULL, &tv);
-      if (ret == -1 && errno == EINTR)
+      if (ret == -1 && (errno == EINTR || errno == EAGAIN))
         {
           if (request != NULL && request->cancel)
-            break;
-          else
-            continue;
+            {
+              gftp_disconnect (request);
+              return (GFTP_ERETRYABLE);
+            }
+
+          continue;
         }
       else if (ret <= 0)
         {
@@ -2581,18 +2588,22 @@
                                          request->hostname);
               gftp_disconnect (request);
             }
+
           return (GFTP_ERETRYABLE);
         }
 
       w_ret = write (fd, ptr, size);
       if (w_ret < 0)
         {
-          if (errno == EINTR)
+          if (errno == EINTR || errno == EAGAIN)
             {
               if (request != NULL && request->cancel)
-                break;
-              else
-                continue;
+                {
+                  gftp_disconnect (request);
+                  return (GFTP_ERETRYABLE);
+                }
+
+              continue;
              }
  
           if (request != NULL)
@@ -2602,6 +2613,7 @@
                                     g_strerror (errno));
               gftp_disconnect (request);
             }
+
           return (GFTP_ERETRYABLE);
         }
 
@@ -2611,12 +2623,6 @@
     }
   while (size > 0);
 
-  if (errno == EINTR && request != NULL && request->cancel)
-    {
-      gftp_disconnect (request);
-      return (GFTP_ERETRYABLE);
-    }
-
   return (ret);
 }
 
@@ -2823,7 +2829,7 @@
                 {
                   ret1 = select (0, NULL, NULL, NULL, &tv);
                 }
-              while (ret1 == -1 && errno == EINTR);
+              while (ret1 == -1 && (errno == EINTR || errno == EAGAIN));
             }
 
           if ((ret1 = gftp_connect (tdata->fromreq)) == 0 &&
--- a/lib/sshv2.c	Tue Sep 07 23:30:40 2004 +0000
+++ b/lib/sshv2.c	Wed Sep 08 00:18:10 2004 +0000
@@ -346,7 +346,7 @@
       FD_SET (ptymfd, &eset);
 
       ret = select (maxfd + 1, &rset, NULL, &eset, NULL);
-      if (ret < 0 && errno == EINTR)
+      if (ret < 0 && (errno == EINTR || errno == EAGAIN))
         continue;
 
       if (ret < 0)
--- a/lib/sslcommon.c	Tue Sep 07 23:30:40 2004 +0000
+++ b/lib/sslcommon.c	Wed Sep 08 00:18:10 2004 +0000
@@ -408,6 +408,8 @@
   ssize_t ret;
   int err;
 
+  g_return_val_if_fail (request->ssl != NULL, GFTP_EFATAL);
+
   if (!gftp_ssl_initialized)
     {
       request->logging_function (gftp_logging_error, request,
@@ -422,13 +424,16 @@
       if ((ret = SSL_read (request->ssl, ptr, size)) < 0)
         { 
           err = SSL_get_error (request->ssl, ret);
-          if (errno == EINTR)
+          if (errno == EINTR || errno == EAGAIN)
             {
               if (request->cancel)
-                break;
-              else
-                continue;
-             }
+                {
+                  gftp_disconnect (request);
+                  return (GFTP_ERETRYABLE);
+                }
+
+              continue;
+            }
  
           request->logging_function (gftp_logging_error, request,
                                    _("Error: Could not read from socket: %s\n"),
@@ -437,14 +442,10 @@
 
           return (GFTP_ERETRYABLE);
         }
+
+      break;
     }
-  while (errno == EINTR && !(request != NULL && request->cancel));
-
-  if (errno == EINTR && request != NULL && request->cancel)
-    {
-      gftp_disconnect (request);
-      return (GFTP_ERETRYABLE);
-    }
+  while (1);
 
   return (ret);
 }
@@ -455,6 +456,8 @@
 {
   size_t ret, w_ret;
  
+  g_return_val_if_fail (request->ssl != NULL, GFTP_EFATAL);
+
   if (!gftp_ssl_initialized)
     {
       request->logging_function (gftp_logging_error, request,
@@ -468,12 +471,15 @@
       w_ret = SSL_write (request->ssl, ptr, size);
       if (w_ret <= 0)
         {
-          if (errno == EINTR)
+          if (errno == EINTR || errno == EAGAIN)
             {
               if (request != NULL && request->cancel)
-                break;
-              else
-                continue;
+                {
+                  gftp_disconnect (request);
+                  return (GFTP_ERETRYABLE);
+                }
+
+              continue;
              }
  
           request->logging_function (gftp_logging_error, request,
@@ -483,18 +489,13 @@
 
           return (GFTP_ERETRYABLE);
         }
+
       ptr += w_ret;
       size -= w_ret;
       ret += w_ret;
     }
   while (size > 0);
 
-  if (errno == EINTR && request != NULL && request->cancel)
-    {
-      gftp_disconnect (request);
-      return (GFTP_ERETRYABLE);
-    }
-
   return (ret);
 }