Differences From 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]
To Artifact [d516c427cd]:
- File
src/OFTCPSocket.m
— part of check-in
[f218986f51]
at
2018-12-18 14:14:25
on branch trunk
— Use OFData instead of a buffer for async writes
This avoids the entire problem of keeping the buffer alive until the
write finished. (user: js, size: 25724) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
359 360 361 362 363 364 365 366 | socketAddresses:context: exception:) context: nil]; } - (void)sendSOCKS5Request { _SOCKS5State = SOCKS5_STATE_SEND_AUTHENTICATION; | > > > | < | | 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | socketAddresses:context: exception:) context: nil]; } - (void)sendSOCKS5Request { OFData *data = [OFData dataWithItems: "\x05\x01\x00" count: 3]; _SOCKS5State = SOCKS5_STATE_SEND_AUTHENTICATION; [_socket asyncWriteData: data runLoopMode: [[OFRunLoop currentRunLoop] currentMode]]; } - (bool)stream: (OF_KINDOF(OFStream *))sock didReadIntoBuffer: (void *)buffer length: (size_t)length exception: (id)exception { |
︙ | ︙ | |||
415 416 417 418 419 420 421 | port[0] = _port >> 8; port[1] = _port & 0xFF; [_request addItems: port count: 2]; _SOCKS5State = SOCKS5_STATE_SEND_REQUEST; | | < | | 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | port[0] = _port >> 8; port[1] = _port & 0xFF; [_request addItems: port count: 2]; _SOCKS5State = SOCKS5_STATE_SEND_REQUEST; [_socket asyncWriteData: _request runLoopMode: runLoopMode]; return false; case SOCKS5_STATE_READ_RESPONSE: response = buffer; if (response[0] != 5 || response[2] != 0) { _exception = [[OFConnectionFailedException alloc] initWithHost: _host |
︙ | ︙ | |||
519 520 521 522 523 524 525 | return false; default: assert(0); return false; } } | | | | | | | | | | 520 521 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 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | return false; default: assert(0); return false; } } - (OFData *)stream: (OF_KINDOF(OFStream *))sock didWriteData: (OFData *)data bytesWritten: (size_t)bytesWritten exception: (id)exception { of_run_loop_mode_t runLoopMode; if (exception != nil) { _exception = [exception retain]; [self didConnect]; return nil; } runLoopMode = [[OFRunLoop currentRunLoop] currentMode]; switch (_SOCKS5State) { case SOCKS5_STATE_SEND_AUTHENTICATION: _SOCKS5State = SOCKS5_STATE_READ_VERSION; [_socket asyncReadIntoBuffer: _buffer exactLength: 2 runLoopMode: runLoopMode]; return nil; case SOCKS5_STATE_SEND_REQUEST: [_request release]; _request = nil; _SOCKS5State = SOCKS5_STATE_READ_RESPONSE; [_socket asyncReadIntoBuffer: _buffer exactLength: 4 runLoopMode: runLoopMode]; return nil; default: assert(0); return nil; } } @end @implementation OFTCPSocket_ConnectDelegate - (void)dealloc { |
︙ | ︙ |