@@ -23,10 +23,12 @@ #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFDictionary.h" #ifdef OF_HAVE_SOCKETS # import "OFKernelEventObserver.h" +# import "OFTCPSocket.h" +# import "OFTCPSocket+Private.h" #endif #import "OFThread.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" # import "OFCondition.h" @@ -35,10 +37,13 @@ #import "OFTimer.h" #import "OFTimer+Private.h" #import "OFDate.h" #import "OFObserveFailedException.h" +#ifdef OF_HAVE_SOCKETS +# import "OFConnectionFailedException.h" +#endif static OFRunLoop *mainRunLoop = nil; #ifdef OF_HAVE_SOCKETS @interface OFRunLoop_QueueItem: OFObject @@ -92,10 +97,13 @@ # endif const void *_buffer; size_t _length, _writtenLength; } @end + +@interface OFRunLoop_ConnectQueueItem: OFRunLoop_QueueItem +@end @interface OFRunLoop_AcceptQueueItem: OFRunLoop_QueueItem { @public # ifdef OF_HAVE_BLOCKS @@ -332,10 +340,32 @@ [super dealloc]; } # endif @end + +@implementation OFRunLoop_ConnectQueueItem +- (bool)handleObject: (id)object +{ + id exception = nil; + int errNo; + void (*func)(id, SEL, OFTCPSocket *, id, id); + + if ((errNo = [object of_socketError]) != 0) + exception = [OFConnectionFailedException + exceptionWithHost: nil + port: 0 + socket: object + errNo: errNo]; + + func = (void (*)(id, SEL, OFTCPSocket *, id, id)) + [_target methodForSelector: _selector]; + func(_target, _selector, object, _context, exception); + + return false; +} +@end @implementation OFRunLoop_AcceptQueueItem - (bool)handleObject: (id)object { OFTCPSocket *newSocket; @@ -593,10 +623,22 @@ queueItem->_context = [context retain]; queueItem->_buffer = buffer; queueItem->_length = length; }) } + ++ (void)of_addAsyncConnectForTCPSocket: (OFTCPSocket *)stream + target: (id)target + selector: (SEL)selector + context: (id)context +{ + ADD_WRITE(OFRunLoop_ConnectQueueItem, stream, { + queueItem->_target = [target retain]; + queueItem->_selector = selector; + queueItem->_context = [context retain]; + }) +} + (void)of_addAsyncAcceptForTCPSocket: (OFTCPSocket *)stream target: (id)target selector: (SEL)selector context: (id)context