@@ -33,11 +33,13 @@ #endif #import "OFTCPSocket.h" #import "OFTCPSocket+SOCKS5.h" #import "OFString.h" -#import "OFThread.h" +#ifdef OF_THREADS +# import "OFThread.h" +#endif #import "OFTimer.h" #import "OFRunLoop.h" #import "OFAcceptFailedException.h" #import "OFAlreadyConnectedException.h" @@ -77,37 +79,38 @@ Class of_tls_socket_class = Nil; static OFString *defaultSOCKS5Host = nil; static uint16_t defaultSOCKS5Port = 1080; +#ifdef OF_THREADS @interface OFTCPSocket_ConnectThread: OFThread { OFThread *sourceThread; OFTCPSocket *sock; OFString *host; uint16_t port; id target; SEL selector; -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS of_tcpsocket_async_connect_block_t connectBlock; -#endif +# endif OFException *exception; } - initWithSourceThread: (OFThread*)sourceThread socket: (OFTCPSocket*)socket host: (OFString*)host port: (uint16_t)port target: (id)target selector: (SEL)selector; -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS - initWithSourceThread: (OFThread*)sourceThread socket: (OFTCPSocket*)socket host: (OFString*)host port: (uint16_t)port block: (of_tcpsocket_async_connect_block_t)block; -#endif +# endif @end @implementation OFTCPSocket_ConnectThread - initWithSourceThread: (OFThread*)sourceThread_ socket: (OFTCPSocket*)sock_ @@ -131,11 +134,11 @@ } return self; } -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS - initWithSourceThread: (OFThread*)sourceThread_ socket: (OFTCPSocket*)sock_ host: (OFString*)host_ port: (uint16_t)port_ block: (of_tcpsocket_async_connect_block_t)block_ @@ -153,43 +156,43 @@ @throw e; } return self; } -#endif +# endif - (void)dealloc { [sourceThread release]; [sock release]; [host release]; [target release]; -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS [connectBlock release]; -#endif +# endif [exception release]; [super dealloc]; } - (void)didConnect { [self join]; -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS if (connectBlock != NULL) connectBlock(sock, exception); else { -#endif +# endif void (*func)(id, SEL, OFTCPSocket*, OFException*) = (void(*)(id, SEL, OFTCPSocket*, OFException*))[target methodForSelector: selector]; func(target, selector, sock, exception); -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS } -#endif +# endif } - (id)main { void *pool = objc_autoreleasePoolPush(); @@ -208,10 +211,11 @@ objc_autoreleasePoolPop(pool); return nil; } @end +#endif @implementation OFTCPSocket #if defined(OF_THREADS) && !defined(HAVE_THREADSAFE_GETADDRINFO) + (void)initialize { @@ -423,10 +427,11 @@ if (SOCKS5Host != nil) [self OF_SOCKS5ConnectToHost: destinationHost port: destinationPort]; } +#ifdef OF_THREADS - (void)asyncConnectToHost: (OFString*)host port: (uint16_t)port target: (id)target selector: (SEL)selector { @@ -441,11 +446,11 @@ selector: selector] autorelease] start]; objc_autoreleasePoolPop(pool); } -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS - (void)asyncConnectToHost: (OFString*)host port: (uint16_t)port block: (of_tcpsocket_async_connect_block_t)block { void *pool = objc_autoreleasePoolPush(); @@ -457,10 +462,11 @@ port: port block: block] autorelease] start]; objc_autoreleasePoolPop(pool); } +# endif #endif - (uint16_t)bindToHost: (OFString*)host port: (uint16_t)port {