Index: src/OFThread.h ================================================================== --- src/OFThread.h +++ src/OFThread.h @@ -24,10 +24,13 @@ OF_ASSUME_NONNULL_BEGIN /*! @file */ @class OFDate; +#ifdef OF_HAVE_SOCKETS +@class OFDNSResolver; +#endif @class OFRunLoop; @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); #if defined(OF_HAVE_THREADS) && defined(OF_HAVE_BLOCKS) /*! @@ -72,20 +75,30 @@ id _returnValue; OFRunLoop *_Nullable _runLoop; OFMutableDictionary *_threadDictionary; @private OFString *_Nullable _name; +# ifdef OF_HAVE_SOCKETS + OFDNSResolver *_DNSResolver; +# endif } +#endif -# ifdef OF_HAVE_CLASS_PROPERTIES +#ifdef OF_HAVE_CLASS_PROPERTIES +# ifdef OF_HAVE_THREADS @property (class, readonly, nullable, nonatomic) OFThread *currentThread; @property (class, readonly, nullable, nonatomic) OFThread *mainThread; @property (class, readonly, nullable, nonatomic) OFMutableDictionary *threadDictionary; @property (class, nullable, copy, nonatomic) OFString *name; # endif +# ifdef OF_HAVE_SOCKETS +@property (class, readonly, nonatomic) OFDNSResolver *DNSResolver; +# endif +#endif +#ifdef OF_HAVE_THREADS /*! * @brief The name for the thread to use when starting it. * * @note While this can be changed after the thread has been started, it will * have no effect once the thread started. If you want to change the name @@ -158,14 +171,23 @@ /*! * @brief Returns a dictionary to store thread-specific data, meaning it * returns a different dictionary for every thread. * - * @return A dictionary to store thread-specific data. + * @return A dictionary to store thread-specific data */ + (nullable OFMutableDictionary *)threadDictionary; #endif + +#ifdef OF_HAVE_SOCKETS +/*! + * @brief Returns the DNS resolver for the current thread. + * + * @return The DNS resolver for the current thread + */ ++ (OFDNSResolver *)DNSResolver; +#endif /*! * @brief Suspends execution of the current thread for the specified time * interval. * Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -50,11 +50,13 @@ #import "OFThread+Private.h" #import "OFAutoreleasePool+Private.h" #import "OFAutoreleasePool.h" #import "OFDate.h" #import "OFDictionary.h" -#import "OFList.h" +#ifdef OF_HAVE_SOCKETS +# import "OFDNSResolver.h" +#endif #import "OFLocale.h" #import "OFRunLoop.h" #import "OFString.h" #ifdef OF_WINDOWS @@ -128,10 +130,12 @@ objc_autoreleasePoolPop(thread->_pool); [OFAutoreleasePool of_handleThreadTermination]; [thread release]; } +#else +static OFDNSResolver *DNSResolver; #endif @implementation OFThread #ifdef OF_HAVE_THREADS @synthesize name = _name; @@ -182,10 +186,32 @@ thread->_threadDictionary = [[OFMutableDictionary alloc] init]; return thread->_threadDictionary; } #endif + +#ifdef OF_HAVE_SOCKETS ++ (OFDNSResolver *)DNSResolver +{ +# ifdef OF_HAVE_THREADS + OFThread *thread = of_tlskey_get(threadSelfKey); + + if (thread == nil) + return nil; + + if (thread->_DNSResolver == nil) + thread->_DNSResolver = [[OFDNSResolver alloc] init]; + + return thread->_DNSResolver; +# else + if (DNSResolver == nil) + DNSResolver = [[OFDNSResolver alloc] init]; + + return DNSResolver; +# endif +} +#endif + (void)sleepForTimeInterval: (of_time_interval_t)timeInterval { if (timeInterval < 0) return; @@ -352,10 +378,15 @@ _runLoop = nil; [oldRunLoop release]; [_threadDictionary release]; _threadDictionary = nil; + +# ifdef OF_HAVE_SOCKETS + [_DNSResolver release]; + _DNSResolver = nil; +# endif } - (void)start { if (_running == OF_THREAD_RUNNING)