Changeset 3673
- Timestamp:
- 02/06/06 00:08:05 (3 years ago)
- Files:
-
- WiredClient/trunk/WCConnection.h (modified) (1 diff)
- WiredClient/trunk/WCLink.h (modified) (2 diffs)
- WiredClient/trunk/WCLink.m (modified) (5 diffs)
- WiredClient/trunk/WCPublicChat.m (modified) (1 diff)
- WiredClient/trunk/WCServerConnection.m (modified) (4 diffs)
- WiredClient/trunk/WCTrackerConnection.m (modified) (1 diff)
- WiredClient/trunk/WCTrackers.m (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
WiredClient/trunk/WCConnection.h
r3570 r3673 99 99 100 100 #define WCConnectionDidConnect @"WCConnectionDidConnect" 101 #define WCConnectionDidFail @"WCConnectionDidFail"102 101 #define WCConnectionDidClose @"WCConnectionDidClose" 103 102 #define WCConnectionWillTerminate @"WCConnectionWillTerminate" WiredClient/trunk/WCLink.h
r3661 r3673 37 37 id _delegate; 38 38 BOOL _delegateLinkConnected; 39 BOOL _delegateLinkFailed;40 39 BOOL _delegateLinkClosed; 41 40 BOOL _delegateLinkTerminated; … … 72 71 73 72 - (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; 76 74 - (void)linkTerminated:(WCLink *)link; 77 75 - (void)link:(WCLink *)link sentCommand:(NSString *)command; WiredClient/trunk/WCLink.m
r3664 r3673 79 79 80 80 _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:)]; 83 82 _delegateLinkTerminated = [_delegate respondsToSelector:@selector(linkTerminated:)]; 84 83 _delegateLinkSentCommand = [_delegate respondsToSelector:@selector(link:sentCommand:)]; … … 202 201 203 202 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; 208 207 } 209 208 … … 214 213 215 214 if(![_socket connectWithContext:context timeout:10.0 error:&error]) { 216 if(!_closing) 217 failed = YES; 215 failed = YES; 218 216 219 217 goto close; 220 218 } 221 219 222 if( !_closing &&_delegateLinkConnected)220 if(_delegateLinkConnected) 223 221 [_delegate linkConnected:self]; 224 222 225 while( YES) {223 while(!_closing) { 226 224 if(!loopPool) 227 225 loopPool = [[NSAutoreleasePool alloc] init]; … … 230 228 string = [_socket readStringUpToString:WCMessageSeparator encoding:NSUTF8StringEncoding timeout:1.0 error:&error]; 231 229 232 if(_closing )230 if(_closing || (string && [string length] == 0)) { 233 231 goto close; 234 else if(string && [string length] == 0) 235 goto close; 232 } 236 233 else if(!string) { 237 234 if([[[error userInfo] objectForKey:WILibWiredErrorKey] code] == ETIMEDOUT) { … … 257 254 258 255 close: 259 [loopPool release];260 261 _reading = NO;262 263 256 [_pingTimer invalidate]; 264 257 265 258 if(_closing) { 266 259 if(_delegateLinkTerminated) 267 260 [_delegate linkTerminated:self]; 268 261 } else { 269 if(failed && _delegateLinkFailed)270 [_delegate linkFailed:self error:error];271 272 262 if(_delegateLinkClosed) 273 [_delegate linkClosed:self]; 274 } 275 263 [_delegate linkClosed:self error:error]; 264 } 265 266 _reading = NO; 267 276 268 if(!failed) 277 269 [_socket close]; 278 270 279 end: 271 [_socket release]; 272 280 273 [_delegate release]; 274 [loopPool release]; 281 275 [pool release]; 282 276 } WiredClient/trunk/WCPublicChat.m
r3646 r3673 299 299 300 300 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 302 306 [[error alert] beginSheetModalForWindow:[self window]]; 303 307 } WiredClient/trunk/WCServerConnection.m
r3662 r3673 92 92 93 93 [self addObserver:self 94 selector:@selector(connectionDidFail:)95 name:WCConnectionDidFail];96 97 [self addObserver:self98 94 selector:@selector(connectionWillTerminate:) 99 95 name:WCConnectionWillTerminate]; … … 328 324 329 325 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 else340 [[error alert] runModal];341 }342 343 344 345 326 - (void)connectionWillTerminate:(NSNotification *)notification { 346 327 if(!_closingWindow) … … 374 355 375 356 - (void)connectionDidClose:(NSNotification *)notification { 357 WCError *error; 358 376 359 [_progressIndicator stopAnimation:self]; 360 361 error = [[notification userInfo] objectForKey:WCErrorKey]; 362 363 if(error && [[self window] isVisible]) 364 [[error alert] beginSheetModalForWindow:[self window]]; 377 365 378 366 [_link release]; … … 597 585 598 586 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]; 607 592 } 608 593 WiredClient/trunk/WCTrackerConnection.m
r3596 r3673 232 232 233 233 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]; 242 239 } 243 240 WiredClient/trunk/WCTrackers.m
r3653 r3673 212 212 213 213 [connection addObserver:self 214 selector:@selector(connectionDid Fail:)215 name:WCConnectionDid Fail];214 selector:@selector(connectionDidClose:) 215 name:WCConnectionDidClose]; 216 216 217 217 [connection addObserver:self … … 327 327 328 328 329 - (void)connectionDid Fail:(NSNotification *)notification {329 - (void)connectionDidClose:(NSNotification *)notification { 330 330 WCTrackerConnection *connection; 331 331 WCError *error; 332 333 connection = [notification object]; 332 334 333 error = [[notification userInfo] objectForKey:WCErrorKey]; 335 334 335 if(!error) 336 error = [WCError errorWithDomain:WCWiredClientErrorDomain code:WCWiredClientServerDisconnected]; 337 336 338 [[error alert] beginSheetModalForWindow:[self window]]; 339 340 [_progressIndicator stopAnimation:self]; 337 341 338 342 [connection terminate];
