Changeset 3661

Show
Ignore:
Timestamp:
01/29/06 02:28:14 (3 years ago)
Author:
morris
Message:

Bring back automatic server pinging

Add /ping command

Files:

Legend:

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

    r3545 r3661  
    6666        NSDate                                                          *_timestamp; 
    6767        WCTopic                                                         *_topic; 
     68         
     69        BOOL                                                            _receivingPings; 
     70        NSTimeInterval                                          _pingInterval; 
    6871} 
    6972 
  • WiredClient/trunk/WCChat.m

    r3646 r3661  
    309309                @"/topic", 
    310310                @"/broadcast", 
    311  
    312                 @"/benchmark", 
    313                 @"/scan", 
     311                @"/ping", 
    314312                NULL]; 
    315313} 
     
    439437        } 
    440438#endif 
     439        else if([command isEqualToString:@"/ping"]) { 
     440                if(!_receivingPings) { 
     441                        [[self connection] addObserver:self 
     442                                                                  selector:@selector(serverConnectionReceivedPing:) 
     443                                                                          name:WCServerConnectionReceivedPing]; 
     444                         
     445                        _receivingPings = YES; 
     446                } 
     447                 
     448                _pingInterval = [NSDate timeIntervalSinceReferenceDate]; 
     449                 
     450                [[self connection] sendCommand:WCPingCommand]; 
     451                 
     452                return YES; 
     453        } 
    441454 
    442455        return NO; 
     
    645658 
    646659        [self validate]; 
     660} 
     661 
     662 
     663 
     664- (void)serverConnectionReceivedPing:(NSNotification *)notification { 
     665        NSTimeInterval          interval; 
     666         
     667        interval = [NSDate timeIntervalSinceReferenceDate]; 
     668         
     669        [self printEvent:[NSSWF: 
     670                NSLS(@"Received ping reply after %.2fms", @"Ping received message (interval)"), 
     671                (interval - _pingInterval) * 1000.0]]; 
     672         
     673        [[self connection] removeObserver:self name:WCServerConnectionReceivedPing]; 
     674 
     675        _receivingPings = NO; 
    647676} 
    648677 
  • WiredClient/trunk/WCLink.h

    r3525 r3661  
    3232        WISocket                                *_socket; 
    3333        WIURL                                   *_url; 
     34         
     35        NSTimer                                 *_pingTimer; 
    3436         
    3537        id                                              _delegate; 
  • WiredClient/trunk/WCLink.m

    r3659 r3661  
    6565 
    6666- (void)dealloc { 
     67        NSLog(@"%@ dealloc", self); 
     68         
    6769        [_url release]; 
     70        [_pingTimer release]; 
    6871         
    6972        [super dealloc]; 
     
    120123 
    121124        [WIThread detachNewThreadSelector:@selector(linkThread:) toTarget:self withObject:NULL]; 
     125         
     126        _pingTimer = [[NSTimer scheduledTimerWithTimeInterval:60.0 
     127                                                                                                   target:self 
     128                                                                                                 selector:@selector(pingTimer:) 
     129                                                                                                 userInfo:NULL 
     130                                                                                                  repeats:YES] retain]; 
     131         
    122132} 
    123133 
     
    127137        _closing = YES; 
    128138        _reading = NO; 
     139         
     140        [_pingTimer invalidate]; 
    129141} 
    130142 
     
    214226        if(!_closing && _delegateLinkConnected) 
    215227                [_delegate linkConnected:self]; 
    216  
     228         
    217229        while(YES) { 
    218230                if(!loopPool) 
     
    248260        } 
    249261         
     262close: 
    250263        [loopPool release]; 
    251264 
    252 close: 
    253265        _reading = NO; 
    254266         
     
    272284} 
    273285 
     286 
     287 
     288- (void)pingTimer:(NSTimer *)timer { 
     289        [self sendCommand:WCPingCommand]; 
     290} 
     291 
    274292@end