ws2_32/tests: Fix a race in sock.c:test_write_events().

Francois Gouget fgouget at free.fr
Thu Sep 11 09:53:43 CDT 2008


Stop draining the socket to make sure we will be able to fill the send 
buffer and trigger a short write.
---

Without this patch we have a race between the thread that tries to fill 
the send buffer, and the thread that drains it. This caused the test to 
time out on my XP machine.


 dlls/ws2_32/tests/sock.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 0643d00..5ee7918 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -2016,6 +2016,7 @@ static void test_ioctlsocket(void)
     }
 }
 
+static int drain_pause=0;
 static DWORD WINAPI drain_socket_thread(LPVOID arg)
 {
     char buffer[1024];
@@ -2032,6 +2033,8 @@ static DWORD WINAPI drain_socket_thread(LPVOID arg)
                 FD_ZERO(&readset);
                 FD_SET(sock, &readset);
                 select(0, &readset, NULL, NULL, NULL);
+                while (drain_pause)
+                    Sleep(100);
             }
             else
                 break;
@@ -2184,13 +2187,17 @@ static void test_write_events(void)
         goto end;
     }
 
-    /* Now if we send a tonne of data, the socket send buffer will only take some of it,
-       and we will get a short write, which will trigger another FD_WRITE event
-       as soon as data is sent and more space becomes available, but not any earlier. */
+    /* Now if we send a ton of data and the 'server' does not drain it fast
+     * enough (set drain_pause to be sure), the socket send buffer will only
+     * take some of it, and we will get a short write. This will trigger
+     * another FD_WRITE event as soon as data is sent and more space becomes
+     * available, but not any earlier. */
+    drain_pause=1;
     do
     {
         ret = send(src, buffer, bufferSize, 0);
     } while (ret == bufferSize);
+    drain_pause=0;
     if (ret >= 0 || WSAGetLastError() == WSAEWOULDBLOCK)
     {
         dwRet = WaitForSingleObject(hEvent, 5000);
-- 
1.5.6.3



More information about the wine-patches mailing list