Added broken reuseaddr checks.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13487 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2002-04-16 18:54:01 +00:00
parent 73906e410f
commit 4c077389a9
4 changed files with 45 additions and 36 deletions

View file

@ -4,6 +4,9 @@
* configure.in: test for broken SO_REUSEADDR * configure.in: test for broken SO_REUSEADDR
* acconfig.h: Add BROKEN_SO_REUSEADDR * acconfig.h: Add BROKEN_SO_REUSEADDR
* configure: regenerated * 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 * Source/NSPortNameServer.m: Improved warnings about launching
gdomap. gdomap.
* Source/NSDistributedNotification.m: Improved warnings about * Source/NSDistributedNotification.m: Improved warnings about

View file

@ -1461,13 +1461,13 @@ static Class tcpPortClass;
NSLog(@"unable to create socket - %s", GSLastErrorStr(errno)); NSLog(@"unable to create socket - %s", GSLastErrorStr(errno));
DESTROY(port); DESTROY(port);
} }
#ifndef __MINGW__ #ifndef BROKEN_SO_REUSEADDR
/* /*
* Under unix, SO_REUSEADDR means that the port can be reused * Under decent systems, SO_REUSEADDR means that the port can be
* immediately that this porcess exits. Under windoze it means * reused immediately that this porcess exits. Under some it means
* that multiple processes can serve the same port simultaneously. * 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(desc, SOL_SOCKET, SO_REUSEADDR, (char*)&reuse, else if (setsockopt(desc, SOL_SOCKET, SO_REUSEADDR, (char*)&reuse,
sizeof(reuse)) < 0) sizeof(reuse)) < 0)
{ {
@ -1686,12 +1686,12 @@ static Class tcpPortClass;
{ {
NSLog(@"unable to create socket - %s", GSLastErrorStr(errno)); 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 * Under decent systems, SO_REUSEADDR means that the port can be reused
* immediately that this porcess exits. Under windoze it means * immediately that this process exits. Under some it means
* that multiple processes can serve the same port simultaneously. * 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, else if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&opt,
sizeof(opt)) < 0) sizeof(opt)) < 0)

View file

@ -384,7 +384,15 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
return nil; 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)); setsockopt(net, SOL_SOCKET, SO_REUSEADDR, (char *)&status, sizeof(status));
#endif
if (bind(net, (struct sockaddr *)&sin, sizeof(sin)) < 0) if (bind(net, (struct sockaddr *)&sin, sizeof(sin)) < 0)
{ {

View file

@ -1651,12 +1651,12 @@ init_ports()
sprintf(ebuf, "Opened UDP socket %d", udp_desc); sprintf(ebuf, "Opened UDP socket %d", udp_desc);
gdomap_log(LOG_DEBUG); gdomap_log(LOG_DEBUG);
} }
#ifndef __MINGW__ #ifndef BROKEN_SO_REUSEADDR
/* /*
* Under windoze, REUSEADDR means something different from under unix. * Under decent systems, SO_REUSEADDR means that the port can be reused
* It lets multiple processes bind to the same port at once - * immediately that this process exits. Under some it means
* which we don't want. So we only set it under unix (to allow a process to * that multiple processes can serve the same port simultaneously.
* bind to the same port immediately after one which was using the port exits. * We don't want that broken behavior!
*/ */
r = 1; r = 1;
if ((setsockopt(udp_desc,SOL_SOCKET,SO_REUSEADDR,(char*)&r,sizeof(r)))<0) 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); sprintf(ebuf, "Opened TDP socket %d", tcp_desc);
gdomap_log(LOG_DEBUG); gdomap_log(LOG_DEBUG);
} }
#ifndef __MINGW__ #ifndef BROKEN_SO_REUSEADDR
/* /*
* Under windoze, REUSEADDR means something different from under unix. * Under decent systems, SO_REUSEADDR means that the port can be reused
* It lets multiple processes bind to the same port at once - * immediately that this process exits. Under some it means
* which we don't want. So we only set it under unix (to allow a process to * that multiple processes can serve the same port simultaneously.
* bind to the same port immediately after one which was using the port exits. * We don't want that broken behavior!
*/ */
r = 1; r = 1;
if ((setsockopt(tcp_desc,SOL_SOCKET,SO_REUSEADDR,(char*)&r,sizeof(r)))<0) if ((setsockopt(tcp_desc,SOL_SOCKET,SO_REUSEADDR,(char*)&r,sizeof(r)))<0)
@ -2645,19 +2645,18 @@ handle_request(int desc)
} }
else else
{ {
#ifndef __MINGW__ #ifndef BROKEN_SO_REUSEADDR
int r = 1; int r = 1;
/* /*
* Under windoze, REUSEADDR means something different from * Under decent systems, SO_REUSEADDR means that the port can
* under unix. * be reused immediately that this process exits. Under some
* It lets multiple processes bind to the same port at once - * it means that multiple processes can serve the same port
* which we don't want. So we only set it under unix (to allow * simultaneously.
* a process to bind to the same port immediately after one * We don't want that broken behavior!
* which was using the port exits.
*/ */
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(char*)&r, sizeof(r)) < 0) (char*)&r, sizeof(r)) < 0)
{ {
perror("unable to set socket options"); perror("unable to set socket options");
} }
@ -2747,16 +2746,15 @@ handle_request(int desc)
} }
else else
{ {
#ifndef __MINGW__ #ifndef BROKEN_SO_REUSEADDR
int r = 1; int r = 1;
/* /*
* Under windoze, REUSEADDR means something different from * Under decent systems, SO_REUSEADDR means that the port can
* under unix. * be reused immediately that this process exits. Under some
* It lets multiple processes bind to the same port at once - * it means that multiple processes can serve the same port
* which we don't want. So we only set it under unix (to allow * simultaneously.
* a process to bind to the same port immediately after one * We don't want that broken behavior!
* which was using the port exits.
*/ */
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(char*)&r, sizeof(r)) < 0) (char*)&r, sizeof(r)) < 0)