diff --git a/ChangeLog b/ChangeLog index 0f6a1104a..ebed72a1b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,9 @@ * configure.in: test for broken SO_REUSEADDR * acconfig.h: Add BROKEN_SO_REUSEADDR * configure: regenerated + * Source/UnixFileHandle.m: Use reuseaddr info. + * Source/GSTcpPort.m: Use reuseaddr info. + * Tools/gdomap.c: Use reuseaddr info. * Source/NSPortNameServer.m: Improved warnings about launching gdomap. * Source/NSDistributedNotification.m: Improved warnings about diff --git a/Source/GSTcpPort.m b/Source/GSTcpPort.m index 3a435acc0..9e9559122 100644 --- a/Source/GSTcpPort.m +++ b/Source/GSTcpPort.m @@ -1461,13 +1461,13 @@ static Class tcpPortClass; NSLog(@"unable to create socket - %s", GSLastErrorStr(errno)); DESTROY(port); } -#ifndef __MINGW__ - /* - * Under unix, SO_REUSEADDR means that the port can be reused - * immediately that this porcess exits. Under windoze it means - * that multiple processes can serve the same port simultaneously. - * We don't want that windows behavior! - */ +#ifndef BROKEN_SO_REUSEADDR + /* + * Under decent systems, SO_REUSEADDR means that the port can be + * reused immediately that this porcess exits. Under some it means + * that multiple processes can serve the same port simultaneously. + * We don't want that broken behavior! + */ else if (setsockopt(desc, SOL_SOCKET, SO_REUSEADDR, (char*)&reuse, sizeof(reuse)) < 0) { @@ -1686,12 +1686,12 @@ static Class tcpPortClass; { NSLog(@"unable to create socket - %s", GSLastErrorStr(errno)); } -#ifndef __MINGW__ +#ifndef BROKEN_SO_REUSEADDR /* - * Under unix, SO_REUSEADDR means that the port can be reused - * immediately that this porcess exits. Under windoze it means + * Under decent systems, SO_REUSEADDR means that the port can be reused + * immediately that this process exits. Under some it means * that multiple processes can serve the same port simultaneously. - * We don't want that windows behavior! + * We don't want that broken behavior! */ else if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&opt, sizeof(opt)) < 0) diff --git a/Source/UnixFileHandle.m b/Source/UnixFileHandle.m index df0ef72af..4b8b4fd19 100644 --- a/Source/UnixFileHandle.m +++ b/Source/UnixFileHandle.m @@ -384,7 +384,15 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin) return nil; } +#ifndef BROKEN_SO_REUSEADDR + /* + * Under decent systems, SO_REUSEADDR means that the port can be reused + * immediately that this process exits. Under some it means + * that multiple processes can serve the same port simultaneously. + * We don't want that broken behavior! + */ setsockopt(net, SOL_SOCKET, SO_REUSEADDR, (char *)&status, sizeof(status)); +#endif if (bind(net, (struct sockaddr *)&sin, sizeof(sin)) < 0) { diff --git a/Tools/gdomap.c b/Tools/gdomap.c index 24f23c13a..defcc5623 100644 --- a/Tools/gdomap.c +++ b/Tools/gdomap.c @@ -1651,12 +1651,12 @@ init_ports() sprintf(ebuf, "Opened UDP socket %d", udp_desc); gdomap_log(LOG_DEBUG); } -#ifndef __MINGW__ +#ifndef BROKEN_SO_REUSEADDR /* - * Under windoze, REUSEADDR means something different from under unix. - * It lets multiple processes bind to the same port at once - - * which we don't want. So we only set it under unix (to allow a process to - * bind to the same port immediately after one which was using the port exits. + * Under decent systems, SO_REUSEADDR means that the port can be reused + * immediately that this process exits. Under some it means + * that multiple processes can serve the same port simultaneously. + * We don't want that broken behavior! */ r = 1; if ((setsockopt(udp_desc,SOL_SOCKET,SO_REUSEADDR,(char*)&r,sizeof(r)))<0) @@ -1744,12 +1744,12 @@ init_ports() sprintf(ebuf, "Opened TDP socket %d", tcp_desc); gdomap_log(LOG_DEBUG); } -#ifndef __MINGW__ +#ifndef BROKEN_SO_REUSEADDR /* - * Under windoze, REUSEADDR means something different from under unix. - * It lets multiple processes bind to the same port at once - - * which we don't want. So we only set it under unix (to allow a process to - * bind to the same port immediately after one which was using the port exits. + * Under decent systems, SO_REUSEADDR means that the port can be reused + * immediately that this process exits. Under some it means + * that multiple processes can serve the same port simultaneously. + * We don't want that broken behavior! */ r = 1; if ((setsockopt(tcp_desc,SOL_SOCKET,SO_REUSEADDR,(char*)&r,sizeof(r)))<0) @@ -2645,19 +2645,18 @@ handle_request(int desc) } else { -#ifndef __MINGW__ +#ifndef BROKEN_SO_REUSEADDR int r = 1; /* - * Under windoze, REUSEADDR means something different from - * under unix. - * It lets multiple processes bind to the same port at once - - * which we don't want. So we only set it under unix (to allow - * a process to bind to the same port immediately after one - * which was using the port exits. + * Under decent systems, SO_REUSEADDR means that the port can + * be reused immediately that this process exits. Under some + * it means that multiple processes can serve the same port + * simultaneously. + * We don't want that broken behavior! */ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, - (char*)&r, sizeof(r)) < 0) + (char*)&r, sizeof(r)) < 0) { perror("unable to set socket options"); } @@ -2747,16 +2746,15 @@ handle_request(int desc) } else { -#ifndef __MINGW__ +#ifndef BROKEN_SO_REUSEADDR int r = 1; /* - * Under windoze, REUSEADDR means something different from - * under unix. - * It lets multiple processes bind to the same port at once - - * which we don't want. So we only set it under unix (to allow - * a process to bind to the same port immediately after one - * which was using the port exits. + * Under decent systems, SO_REUSEADDR means that the port can + * be reused immediately that this process exits. Under some + * it means that multiple processes can serve the same port + * simultaneously. + * We don't want that broken behavior! */ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&r, sizeof(r)) < 0)