Index: src/OFTCPSocket.h ================================================================== --- src/OFTCPSocket.h +++ src/OFTCPSocket.h @@ -47,10 +47,38 @@ @property (assign, readonly, getter=isListening) BOOL listening; @property (copy) OFString *SOCKS5Host; @property (assign) uint16_t SOCKS5Port; #endif +/** + * \brief Sets the global SOCKS5 proxy host to use when creating a new socket + * + * \param host The host to use as a SOCKS5 proxy when creating a new socket + */ ++ (void)setSOCKS5Host: (OFString*)host; + +/** + * \brief Returns the host to use as a SOCKS5 proxy when creating a new socket + * + * \return The host to use as a SOCKS5 proxy when creating a new socket + */ ++ (OFString*)SOCKS5Host; + +/** + * \brief Sets the global SOCKS5 proxy port to use when creating a new socket + * + * \param port The port to use as a SOCKS5 proxy when creating a new socket + */ ++ (void)setSOCKS5Port: (uint16_t)port; + +/** + * \brief Returns the port to use as a SOCKS5 proxy when creating a new socket + * + * \return The port to use as a SOCKS5 proxy when creating a new socket + */ ++ (uint16_t)SOCKS5Port; + /** * \brief Sets the host to use as a SOCKS5 proxy. * * \param host The host to use as a SOCKS5 proxy */ Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -68,29 +68,67 @@ void _references_to_categories_of_OFTCPSocket(void) { _OFTCPSocket_SOCKS5_reference = 1; } +static OFString *defaultSOCKS5Host = nil; +static uint16_t defaultSOCKS5Port = 1080; + @implementation OFTCPSocket #if defined(OF_THREADS) && !defined(HAVE_THREADSAFE_GETADDRINFO) + (void)initialize { if (self == [OFTCPSocket class]) mutex = [[OFMutex alloc] init]; } #endif + ++ (void)setSOCKS5Host: (OFString*)host +{ + id old = defaultSOCKS5Host; + defaultSOCKS5Host = [host copy]; + [old release]; +} + ++ (OFString*)SOCKS5Host +{ + return [[defaultSOCKS5Host copy] autorelease]; +} + ++ (void)setSOCKS5Port: (uint16_t)port +{ + defaultSOCKS5Port = port; +} + ++ (uint16_t)SOCKS5Port +{ + return defaultSOCKS5Port; +} - init { self = [super init]; - sock = INVALID_SOCKET; - sockAddr = NULL; - SOCKS5Port = 1080; + @try { + sock = INVALID_SOCKET; + sockAddr = NULL; + SOCKS5Host = [defaultSOCKS5Host copy]; + SOCKS5Port = defaultSOCKS5Port; + } @catch (id e) { + [self release]; + @throw e; + } return self; } + +- (void)dealloc +{ + [SOCKS5Host release]; + + [super dealloc]; +} - (void)setSOCKS5Host: (OFString*)host { OF_SETTER(SOCKS5Host, host, YES, YES) }