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

Alexander Morozov amorozov на etersoft.ru
Вт Июл 26 19:41:33 MSD 2011


Забыл [eterhack]
----------- следующая часть -----------
From 4b3c505e2e04159d7acbe41a88f9cba82c8447ff Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Tue, 26 Jul 2011 18:46:37 +0400
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 c67295a..3f2ad2c 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -3878,6 +3878,7 @@ static int WS2_sendto( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount,
     int n, fd, err;
     struct ws2_async *wsa = NULL;
     int totalLength = 0;
+    DWORD timeout_start;
     ULONG_PTR cvalue = (lpOverlapped && ((ULONG_PTR)lpOverlapped->hEvent & 1) == 0) ? (ULONG_PTR)lpOverlapped : 0;
     DWORD bytes_sent;
 
@@ -3980,55 +3981,47 @@ static int WS2_sendto( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount,
         return 0;
     }
 
-    if ( _is_blocking(s) )
+    timeout_start = GetTickCount();
+    bytes_sent = 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;
 
-        bytes_sent = 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;
-            }
+            timeout -= GetTickCount() - timeout_start;
+            if (timeout < 0) timeout = 0;
+        }
 
-            pfd.fd = fd;
-            pfd.events = POLLOUT;
+        pfd.fd = fd;
+        pfd.events = POLLOUT;
 
-            if (!timeout || check_eterbug3421() || !poll( &pfd, 1, timeout ))
-            {
-                err = WSAETIMEDOUT;
-                goto error; /* msdn says a timeout in send is fatal */
-            }
-
-            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)
-                bytes_sent += 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;
         }
-        bytes_sent = n;
+
+        if (n >= 0)
+            bytes_sent += n;
     }
 
     TRACE(" -> %i bytes\n", bytes_sent);
-- 
1.7.5.4



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