1.1 --- a/BLIP/BLIPConnection.h Thu Jun 19 16:22:05 2008 -0700
1.2 +++ b/BLIP/BLIPConnection.h Mon Jun 23 14:02:31 2008 -0700
1.3 @@ -79,7 +79,7 @@
1.4 - (BOOL) connectionReceivedCloseRequest: (BLIPConnection*)connection;
1.5
1.6 /** Called if the peer refuses a close request.
1.7 - The typical error is BLIP error kBLIPError_Forbidden. */
1.8 + The typical error is kBLIPError_Forbidden. */
1.9 - (void) connection: (BLIPConnection*)connection closeRequestFailedWithError: (NSError*)error;
1.10 @end
1.11
2.1 --- a/BLIP/BLIPConnection.m Thu Jun 19 16:22:05 2008 -0700
2.2 +++ b/BLIP/BLIPConnection.m Mon Jun 23 14:02:31 2008 -0700
2.3 @@ -8,6 +8,7 @@
2.4
2.5 #import "BLIPConnection.h"
2.6 #import "BLIP_Internal.h"
2.7 +#import "TCP_Internal.h"
2.8 #import "BLIPReader.h"
2.9 #import "BLIPWriter.h"
2.10 #import "BLIPDispatcher.h"
2.11 @@ -153,8 +154,8 @@
2.12 NSError *error = response.error;
2.13 LogTo(BLIPVerbose,@"Received close response: error=%@",error);
2.14 if( error ) {
2.15 - if( [_delegate respondsToSelector: @selector(connection:closeRequestFailedWithError:)] )
2.16 - [_delegate connection: self closeRequestFailedWithError: error];
2.17 + [self _unclose];
2.18 + [self tellDelegate: @selector(connection:closeRequestFailedWithError:) withObject: error];
2.19 } else {
2.20 // Now finally close the socket:
2.21 [super _beginClose];
3.1 --- a/BLIP/BLIPTest.m Thu Jun 19 16:22:05 2008 -0700
3.2 +++ b/BLIP/BLIPTest.m Mon Jun 23 14:02:31 2008 -0700
3.3 @@ -194,6 +194,13 @@
3.4 Log(@"Now %u replies pending", _pending.count);
3.5 }
3.6
3.7 +- (BOOL) connectionReceivedCloseRequest: (BLIPConnection*)connection
3.8 +{
3.9 + BOOL response = NO;
3.10 + Log(@"***** %@ received a close request; returning %i",connection,response);
3.11 + return response;
3.12 +}
3.13 +
3.14
3.15 @end
3.16
3.17 @@ -324,6 +331,17 @@
3.18 }
3.19 }
3.20
3.21 +- (BOOL) connectionReceivedCloseRequest: (BLIPConnection*)connection;
3.22 +{
3.23 + Log(@"***** %@ received a close request",connection);
3.24 + return YES;
3.25 +}
3.26 +
3.27 +- (void) connection: (BLIPConnection*)connection closeRequestFailedWithError: (NSError*)error
3.28 +{
3.29 + Log(@"***** %@'s close request failed: %@",connection,error);
3.30 +}
3.31 +
3.32
3.33 @end
3.34
4.1 --- a/BLIP/BLIP_Internal.h Thu Jun 19 16:22:05 2008 -0700
4.2 +++ b/BLIP/BLIP_Internal.h Mon Jun 23 14:02:31 2008 -0700
4.3 @@ -42,7 +42,7 @@
4.4 UInt16 size; // total size of frame, _including_ this header
4.5 } BLIPFrameHeader;
4.6
4.7 -#define kBLIPFrameHeaderMagicNumber 0x9B34F205
4.8 +#define kBLIPFrameHeaderMagicNumber 0x9B34F206
4.9
4.10 #define kBLIPProfile_Hi @"Hi" // Used for Profile header in meta greeting message
4.11 #define kBLIPProfile_Bye @"Bye" // Used for Profile header in meta close-request message
5.1 --- a/TCP/TCPConnection.h Thu Jun 19 16:22:05 2008 -0700
5.2 +++ b/TCP/TCPConnection.h Mon Jun 23 14:02:31 2008 -0700
5.3 @@ -109,6 +109,7 @@
5.4 - (Class) readerClass;
5.5 - (Class) writerClass;
5.6 - (void) _beginClose;
5.7 +- (void) _unclose;
5.8
5.9 @end
5.10
6.1 --- a/TCP/TCPConnection.m Thu Jun 19 16:22:05 2008 -0700
6.2 +++ b/TCP/TCPConnection.m Mon Jun 23 14:02:31 2008 -0700
6.3 @@ -247,7 +247,24 @@
6.4 [self disconnect];
6.5 }
6.6
6.7 +- (void) _stopCloseTimer
6.8 +{
6.9 + [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(_closeTimeoutExpired) object: nil];
6.10 +}
6.11
6.12 +- (void) _unclose
6.13 +{
6.14 + if( _status == kTCP_Closing ) {
6.15 + LogTo(TCP,@"%@: _unclose!",self);
6.16 + [_reader _unclose];
6.17 + [_writer _unclose];
6.18 + [self _stopCloseTimer];
6.19 + self.status = kTCP_Open;
6.20 + }
6.21 +}
6.22 +
6.23 +
6.24 +/** Subclasses can override this to customize what happens when -close is called. */
6.25 - (void) _beginClose
6.26 {
6.27 [_reader close];
6.28 @@ -278,9 +295,7 @@
6.29 else
6.30 [self tellDelegate: @selector(connectionDidClose:) withObject: nil];
6.31 }
6.32 - [NSObject cancelPreviousPerformRequestsWithTarget: self
6.33 - selector: @selector(_closeTimeoutExpired)
6.34 - object: nil];
6.35 + [self _stopCloseTimer];
6.36 [self _stopOpenTimer];
6.37 [sAllConnections removeObjectIdenticalTo: self];
6.38 }
7.1 --- a/TCP/TCPStream.m Thu Jun 19 16:22:05 2008 -0700
7.2 +++ b/TCP/TCPStream.m Mon Jun 23 14:02:31 2008 -0700
7.3 @@ -121,17 +121,24 @@
7.4
7.5 - (BOOL) close
7.6 {
7.7 - _shouldClose = YES;
7.8 + if( ! _shouldClose ) {
7.9 + _shouldClose = YES;
7.10 + LogTo(TCP,@"Request to close %@",self);
7.11 + }
7.12 if( self.isBusy ) {
7.13 return NO;
7.14 } else {
7.15 - LogTo(TCP,@"Request to close %@",self);
7.16 [[self retain] autorelease]; // don't let myself be dealloced in the midst of this
7.17 [_conn _streamCanClose: self];
7.18 return YES;
7.19 }
7.20 }
7.21
7.22 +- (void) _unclose
7.23 +{
7.24 + _shouldClose = NO;
7.25 +}
7.26 +
7.27
7.28 - (BOOL) isOpen
7.29 {
8.1 --- a/TCP/TCP_Internal.h Thu Jun 19 16:22:05 2008 -0700
8.2 +++ b/TCP/TCP_Internal.h Mon Jun 23 14:02:31 2008 -0700
8.3 @@ -24,3 +24,9 @@
8.4 - (void) _streamGotEOF: (TCPStream*)stream;
8.5 - (void) _streamDisconnected: (TCPStream*)stream;
8.6 @end
8.7 +
8.8 +
8.9 +@interface TCPStream ()
8.10 +- (void) _unclose;
8.11 +@end
8.12 +