@@ -210,24 +210,16 @@ _block(_socket, _exception); else { #endif [_socket setDelegate: _delegate]; - if (_exception == nil) { - if ([_delegate respondsToSelector: - @selector(socket:didConnectToHost:port:)]) - [_delegate socket: _socket - didConnectToHost: _host - port: _port]; - } else { - if ([_delegate respondsToSelector: @selector(socket: - didFailToConnectWithException:host:port:)]) - [_delegate socket: _socket - didFailToConnectWithException: _exception - host: _host - port: _port]; - } + if ([_delegate respondsToSelector: + @selector(socket:didConnectToHost:port:exception:)]) + [_delegate socket: _socket + didConnectToHost: _host + port: _port + exception: _exception]; #ifdef OF_HAVE_BLOCKS } #endif } @@ -378,18 +370,26 @@ } - (bool)stream: (OF_KINDOF(OFStream *))sock didReadIntoBuffer: (void *)buffer length: (size_t)length + exception: (id)exception { - of_run_loop_mode_t runLoopMode = - [[OFRunLoop currentRunLoop] currentMode]; + 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) { @@ -524,13 +524,21 @@ } - (size_t)stream: (OF_KINDOF(OFStream *))sock didWriteBuffer: (const void **)buffer length: (size_t)length + exception: (id)exception { - of_run_loop_mode_t runLoopMode = - [[OFRunLoop currentRunLoop] currentMode]; + 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 @@ -549,24 +557,10 @@ default: assert(0); return 0; } } - -- (void)stream: (OF_KINDOF(OFStream *))sock - didFailToReadWithException: (id)exception -{ - _exception = [exception retain]; - [self didConnect]; -} - -- (void)stream: (OF_KINDOF(OFStream *))sock - didFailToWriteWithException: (id)exception -{ - _exception = [exception retain]; - [self didConnect]; -} @end @implementation OFTCPSocket_ConnectDelegate - (void)dealloc { @@ -576,16 +570,11 @@ } - (void)socket: (OF_KINDOF(OFTCPSocket *))sock didConnectToHost: (OFString *)host port: (uint16_t)port -{ - _done = true; -} - -- (void)socket: (OF_KINDOF(OFTCPSocket *))sock - didFailToConnectWithException: (id)exception + exception: (id)exception { _done = true; _exception = [exception retain]; } @end