From 58b030c270e68c4e130a7decb646ca1aa3d3ea2f Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Sat, 3 Nov 2007 08:45:12 +0100 Subject: [PATCH] ws2_32: Map SO_REUSEADDR. BSD socket SO_REUSEADDR is not a complete match, but features like "allow binding to a port immediately after closing it" seem to be compatible. --- dlls/ws2_32/socket.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 24a4a766708..4c185d81236 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -1654,6 +1654,7 @@ INT WINAPI WS_getsockopt(SOCKET s, INT level, case WS_SO_KEEPALIVE: case WS_SO_OOBINLINE: case WS_SO_RCVBUF: + case WS_SO_REUSEADDR: case WS_SO_SNDBUF: case WS_SO_TYPE: if ( (fd = get_sock_fd( s, 0, NULL )) == -1) @@ -1796,18 +1797,6 @@ INT WINAPI WS_getsockopt(SOCKET s, INT level, return ret; } #endif - /* As mentioned in setsockopt, the windows style SO_REUSEADDR is - * not possible in Unix, so always return false here. */ - case WS_SO_REUSEADDR: - if (!optlen || *optlen < sizeof(int) || !optval) - { - SetLastError(WSAEFAULT); - return SOCKET_ERROR; - } - *(int *)optval = 0; - *optlen = sizeof(int); - return 0; - default: TRACE("Unknown SOL_SOCKET optname: 0x%08x\n", optname); SetLastError(WSAENOPROTOOPT); @@ -2869,6 +2858,10 @@ int WINAPI WS_setsockopt(SOCKET s, int level, int optname, case WS_SO_ERROR: case WS_SO_KEEPALIVE: case WS_SO_OOBINLINE: + /* BSD socket SO_REUSEADDR is not 100% compatible to winsock semantics. + * however, using it the BSD way fixes bug 8513 and seems to be what + * most programmers assume, anyway */ + case WS_SO_REUSEADDR: case WS_SO_SNDBUF: case WS_SO_TYPE: convert_sockopt(&level, &optname); @@ -2902,13 +2895,6 @@ int WINAPI WS_setsockopt(SOCKET s, int level, int optname, TRACE("setting global SO_OPENTYPE = 0x%x\n", *((int*)optval) ); return 0; - /* SO_REUSEADDR allows two applications to bind to the same port at at - * same time. There is no direct way to do that in unix. While Wineserver - * might do this, it does not seem useful for now, so just ignore it.*/ - case WS_SO_REUSEADDR: - TRACE("Ignoring SO_REUSEADDR, does not translate\n"); - return 0; - #ifdef SO_RCVTIMEO case WS_SO_RCVTIMEO: #endif -- 2.11.4.GIT