Differences From Artifact [349339a041]:
- File src/OFTCPSocket.m — part of check-in [da2dd2dde5] at 2018-12-08 18:55:26 on branch trunk — OFUDPSocket: Use a delegate for async operations (user: js, size: 26067) [annotate] [blame] [check-ins using]
To Artifact [dd4630f033]:
- File
src/OFTCPSocket.m
— part of check-in
[064dbe5127]
at
2018-12-11 22:57:46
on branch trunk
— Include an exception in delegate methods
Otherwise, there would be two methods for every operation: One for
success and one for failure. It also makes it easy to forget about
handling failure, so it's better to always pass an optional exception. (user: js, size: 25706) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
208 209 210 211 212 213 214 | #ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(_socket, _exception); else { #endif [_socket setDelegate: _delegate]; | < | | | | | < < < < | < < < | 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | #ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(_socket, _exception); else { #endif [_socket setDelegate: _delegate]; if ([_delegate respondsToSelector: @selector(socket:didConnectToHost:port:exception:)]) [_delegate socket: _socket didConnectToHost: _host port: _port exception: _exception]; #ifdef OF_HAVE_BLOCKS } #endif } - (void)of_socketDidConnect: (OF_KINDOF(OFTCPSocket *))sock exception: (id)exception |
︙ | ︙ | |||
376 377 378 379 380 381 382 383 | length: 3 runLoopMode: [[OFRunLoop currentRunLoop] currentMode]]; } - (bool)stream: (OF_KINDOF(OFStream *))sock didReadIntoBuffer: (void *)buffer length: (size_t)length { | > | < > > > > > > > > | 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | length: 3 runLoopMode: [[OFRunLoop currentRunLoop] currentMode]]; } - (bool)stream: (OF_KINDOF(OFStream *))sock didReadIntoBuffer: (void *)buffer length: (size_t)length exception: (id)exception { of_run_loop_mode_t runLoopMode; unsigned char *SOCKSVersion; uint8_t hostLength; unsigned char port[2]; unsigned char *response, *addressLength; if (exception != nil) { _exception = [exception retain]; [self didConnect]; return false; } runLoopMode = [[OFRunLoop currentRunLoop] currentMode]; switch (_SOCKS5State) { case SOCKS5_STATE_READ_VERSION: SOCKSVersion = buffer; if (SOCKSVersion[0] != 5 || SOCKSVersion[1] != 0) { _exception = [[OFConnectionFailedException alloc] initWithHost: _host |
︙ | ︙ | |||
522 523 524 525 526 527 528 529 | return false; } } - (size_t)stream: (OF_KINDOF(OFStream *))sock didWriteBuffer: (const void **)buffer length: (size_t)length { | > | > > > > > > > | | 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | return false; } } - (size_t)stream: (OF_KINDOF(OFStream *))sock didWriteBuffer: (const void **)buffer length: (size_t)length exception: (id)exception { of_run_loop_mode_t runLoopMode; if (exception != nil) { _exception = [exception retain]; [self didConnect]; return 0; } runLoopMode = [[OFRunLoop currentRunLoop] currentMode]; switch (_SOCKS5State) { case SOCKS5_STATE_SEND_AUTHENTICATION: _SOCKS5State = SOCKS5_STATE_READ_VERSION; [_socket asyncReadIntoBuffer: _buffer exactLength: 2 runLoopMode: runLoopMode]; |
︙ | ︙ | |||
547 548 549 550 551 552 553 | runLoopMode: runLoopMode]; return 0; default: assert(0); return 0; } } | < < < < < < < < < < < < < < < < < < < | | 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | runLoopMode: runLoopMode]; return 0; default: assert(0); return 0; } } @end @implementation OFTCPSocket_ConnectDelegate - (void)dealloc { [_exception release]; [super dealloc]; } - (void)socket: (OF_KINDOF(OFTCPSocket *))sock didConnectToHost: (OFString *)host port: (uint16_t)port exception: (id)exception { _done = true; _exception = [exception retain]; } @end @implementation OFTCPSocket |
︙ | ︙ |