Changeset 3673

Show
Ignore:
Timestamp:
02/06/06 00:08:05 (3 years ago)
Author:
morris
Message:

Consolidate linkFailed and linkClosed

Fix a crash with autoreleased error popped

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredClient/trunk/WCConnection.h

    r3570 r3673  
    9999 
    100100#define WCConnectionDidConnect                  @"WCConnectionDidConnect" 
    101 #define WCConnectionDidFail                             @"WCConnectionDidFail" 
    102101#define WCConnectionDidClose                    @"WCConnectionDidClose" 
    103102#define WCConnectionWillTerminate               @"WCConnectionWillTerminate" 
  • WiredClient/trunk/WCLink.h

    r3661 r3673  
    3737        id                                              _delegate; 
    3838        BOOL                                    _delegateLinkConnected; 
    39         BOOL                                    _delegateLinkFailed; 
    4039        BOOL                                    _delegateLinkClosed; 
    4140        BOOL                                    _delegateLinkTerminated; 
     
    7271 
    7372- (void)linkConnected:(WCLink *)link; 
    74 - (void)linkClosed:(WCLink *)link; 
    75 - (void)linkFailed:(WCLink *)link error:(WIError *)error; 
     73- (void)linkClosed:(WCLink *)link error:(WIError *)error; 
    7674- (void)linkTerminated:(WCLink *)link; 
    7775- (void)link:(WCLink *)link sentCommand:(NSString *)command; 
  • WiredClient/trunk/WCLink.m

    r3664 r3673  
    7979         
    8080        _delegateLinkConnected = [_delegate respondsToSelector:@selector(linkConnected:)]; 
    81         _delegateLinkClosed = [_delegate respondsToSelector:@selector(linkClosed:)]; 
    82         _delegateLinkFailed = [_delegate respondsToSelector:@selector(linkFailed:error:)]; 
     81        _delegateLinkClosed = [_delegate respondsToSelector:@selector(linkClosed:error:)]; 
    8382        _delegateLinkTerminated = [_delegate respondsToSelector:@selector(linkTerminated:)]; 
    8483        _delegateLinkSentCommand = [_delegate respondsToSelector:@selector(link:sentCommand:)]; 
     
    202201         
    203202        if(!address) { 
    204                if(_delegateLinkFailed) 
    205                        [_delegate linkFailed:self error:error]; 
    206                  
    207                 goto end
     203//             if(_delegateLinkClosed) 
     204//                     [_delegate linkClosed:self error:error]; 
     205                 
     206                goto close
    208207        } 
    209208         
     
    214213         
    215214        if(![_socket connectWithContext:context timeout:10.0 error:&error]) { 
    216                 if(!_closing) 
    217                         failed = YES; 
     215                failed = YES; 
    218216                 
    219217                goto close; 
    220218        } 
    221219         
    222         if(!_closing && _delegateLinkConnected) 
     220        if(_delegateLinkConnected) 
    223221                [_delegate linkConnected:self]; 
    224222         
    225         while(YES) { 
     223        while(!_closing) { 
    226224                if(!loopPool) 
    227225                        loopPool = [[NSAutoreleasePool alloc] init]; 
     
    230228                string = [_socket readStringUpToString:WCMessageSeparator encoding:NSUTF8StringEncoding timeout:1.0 error:&error]; 
    231229                 
    232                 if(_closing) 
     230                if(_closing || (string && [string length] == 0)) { 
    233231                        goto close; 
    234                 else if(string && [string length] == 0) 
    235                         goto close; 
     232                } 
    236233                else if(!string) { 
    237234                        if([[[error userInfo] objectForKey:WILibWiredErrorKey] code] == ETIMEDOUT) { 
     
    257254         
    258255close: 
    259         [loopPool release]; 
    260  
    261         _reading = NO; 
    262          
    263256        [_pingTimer invalidate]; 
    264          
     257                
    265258        if(_closing) { 
    266259                if(_delegateLinkTerminated) 
    267260                        [_delegate linkTerminated:self]; 
    268261        } else { 
    269                 if(failed && _delegateLinkFailed) 
    270                         [_delegate linkFailed:self error:error]; 
    271                  
    272262                if(_delegateLinkClosed) 
    273                         [_delegate linkClosed:self]; 
    274         } 
    275          
     263                        [_delegate linkClosed:self error:error]; 
     264        } 
     265         
     266        _reading = NO; 
     267 
    276268        if(!failed) 
    277269                [_socket close]; 
    278270         
    279 end: 
     271        [_socket release]; 
     272         
    280273        [_delegate release]; 
     274        [loopPool release]; 
    281275        [pool release]; 
    282276} 
  • WiredClient/trunk/WCPublicChat.m

    r3646 r3673  
    299299                 
    300300                if(![[self connection] isReconnecting]) { 
    301                         error = [WCError errorWithDomain:WCWiredClientErrorDomain code:WCWiredClientServerDisconnected]; 
     301                        error = [[notification userInfo] objectForKey:WCErrorKey]; 
     302                         
     303                        if(!error) 
     304                                error = [WCError errorWithDomain:WCWiredClientErrorDomain code:WCWiredClientServerDisconnected]; 
     305                         
    302306                        [[error alert] beginSheetModalForWindow:[self window]]; 
    303307                } 
  • WiredClient/trunk/WCServerConnection.m

    r3662 r3673  
    9292 
    9393        [self addObserver:self 
    94                          selector:@selector(connectionDidFail:) 
    95                                  name:WCConnectionDidFail]; 
    96  
    97         [self addObserver:self 
    9894                         selector:@selector(connectionWillTerminate:) 
    9995                                 name:WCConnectionWillTerminate]; 
     
    328324 
    329325 
    330 - (void)connectionDidFail:(NSNotification *)notification { 
    331         WCError         *error; 
    332          
    333         [_progressIndicator stopAnimation:self]; 
    334  
    335         error = [[notification userInfo] objectForKey:WCErrorKey]; 
    336          
    337         if([[self window] isVisible]) 
    338                 [[error alert] beginSheetModalForWindow:[self window]]; 
    339         else 
    340                 [[error alert] runModal]; 
    341 } 
    342  
    343  
    344  
    345326- (void)connectionWillTerminate:(NSNotification *)notification { 
    346327        if(!_closingWindow) 
     
    374355 
    375356- (void)connectionDidClose:(NSNotification *)notification { 
     357        WCError         *error; 
     358         
    376359        [_progressIndicator stopAnimation:self]; 
     360         
     361        error = [[notification userInfo] objectForKey:WCErrorKey]; 
     362         
     363        if(error && [[self window] isVisible]) 
     364                [[error alert] beginSheetModalForWindow:[self window]]; 
    377365         
    378366        [_link release]; 
     
    597585 
    598586 
    599 - (void)linkClosed:(WCLink *)link { 
    600         [self postNotificationName:WCConnectionDidClose object:self]; 
    601 
    602  
    603  
    604  
    605 - (void)linkFailed:(WCLink *)link error:(WIError *)error { 
    606         [self postNotificationName:WCConnectionDidFail object:self userInfo:[NSDictionary dictionaryWithObject:error forKey:WCErrorKey]]; 
     587- (void)linkClosed:(WCLink *)link error:(WIError *)error { 
     588        if(error) 
     589                [self postNotificationName:WCConnectionDidClose object:self userInfo:[NSDictionary dictionaryWithObject:error forKey:WCErrorKey]]; 
     590        else 
     591                [self postNotificationName:WCConnectionDidClose object:self]; 
    607592} 
    608593 
  • WiredClient/trunk/WCTrackerConnection.m

    r3596 r3673  
    232232 
    233233 
    234 - (void)linkClosed:(WCLink *)link { 
    235         [self postNotificationName:WCConnectionDidClose object:self]; 
    236 
    237  
    238  
    239  
    240 - (void)linkFailed:(WCLink *)link error:(WIError *)error { 
    241         [self postNotificationName:WCConnectionDidFail object:self userInfo:[NSDictionary dictionaryWithObject:error forKey:WCErrorKey]]; 
     234- (void)linkClosed:(WCLink *)link error:(WIError *)error { 
     235        if(error) 
     236                [self postNotificationName:WCConnectionDidClose object:self userInfo:[NSDictionary dictionaryWithObject:error forKey:WCErrorKey]]; 
     237        else 
     238                [self postNotificationName:WCConnectionDidClose object:self]; 
    242239} 
    243240 
  • WiredClient/trunk/WCTrackers.m

    r3653 r3673  
    212212 
    213213        [connection addObserver:self 
    214                                    selector:@selector(connectionDidFail:) 
    215                                            name:WCConnectionDidFail]; 
     214                                   selector:@selector(connectionDidClose:) 
     215                                           name:WCConnectionDidClose]; 
    216216 
    217217        [connection addObserver:self 
     
    327327 
    328328 
    329 - (void)connectionDidFail:(NSNotification *)notification { 
     329- (void)connectionDidClose:(NSNotification *)notification { 
    330330        WCTrackerConnection     *connection; 
    331331        WCError                         *error; 
    332  
    333         connection = [notification object]; 
     332         
    334333        error = [[notification userInfo] objectForKey:WCErrorKey]; 
    335334         
     335        if(!error) 
     336                error = [WCError errorWithDomain:WCWiredClientErrorDomain code:WCWiredClientServerDisconnected]; 
     337         
    336338        [[error alert] beginSheetModalForWindow:[self window]]; 
     339         
     340        [_progressIndicator stopAnimation:self]; 
    337341         
    338342        [connection terminate];