From 7a0f96c908a72290a51aeceebf652a06c1f364ad Mon Sep 17 00:00:00 2001
From: Ove Kaaven <ovek@arcticnet.no>
Date: Wed, 6 Sep 2000 19:40:23 +0000
Subject: [PATCH] Adapted Winsock to Linux 2.4 TCP socket poll() behaviour
 (thanks to Berend Ozceri for finding the problem).

---
 server/sock.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/server/sock.c b/server/sock.c
index 043b0443e5e..1e9ba539338 100644
--- a/server/sock.c
+++ b/server/sock.c
@@ -83,6 +83,14 @@ static void sock_reselect( struct sock *sock )
 
     if (debug_level)
         fprintf(stderr,"sock_reselect(%d): new mask %x\n", sock->obj.fd, ev);
+
+    if (sock->obj.select == -1) {
+        /* previously unconnected socket, is this reselect supposed to connect it? */
+        if (!sock->state) return;
+        /* ok, it is, attach it to the wineserver's main poll loop */
+        add_select_user( &sock->obj );
+    }
+    /* update condition mask */
     set_select_events( &sock->obj, ev );
 
     /* check whether condition is satisfied already */
@@ -288,8 +296,9 @@ static struct object *create_socket( int family, int type, int protocol )
         return NULL;
     }
     fcntl(sockfd, F_SETFL, O_NONBLOCK); /* make socket nonblocking */
-    if (!(sock = alloc_object( &sock_ops, sockfd ))) return NULL;
-    sock->state = (type!=SOCK_STREAM) ? WS_FD_READ|WS_FD_WRITE : 0;
+    if (!(sock = alloc_object( &sock_ops, -1 ))) return NULL;
+    sock->obj.fd = sockfd;
+    sock->state = (type != SOCK_STREAM) ? (WS_FD_READ|WS_FD_WRITE) : 0;
     sock->mask  = 0;
     sock->hmask = 0;
     sock->pmask = 0;
@@ -323,12 +332,13 @@ static struct object *accept_socket( int handle )
         release_object( sock );
 	return NULL;
     }
-    if (!(acceptsock = alloc_object( &sock_ops, acceptfd )))
+    if (!(acceptsock = alloc_object( &sock_ops, -1 )))
     {
         release_object( sock );
         return NULL;
     }
 
+    acceptsock->obj.fd = acceptfd;
     acceptsock->state  = WS_FD_CONNECTED|WS_FD_READ|WS_FD_WRITE;
     acceptsock->mask   = sock->mask;
     acceptsock->hmask  = 0;
-- 
GitLab