[Wine-patches] [eterhack] ws2_32: Use a little timeout in non-blocking mode (eterbug #6915).

Alexander Morozov amorozov на etersoft.ru
Ср Мар 23 16:20:36 MSK 2011


----------- следующая часть -----------
From 5850cc7be81f712c58ee24c3873960555f807a06 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Wed, 23 Mar 2011 16:07:32 +0300
Subject: [eterhack] ws2_32: Use a little timeout in non-blocking mode (eterbug #6915).

---
 dlls/ws2_32/socket.c |   67 ++++++++++++++++++++++---------------------------
 1 files changed, 30 insertions(+), 37 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index d794064..786cafe 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -3950,6 +3950,7 @@ static int WS2_sendto( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount,
     int n, fd, err;
     struct ws2_async *wsa;
     int totalLength = 0;
+    DWORD timeout_start;
     ULONG_PTR cvalue = (lpOverlapped && ((ULONG_PTR)lpOverlapped->hEvent & 1) == 0) ? (ULONG_PTR)lpOverlapped : 0;
 
     TRACE("socket %04lx, wsabuf %p, nbufs %d, flags %d, to %p, tolen %d, ovl %p, func %p\n",
@@ -4052,55 +4053,47 @@ static int WS2_sendto( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount,
         return 0;
     }
 
-    if ( _is_blocking(s) )
+    timeout_start = GetTickCount();
+    *lpNumberOfBytesSent = n == -1 ? 0 : n;
+
+    while (wsa->first_iovec < wsa->n_iovecs)
     {
-        /* On a blocking non-overlapped stream socket,
-         * sending blocks until the entire buffer is sent. */
-        DWORD timeout_start = GetTickCount();
+        struct pollfd pfd;
+        int timeout = 50;
 
-        *lpNumberOfBytesSent = n == -1 ? 0 : n;
+        if ( _is_blocking(s) )
+            timeout = GET_SNDTIMEO(fd);
 
-        while (wsa->first_iovec < wsa->n_iovecs)
+        if (timeout != -1)
         {
-            struct pollfd pfd;
-            int timeout = GET_SNDTIMEO(fd);
-
-            if (timeout != -1)
-            {
-                timeout -= GetTickCount() - timeout_start;
-                if (timeout < 0) timeout = 0;
-            }
-
-            pfd.fd = fd;
-            pfd.events = POLLOUT;
+            timeout -= GetTickCount() - timeout_start;
+            if (timeout < 0) timeout = 0;
+        }
 
-            if (!timeout || check_eterbug3421() || !poll( &pfd, 1, timeout ))
-            {
-                err = WSAETIMEDOUT;
-                goto error; /* msdn says a timeout in send is fatal */
-            }
+        pfd.fd = fd;
+        pfd.events = POLLOUT;
 
-            n = WS2_send( fd, wsa );
-            if (n == -1 && errno != EAGAIN && errno != EINTR)
+        if (!timeout || check_eterbug3421() || !poll( &pfd, 1, timeout ))
+        {
+            if ( !_is_blocking(s) )
             {
-                err = wsaErrno();
-                goto error;
+                _enable_event( SOCKET2HANDLE(s), FD_WRITE, 0, 0 );
+                if (n >= 0) break;
+                err = WSAEWOULDBLOCK;
             }
-
-            if (n >= 0)
-                *lpNumberOfBytesSent += n;
+            else err = WSAETIMEDOUT;
+            goto error; /* msdn says a timeout in send is fatal */
         }
-    }
-    else  /* non-blocking */
-    {
-        if (n < totalLength)
-            _enable_event(SOCKET2HANDLE(s), FD_WRITE, 0, 0);
-        if (n == -1)
+
+        n = WS2_send( fd, wsa );
+        if (n == -1 && errno != EAGAIN && errno != EINTR)
         {
-            err = WSAEWOULDBLOCK;
+            err = wsaErrno();
             goto error;
         }
-        *lpNumberOfBytesSent = n;
+
+        if (n >= 0)
+            *lpNumberOfBytesSent += n;
     }
 
     TRACE(" -> %i bytes\n", *lpNumberOfBytesSent);
-- 
1.7.4.1



Подробная информация о списке рассылки Wine-patches