New option to control delay between shutdown and fianl close

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37418 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2013-11-27 17:05:32 +00:00
parent 73a23ba709
commit e4c8d18e60

View file

@ -103,6 +103,7 @@ static GSFileHandle* fh_stdout = nil;
static GSFileHandle* fh_stderr = nil; static GSFileHandle* fh_stderr = nil;
@interface GSTcpTune : NSObject @interface GSTcpTune : NSObject
- (int) delay;
- (int) recvSize; - (int) recvSize;
- (int) sendSize: (int)bytesToSend; - (int) sendSize: (int)bytesToSend;
- (void) tune: (void*)handle; - (void) tune: (void*)handle;
@ -110,6 +111,7 @@ static GSFileHandle* fh_stderr = nil;
@implementation GSTcpTune @implementation GSTcpTune
static int tuneDelay = 0;
static int tuneLinger = -1; static int tuneLinger = -1;
static int tuneReceive = 0; static int tuneReceive = 0;
static BOOL tuneSendAll = NO; static BOOL tuneSendAll = NO;
@ -138,6 +140,7 @@ static int tuneSBuf = 0;
tuneSBuf = (int)[defs integerForKey: @"GSTcpSndBuf"]; tuneSBuf = (int)[defs integerForKey: @"GSTcpSndBuf"];
tuneReceive = (int)[defs integerForKey: @"GSTcpReceive"]; tuneReceive = (int)[defs integerForKey: @"GSTcpReceive"];
tuneSendAll = [defs boolForKey: @"GSTcpSendAll"]; tuneSendAll = [defs boolForKey: @"GSTcpSendAll"];
tuneDelay = [defs boolForKey: @"GSTcpDelay"];
} }
+ (void) initialize + (void) initialize
@ -160,6 +163,11 @@ static int tuneSBuf = 0;
} }
} }
- (int) delay
{
return tuneDelay; // Milliseconds to delay close
}
- (int) recvSize - (int) recvSize
{ {
if (tuneReceive > 0) if (tuneReceive > 0)
@ -1718,22 +1726,38 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
#endif #endif
if (YES == isSocket) if (YES == isSocket)
{ {
shutdown(descriptor, SHUT_WR); int milli = [tune delay];
for(;;)
{
int result;
char buffer[4096];
result = read(descriptor, buffer, sizeof(buffer)); shutdown(descriptor, SHUT_WR);
if (result <= 0) if (milli > 0)
{
NSTimeInterval until;
until = [NSDate timeIntervalSinceReferenceDate];
until += ((double)milli) / 1000.0;
[self setNonBlocking: YES];
while ([NSDate timeIntervalSinceReferenceDate] < until)
{ {
if (result < 0) int result;
char buffer[4096];
result = read(descriptor, buffer, sizeof(buffer));
if (result <= 0)
{ {
NSLog(@"%@ read fail on socket shutdown: %@", if (result < 0)
self, [NSError _last]); {
if (EAGAIN == errno || EINTR == errno)
{
continue;
}
NSLog(@"%@ read fail on socket shutdown: %@",
self, [NSError _last]);
}
break;
} }
break;
} }
[self setNonBlocking: YES];
} }
} }
(void)close(descriptor); (void)close(descriptor);