TCP/TCPStream.m
changeset 18 3be241de1630
parent 7 5936db2c1987
child 19 16454d63d4c2
     1.1 --- a/TCP/TCPStream.m	Sun May 25 13:43:03 2008 -0700
     1.2 +++ b/TCP/TCPStream.m	Thu Jun 19 16:22:05 2008 -0700
     1.3 @@ -110,20 +110,24 @@
     1.4          [_stream close];
     1.5          setObj(&_stream,nil);
     1.6      }
     1.7 -    setObj(&_conn,nil);
     1.8 +    if( _conn ) {
     1.9 +        [self retain];
    1.10 +        [_conn _streamDisconnected: self];
    1.11 +        setObj(&_conn,nil);
    1.12 +        [self release];
    1.13 +    }
    1.14  }
    1.15  
    1.16  
    1.17  - (BOOL) close
    1.18  {
    1.19 +    _shouldClose = YES;
    1.20      if( self.isBusy ) {
    1.21 -        _shouldClose = YES;
    1.22          return NO;
    1.23      } else {
    1.24 -        LogTo(TCP,@"Closing %@",self);
    1.25 -        [[self retain] autorelease];    // don't let myself be dealloced in the midst of this
    1.26 -        [_conn _streamClosed: self];    // have to do this before disconnect
    1.27 -        [self disconnect];
    1.28 +        LogTo(TCP,@"Request to close %@",self);
    1.29 +        [[self retain] autorelease];        // don't let myself be dealloced in the midst of this
    1.30 +        [_conn _streamCanClose: self];
    1.31          return YES;
    1.32      }
    1.33  }
    1.34 @@ -140,6 +144,11 @@
    1.35      return NO;  // abstract
    1.36  }
    1.37  
    1.38 +- (BOOL) isActive
    1.39 +{
    1.40 +    return !_shouldClose || self.isBusy;
    1.41 +}
    1.42 +
    1.43  
    1.44  - (void) _opened
    1.45  {
    1.46 @@ -158,14 +167,7 @@
    1.47  
    1.48  - (void) _gotEOF
    1.49  {
    1.50 -    if( self.isBusy )
    1.51 -        [self _gotError: [NSError errorWithDomain: NSPOSIXErrorDomain code: ECONNRESET userInfo: nil]];
    1.52 -    else {
    1.53 -        [self retain];
    1.54 -        [_conn _streamGotEOF: self];
    1.55 -        [self disconnect];
    1.56 -        [self release];
    1.57 -    }
    1.58 +    [_conn _streamGotEOF: self];
    1.59  }
    1.60  
    1.61  - (BOOL) _gotError: (NSError*)error