2004-10-14 Dick Porter <dick@ximian.com>
authorDick Porter <dick@acm.org>
Thu, 14 Oct 2004 09:00:56 +0000 (09:00 -0000)
committerDick Porter <dick@acm.org>
Thu, 14 Oct 2004 09:00:56 +0000 (09:00 -0000)
* sockets.c (_wapi_accept): On Darwin, make sure a newly
accept()ed socket is blocking.  Fixes bug 67355, patch by
grompf@sublimeintervention.com.

svn path=/trunk/mono/; revision=34980

mono/io-layer/ChangeLog
mono/io-layer/sockets.c

index 7f66f6afa8d82edf536d9619ce1862ca0f3df0cc..6649f6f5ddf9de19d6abd1384b5fdf13d3be1f91 100644 (file)
@@ -1,3 +1,9 @@
+2004-10-14  Dick Porter  <dick@ximian.com>
+
+       * sockets.c (_wapi_accept): On Darwin, make sure a newly
+       accept()ed socket is blocking.  Fixes bug 67355, patch by
+       grompf@sublimeintervention.com.
+
 2004-10-04 Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * system.c: check the number of online processors instead of the
index df7ac8a25dcc2ff43a15000c381f8fa9bd6e0b34..43e6a54cb2f595a9a4a63e816cbbf770a885fea5 100644 (file)
@@ -252,6 +252,31 @@ guint32 _wapi_accept(guint32 fd, struct sockaddr *addr, socklen_t *addrlen)
        }
        while (new_fd==-1 && errno==EINTR && !_wapi_thread_cur_apc_pending());
 
+
+#ifdef __APPLE__
+       {
+               /* It appears that sockets accepted on linux default
+                * to blocking where as on Darwin they inherit the
+                * flags of the listener.  Mono expects sockets to be
+                * blocking by default so we check the flags to see if
+                * its blocking on Darwin and reset it if so.
+                */
+               int args = fcntl (new_fd, F_GETFL, NULL);
+               if (args & O_NONBLOCK) {
+                       args &= ~O_NONBLOCK;
+                       ret = fcntl (new_fd, F_SETFL, args);
+                       if(ret==-1) {
+                               gint errnum = errno;
+                               
+                               errnum = errno_to_WSA (errnum, G_GNUC_PRETTY_FUNCTION);
+                               WSASetLastError (errnum);
+               
+                               return(INVALID_SOCKET);
+                       }
+               }
+       }
+#endif
+
        if(new_fd==-1) {
                gint errnum = errno;
 #ifdef DEBUG