Try to cope with failure of remote end to respond to tls shutdown.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37417 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2013-11-27 12:26:33 +00:00
parent ce7b612350
commit fab72a3218
5 changed files with 50 additions and 26 deletions

View file

@ -366,24 +366,26 @@ static GSTcpTune *tune = nil;
[self ignoreReadDescriptor]; [self ignoreReadDescriptor];
[self ignoreWriteDescriptor]; [self ignoreWriteDescriptor];
#if USE_ZLIB if (closeOnDealloc == YES && descriptor != -1)
/*
* The gzDescriptor should always be closed when we have done with it.
*/
if (gzDescriptor != 0)
{ {
gzclose(gzDescriptor); [self closeFile];
gzDescriptor = 0;
} }
#endif else
if (descriptor != -1)
{ {
[self setNonBlocking: wasNonBlocking]; #if USE_ZLIB
if (closeOnDealloc == YES) /*
{ * The gzDescriptor should always be closed when we have done with it.
close(descriptor); */
descriptor = -1; if (gzDescriptor != 0)
} {
gzclose(gzDescriptor);
gzDescriptor = 0;
}
#endif
if (descriptor != -1)
{
[self setNonBlocking: wasNonBlocking];
}
} }
} }

View file

@ -476,7 +476,7 @@ static NSArray *keys = nil;
{ {
handshake = NO; handshake = NO;
active = NO; active = NO;
[session disconnect]; [session disconnect: NO];
} }
- (void) dealloc - (void) dealloc

View file

@ -197,9 +197,13 @@ typedef ssize_t (*GSTLSIOW)(gnutls_transport_ptr_t, const void *, size_t);
*/ */
- (BOOL) active; - (BOOL) active;
/* Disconnects and closes down the session. /* Disconnects and closes down the session.<br />
* The reusable flag specifies whether we intend to reuse the underlying
* connection.<br />
* Returns YES on success, NO if the shutdown did not complete cleanly
* and the underlying connection cannot be reused.
*/ */
- (void) disconnect; - (BOOL) disconnect: (BOOL)reusable;
/* Try to complete a handshake ... return YES if complete, NO if we need /* Try to complete a handshake ... return YES if complete, NO if we need
* to try again (would have to wait for the remote end).<br /> * to try again (would have to wait for the remote end).<br />

View file

@ -1281,13 +1281,32 @@ static NSMutableDictionary *credentialsCache = nil;
[super dealloc]; [super dealloc];
} }
- (void) disconnect - (BOOL) disconnect: (BOOL)reusable
{ {
BOOL ok = YES;
if (YES == active || YES == handshake) if (YES == active || YES == handshake)
{ {
active = NO; active = NO;
handshake = NO; handshake = NO;
gnutls_bye(session, GNUTLS_SHUT_RDWR); if (NO == reusable)
{
gnutls_bye(session, GNUTLS_SHUT_WR);
}
else
{
int result;
do
{
result = gnutls_bye(session, GNUTLS_SHUT_RDWR);
}
while (GNUTLS_E_AGAIN == result || GNUTLS_E_INTERRUPTED == result);
if (result < 0)
{
ok = NO;
}
}
} }
if (YES == setup) if (YES == setup)
{ {
@ -1295,11 +1314,12 @@ static NSMutableDictionary *credentialsCache = nil;
gnutls_db_remove_session(session); gnutls_db_remove_session(session);
gnutls_deinit(session); gnutls_deinit(session);
} }
return ok;
} }
- (void) finalize - (void) finalize
{ {
[self disconnect]; [self disconnect: NO];
[super finalize]; [super finalize];
} }
@ -1545,7 +1565,7 @@ static NSMutableDictionary *credentialsCache = nil;
ASSIGN(problem, p); ASSIGN(problem, p);
NSLog(@"%@ %@", self, p); NSLog(@"%@ %@", self, p);
} }
[self disconnect]; [self disconnect: NO];
return YES; // Failed ... not active. return YES; // Failed ... not active.
} }
else else
@ -1591,7 +1611,7 @@ static NSMutableDictionary *credentialsCache = nil;
self, gnutls_strerror(ret)); self, gnutls_strerror(ret));
NSLog(@"%@ %@", self, [self sessionInfo]); NSLog(@"%@ %@", self, [self sessionInfo]);
} }
[self disconnect]; [self disconnect: NO];
} }
} }
return YES; // Handshake complete return YES; // Handshake complete

View file

@ -985,9 +985,7 @@ GSTLSHandlePush(gnutls_transport_ptr_t handle, const void *buffer, size_t len)
- (void) sslDisconnect - (void) sslDisconnect
{ {
// TLS may need to read data during teardown, and we need to wait for it. [session disconnect: NO];
[self setNonBlocking: NO];
[session disconnect];
} }
- (BOOL) sslHandshakeEstablished: (BOOL*)result outgoing: (BOOL)isOutgoing - (BOOL) sslHandshakeEstablished: (BOOL*)result outgoing: (BOOL)isOutgoing