@@ -88,17 +88,26 @@ return [[mainRunLoop retain] autorelease]; } + (OFRunLoop*)currentRunLoop { - return [[[OFThread objectForTLSKey: currentRunLoopKey] - retain] autorelease]; + OFRunLoop *runLoop = [OFThread objectForTLSKey: currentRunLoopKey]; + + if (runLoop == nil) { + runLoop = [[OFRunLoop alloc] init]; + [OFThread setObject: runLoop + forTLSKey: currentRunLoopKey]; + } + + return [[runLoop retain] autorelease]; } + (void)_setMainRunLoop: (OFRunLoop*)mainRunLoop_ { mainRunLoop = [mainRunLoop_ retain]; + [OFThread setObject: mainRunLoop + forTLSKey: currentRunLoopKey]; } #ifdef OF_HAVE_BLOCKS + (void)_addAsyncReadForStream: (OFStream*)stream buffer: (void*)buffer @@ -167,13 +176,10 @@ streamObserver = [[OFStreamObserver alloc] init]; [streamObserver setDelegate: self]; readQueues = [[OFMutableDictionary alloc] init]; - [OFThread setObject: self - forTLSKey: currentRunLoopKey]; - objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; }