@@ -13,11 +13,10 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -#define OF_TCP_SOCKET_M #define __NO_EXT_QNX #include "config.h" #include @@ -101,19 +100,15 @@ - (instancetype)initWithSocket: (OFTCPSocket *)sock host: (OFString *)host port: (uint16_t)port SOCKS5Host: (OFString *)SOCKS5Host SOCKS5Port: (uint16_t)SOCKS5Port - delegate: (id )delegate; + delegate: (id )delegate #ifdef OF_HAVE_BLOCKS -- (instancetype)initWithSocket: (OFTCPSocket *)sock - host: (OFString *)host - port: (uint16_t)port - SOCKS5Host: (OFString *)SOCKS5Host - SOCKS5Port: (uint16_t)SOCKS5Port - block: (of_tcp_socket_async_connect_block_t)block; + block: (of_tcp_socket_async_connect_block_t)block #endif +; - (void)didConnect; - (void)tryNextAddressWithRunLoopMode: (of_run_loop_mode_t)runLoopMode; - (void)startWithRunLoopMode: (of_run_loop_mode_t)runLoopMode; - (void)sendSOCKS5Request; @end @@ -131,10 +126,13 @@ host: (OFString *)host port: (uint16_t)port SOCKS5Host: (OFString *)SOCKS5Host SOCKS5Port: (uint16_t)SOCKS5Port delegate: (id )delegate +#ifdef OF_HAVE_BLOCKS + block: (of_tcp_socket_async_connect_block_t)block +#endif { self = [super init]; @try { _socket = [sock retain]; @@ -141,10 +139,13 @@ _host = [host copy]; _port = port; _SOCKS5Host = [SOCKS5Host copy]; _SOCKS5Port = SOCKS5Port; _delegate = [delegate retain]; +#ifdef OF_HAVE_BLOCKS + _block = [block copy]; +#endif _socket.delegate = self; } @catch (id e) { [self release]; @throw e; @@ -151,36 +152,10 @@ } return self; } -#ifdef OF_HAVE_BLOCKS -- (instancetype)initWithSocket: (OFTCPSocket *)sock - host: (OFString *)host - port: (uint16_t)port - SOCKS5Host: (OFString *)SOCKS5Host - SOCKS5Port: (uint16_t)SOCKS5Port - block: (of_tcp_socket_async_connect_block_t)block -{ - self = [super init]; - - @try { - _socket = [sock retain]; - _host = [host copy]; - _port = port; - _SOCKS5Host = [SOCKS5Host copy]; - _SOCKS5Port = SOCKS5Port; - _block = [block copy]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} -#endif - - (void)dealloc { #ifdef OF_HAVE_BLOCKS if (_block == NULL) #endif @@ -265,10 +240,18 @@ if (_SOCKS5Host != nil) [self sendSOCKS5Request]; else [self didConnect]; } + +- (id)of_connectionFailedExceptionForErrNo: (int)errNo +{ + return [OFConnectionFailedException exceptionWithHost: _host + port: _port + socket: _socket + errNo: errNo]; +} - (void)tryNextAddressWithRunLoopMode: (of_run_loop_mode_t)runLoopMode { of_socket_address_t address = *(const of_socket_address_t *) [_socketAddresses itemAtIndex: _socketAddressesIndex++]; @@ -701,11 +684,11 @@ errNo: (int *)errNo { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; - if (connect(_socket, (struct sockaddr *)&address->sockaddr.sockaddr, + if (connect(_socket, &address->sockaddr.sockaddr, address->length) != 0) { *errNo = of_socket_errno(); return false; } @@ -766,12 +749,15 @@ initWithSocket: self host: host port: port SOCKS5Host: _SOCKS5Host SOCKS5Port: _SOCKS5Port - delegate: _delegate] autorelease] - startWithRunLoopMode: runLoopMode]; + delegate: _delegate +#ifdef OF_HAVE_BLOCKS + block: NULL +#endif + ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS @@ -796,10 +782,11 @@ initWithSocket: self host: host port: port SOCKS5Host: _SOCKS5Host SOCKS5Port: _SOCKS5Port + delegate: nil block: block] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); }