2008/9/12, E L <[EMAIL PROTECTED]> wrote:

> The libssh2 code is not getting the real socket errors in most cases.
> After calling send() or recv(), it is assuming errno will be set, but
> Windows does not set errno for socket functions.  If the connection
> gets reset, the call to send() or recv() will fail, but there is a
> good chance errno will still be set to EAGAIN, so the code will keep
> trying indefinititely.

Yes the real problem is that errno is not being cleared for WIN32 if
the call to recv() or send() succeeds!

> patch is included below to set errno for all send() and recv()

Your patch was real close, but it doesn't address the above statement.

Could you verify if the attached patch works fine for you, and report
back to the list, so that someone might commit it to CVS ?

-- 
-=[Yang]=-
Index: src/session.c
===================================================================
RCS file: /cvsroot/libssh2/libssh2/src/session.c,v
retrieving revision 1.53
diff -u -r1.53 session.c
--- src/session.c       2 Jan 2008 14:48:48 -0000       1.53
+++ src/session.c       12 Sep 2008 19:11:55 -0000
@@ -110,28 +110,29 @@
         ret =
             recv(session->socket_fd, &c, 1,
                  LIBSSH2_SOCKET_RECV_FLAGS(session));
-
-        if (ret < 0) {
 #ifdef WIN32
-            switch (WSAGetLastError()) {
+        {
+            int sockerrno = WSAGetLastError();
+            switch (sockerrno) {
             case WSAEWOULDBLOCK:
                 errno = EAGAIN;
                 break;
-
             case WSAENOTSOCK:
                 errno = EBADF;
                 break;
-
             case WSAENOTCONN:
             case WSAECONNABORTED:
                 errno = WSAENOTCONN;
                 break;
-
             case WSAEINTR:
                 errno = EINTR;
                 break;
+            default:
+                errno = sockerrno;
             }
+        }
 #endif /* WIN32 */
+        if (ret < 0) {
             if (errno == EAGAIN) {
                 session->banner_TxRx_total_send = banner_len;
                 return PACKET_EAGAIN;
Index: src/transport.c
===================================================================
RCS file: /cvsroot/libssh2/libssh2/src/transport.c,v
retrieving revision 1.13
diff -u -r1.13 transport.c
--- src/transport.c     8 Nov 2007 13:51:23 -0000       1.13
+++ src/transport.c     12 Sep 2008 19:11:56 -0000
@@ -327,29 +327,31 @@
                 recv(session->socket_fd, &p->buf[remainbuf],
                      PACKETBUFSIZE - remainbuf,
                      LIBSSH2_SOCKET_RECV_FLAGS(session));
-            if (nread <= 0) {
-                /* check if this is due to EAGAIN and return the special
-                   return code if so, error out normally otherwise */
 #ifdef WIN32
-                switch (WSAGetLastError()) {
+            {
+                int sockerrno = WSAGetLastError();
+                switch (sockerrno) {
                 case WSAEWOULDBLOCK:
                     errno = EAGAIN;
                     break;
-
                 case WSAENOTSOCK:
                     errno = EBADF;
                     break;
-
                 case WSAENOTCONN:
                 case WSAECONNABORTED:
                     errno = WSAENOTCONN;
                     break;
-
                 case WSAEINTR:
                     errno = EINTR;
                     break;
+                default:
+                    errno = sockerrno;
                 }
+            }
 #endif /* WIN32 */
+            if (nread <= 0) {
+                /* check if this is due to EAGAIN and return the special
+                   return code if so, error out normally otherwise */
                 if ((nread < 0) && (errno == EAGAIN)) {
                     return PACKET_EAGAIN;
                 }
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
libssh2-devel mailing list
libssh2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel

Reply via email to