diff options
author | Alain Frisch <alain@frisch.fr> | 2013-07-01 08:29:51 +0000 |
---|---|---|
committer | Alain Frisch <alain@frisch.fr> | 2013-07-01 08:29:51 +0000 |
commit | cf5a7e3b5004114dbcce44e2d737dbdb91b9fcf0 (patch) | |
tree | 0b4e780b195bf6d726dbd158261f8eb6617d2d2f | |
parent | c631c7a1ddc216ddf9d21c3dc8ca6a74696bddd0 (diff) |
Re-undo commit 11966 (which is the fix for #5325 that caused #5578) to be synchronized with 4.01 and have a safe trunk.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13860 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | Changes | 2 | ||||
-rw-r--r-- | otherlibs/win32unix/accept.c | 15 | ||||
-rw-r--r-- | otherlibs/win32unix/socket.c | 15 |
3 files changed, 30 insertions, 2 deletions
@@ -378,8 +378,6 @@ Bug Fixes: - PR#5318: segfault on stack overflow when reading marshaled data - PR#5319: %r11 clobbered by Lswitch in Windows AMD64 native-code compilation - PR#5322: type abbreviations expanding to a universal type variable -- PR#5325: (Windows) blocked Unix.recv in one thread blocks Unix.send in - another thread - PR#5328: under Windows, Unix.select leaves sockets in non-blocking mode - PR#5330: thread tag with '.top' and '.inferred.mli' targets - PR#5331: ocamlmktop is not always a shell script diff --git a/otherlibs/win32unix/accept.c b/otherlibs/win32unix/accept.c index 6776a4ac3..f2e14467a 100644 --- a/otherlibs/win32unix/accept.c +++ b/otherlibs/win32unix/accept.c @@ -25,15 +25,30 @@ CAMLprim value unix_accept(sock) SOCKET sconn = Socket_val(sock); SOCKET snew; value fd = Val_unit, adr = Val_unit, res; + int oldvalue, oldvaluelen, newvalue, retcode; union sock_addr_union addr; socklen_param_type addr_len; DWORD err = 0; + oldvaluelen = sizeof(oldvalue); + retcode = getsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, + (char *) &oldvalue, &oldvaluelen); + if (retcode == 0) { + /* Set sockets to synchronous mode */ + newvalue = SO_SYNCHRONOUS_NONALERT; + setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, + (char *) &newvalue, sizeof(newvalue)); + } addr_len = sizeof(sock_addr); enter_blocking_section(); snew = accept(sconn, &addr.s_gen, &addr_len); if (snew == INVALID_SOCKET) err = WSAGetLastError (); leave_blocking_section(); + if (retcode == 0) { + /* Restore initial mode */ + setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, + (char *) &oldvalue, oldvaluelen); + } if (snew == INVALID_SOCKET) { win32_maperr(err); uerror("accept", Nothing); diff --git a/otherlibs/win32unix/socket.c b/otherlibs/win32unix/socket.c index f6e7038ce..ad8165b29 100644 --- a/otherlibs/win32unix/socket.c +++ b/otherlibs/win32unix/socket.c @@ -32,6 +32,7 @@ CAMLprim value unix_socket(domain, type, proto) value domain, type, proto; { SOCKET s; + int oldvalue, oldvaluelen, newvalue, retcode; #ifndef HAS_IPV6 /* IPv6 requires WinSock2, we must raise an error on PF_INET6 */ @@ -41,9 +42,23 @@ CAMLprim value unix_socket(domain, type, proto) } #endif + oldvaluelen = sizeof(oldvalue); + retcode = getsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, + (char *) &oldvalue, &oldvaluelen); + if (retcode == 0) { + /* Set sockets to synchronous mode */ + newvalue = SO_SYNCHRONOUS_NONALERT; + setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, + (char *) &newvalue, sizeof(newvalue)); + } s = socket(socket_domain_table[Int_val(domain)], socket_type_table[Int_val(type)], Int_val(proto)); + if (retcode == 0) { + /* Restore initial mode */ + setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, + (char *) &oldvalue, oldvaluelen); + } if (s == INVALID_SOCKET) { win32_maperr(WSAGetLastError()); uerror("socket", Nothing); |