Enable keepalive on socket connections

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21310 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-06-15 03:56:13 +00:00
parent 433e72bc8d
commit 131e658ae2
4 changed files with 39 additions and 0 deletions

View file

@ -1,3 +1,11 @@
2005-06-15 Richard Frith-Macdonald <rfm@gnu.org>
* 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 <rfm@gnu.org>
* Source/NSCalendardate.m: Fix crash when a nil string is passed to

View file

@ -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

View file

@ -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

View file

@ -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);