diff --git a/ChangeLog b/ChangeLog index 7c1df86b1..c7b8091fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-06-15 Richard Frith-Macdonald + + * Source/GSFileHandle.m: + * Source/NSSocketPort.m: + * Source/NSMessagePort.m: + Enable KEEPALIVE on stream sockets, so we will notice if the remote + end drops the connection. + 2005-06-08 Richard Frith-Macdonald * Source/NSCalendardate.m: Fix crash when a nil string is passed to diff --git a/Source/GSFileHandle.m b/Source/GSFileHandle.m index fec0ee1c6..18af1e544 100644 --- a/Source/GSFileHandle.m +++ b/Source/GSFileHandle.m @@ -697,6 +697,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr"; NSString *lhost = nil; NSString *shost = nil; NSString *sport = nil; + int status; if (beenHere == NO) { @@ -829,6 +830,12 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr"; RELEASE(self); return nil; } + /* + * Enable tcp-level tracking of whether connection is alive. + */ + status = 1; + setsockopt(net, SOL_SOCKET, SO_KEEPALIVE, (char *)&status, sizeof(status)); + if (lhost != nil) { if (bind(net, (struct sockaddr *)&lsin, sizeof(lsin)) == SOCKET_ERROR) @@ -2133,6 +2140,14 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr"; GSFileHandle *h; struct sockaddr_in sin; int size = sizeof(sin); + int status; + + /* + * Enable tcp-level tracking of whether connection is alive. + */ + status = 1; + setsockopt(desc, SOL_SOCKET, SO_KEEPALIVE, (char *)&status, + sizeof(status)); #if defined(__MINGW__) h = [[[self class] alloc] initWithNativeHandle: (void*)desc diff --git a/Source/NSMessagePort.m b/Source/NSMessagePort.m index 9f3e79d7f..f3e9c621b 100644 --- a/Source/NSMessagePort.m +++ b/Source/NSMessagePort.m @@ -469,6 +469,10 @@ static Class runLoopClass; } else { + int status = 1; + + setsockopt(desc, SOL_SOCKET, SO_KEEPALIVE, (char*)&status, + sizeof(status)); addrNum = 0; caller = YES; [aPort addHandle: self forSend: YES]; @@ -1631,6 +1635,10 @@ static int unique_index = 0; } else { + int status = 1; + + setsockopt(desc, SOL_SOCKET, SO_KEEPALIVE, (char*)&status, + sizeof(status)); /* * Create a handle for the socket and set it up so we are its * receiving port, and it's waiting to get the port name from diff --git a/Source/NSSocketPort.m b/Source/NSSocketPort.m index a5a60d27e..7580fcada 100644 --- a/Source/NSSocketPort.m +++ b/Source/NSSocketPort.m @@ -635,6 +635,10 @@ static Class runLoopClass; } else { + int status = 1; + + setsockopt(desc, SOL_SOCKET, SO_KEEPALIVE, (char*)&status, + sizeof(status)); addrNum = 0; caller = YES; [aPort addHandle: self forSend: YES]; @@ -2122,6 +2126,10 @@ static unsigned wordAlign; } else { + int status = 1; + + setsockopt(desc, SOL_SOCKET, SO_KEEPALIVE, (char*)&status, + sizeof(status)); #ifdef __MINGW32__ // reset associated event with new socket WSAEventSelect(desc, eventListener, 0);