ws2_32 fixes

Francois Gouget fgouget at free.fr
Wed Sep 12 18:00:26 CDT 2001


   In Windows select is not supposed to modify the timeout parameter
(it's a const). But on Linux select will modify this parameter so that
when select exits it only contains the remaining time until a potential
timeout (Linux is about the only one to do that, but generally speaking
timeout cannot be trusted after a call to select). So if a windows
application were to initialize a timeout struct, and keep using it
without reinitializing it (since it wants to use the same timeout over
and over), it would soon have a zero timeout. Oups.


Changelog:

 * include/winsock.h,
   dlls/winsock/socket.c

   Fix the WSAStartup prototype
   Fix handling of timeout parameter in select   


--
Francois Gouget         fgouget at free.fr        http://fgouget.free.fr/
     We are Pentium of Borg. You will be approximated. Division is futile.
-------------- next part --------------
Index: include/winsock.h
===================================================================
RCS file: /home/wine/wine/include/winsock.h,v
retrieving revision 1.34
diff -u -r1.34 winsock.h
9 closesocket(SOCKET s);
 
-INT     WINAPI WSAStartup(UINT wVersionRequired, LPWSADATA lpWSAData);
-void      WINAPI WSASetLastError(INT iError);
+int     WINAPI WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
+void    WINAPI WSASetLastError(INT iError);
 INT     WINAPI WSACleanup(void);
 INT     WINAPI WSAGetLastError(void);
 BOOL    WINAPI WSAIsBlocking(void);
--- include/winsock.h	2001/08/24 19:14:56	1.34
+++ include/winsock.h	2001/09/12 18:23:10
Index: dlls/winsock/socket.c
===================================================================
RCS file: /home/wine/wine/dlls/winsock/socket.c,v
retrieving revision 1.60
diff -u -r1.60 socket.c
--- dlls/winsock/socket.c	2001/09/07 15:26:18	1.60
+++ dlls/winsock/socket.c	2001/09/12 18:22:55
@@ -587,7 +589,7 @@
 /***********************************************************************
  *      WSAStartup		(WS2_32.115)
  */
-INT WINAPI WSAStartup(UINT wVersionRequested, LPWSADATA lpWSAData)
+int WINAPI WSAStartup(WORD wVersionRequested, LPWSADATA lpWSAData)
 {
     static const WSADATA data =
     {
@@ -1769,21 +1865,25 @@
 /***********************************************************************
  *		__ws_select
  */
-static INT __ws_select( BOOL b32, void *ws_readfds, void *ws_writefds, void *ws_exceptfds,
-			  struct timeval *timeout )
+static INT __ws_select(BOOL b32,
+                       void *ws_readfds, void *ws_writefds, void *ws_exceptfds,
+                       const struct timeval* ws_timeout)
 {
     int         highfd = 0;
     fd_set      readfds, writefds, exceptfds;
     fd_set     *p_read, *p_write, *p_except;
     int         readfd[FD_SETSIZE], writefd[FD_SETSIZE], exceptfd[FD_SETSIZE];
+    struct timeval timeout;
 
     TRACE("read %p, write %p, excp %p\n", ws_readfds, ws_writefds, ws_exceptfds);
 
     p_read = fd_set_import(&readfds, ws_readfds, &highfd, readfd, b32);
     p_write = fd_set_import(&writefds, ws_writefds, &highfd, writefd, b32);
     p_except = fd_set_import(&exceptfds, ws_exceptfds, &highfd, exceptfd, b32);
+    timeout.tv_sec=ws_timeout->tv_sec;
+    timeout.tv_usec=ws_timeout->tv_usec;
 
-    if( (highfd = select(highfd + 1, p_read, p_write, p_except, timeout)) > 0 )
+    if( (highfd = select(highfd + 1, p_read, p_write, p_except, &timeout)) > 0 )
     {
         fd_set_export(&readfds, p_except, ws_readfds, readfd, b32);
         fd_set_export(&writefds, p_except, ws_writefds, writefd, b32);
@@ -1843,7 +1943,7 @@
  */
 INT WINAPI WSOCK32_select(INT nfds, ws_fd_set32 *ws_readfds,
                               ws_fd_set32 *ws_writefds, ws_fd_set32 *ws_exceptfds,
-                              struct timeval *timeout)
+                              const struct timeval *timeout)
 {
     /* struct timeval is the same for both 32- and 16-bit code */
     return (INT)__ws_select( TRUE, ws_readfds, ws_writefds, ws_exceptfds, timeout );


More information about the wine-patches mailing list