Index: src/OFRunLoop.h ================================================================== --- src/OFRunLoop.h +++ src/OFRunLoop.h @@ -80,10 +80,11 @@ encoding: (of_string_encoding_t)encoding block: (of_stream_async_read_line_block_t)block; + (void)OF_addAsyncAcceptForTCPSocket: (OFTCPSocket*)socket block: (of_tcpsocket_async_accept_block_t)block; #endif ++ (void)OF_cancelAsyncRequestsForStream: (OFStream*)stream; /*! * @brief Adds an OFTimer to the run loop. * * @param timer The timer to add Index: src/OFRunLoop.m ================================================================== --- src/OFRunLoop.m +++ src/OFRunLoop.m @@ -13,10 +13,12 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" + +#include #import "OFRunLoop.h" #import "OFDictionary.h" #import "OFThread.h" #import "OFSortedList.h" @@ -258,10 +260,26 @@ }) } #endif #undef ADD + ++ (void)OF_cancelAsyncRequestsForStream: (OFStream*)stream +{ + void *pool = objc_autoreleasePoolPush(); + OFRunLoop *runLoop = [self currentRunLoop]; + OFList *queue; + + if ((queue = [runLoop->readQueues objectForKey: stream]) != nil) { + assert([queue count] > 0); + + [runLoop->streamObserver removeStreamForReading: stream]; + [runLoop->readQueues removeObjectForKey: stream]; + } + + objc_autoreleasePoolPop(pool); +} - init { self = [super init]; Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -1019,10 +1019,15 @@ * * @return The file descriptor for the write end of the stream */ - (int)fileDescriptorForWriting; +/*! + * @brief Cancels all pending asyncronous requests on the stream. + */ +- (void)cancelAsyncRequests; + /*! * @brief Closes the stream. */ - (void)close; Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -721,13 +721,13 @@ } - (void)asyncReadLineWithTarget: (id)target selector: (SEL)selector { - return [self asyncReadLineWithEncoding: OF_STRING_ENCODING_UTF_8 - target: target - selector: selector]; + [self asyncReadLineWithEncoding: OF_STRING_ENCODING_UTF_8 + target: target + selector: selector]; } - (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding target: (id)target selector: (SEL)selector @@ -739,12 +739,12 @@ } #ifdef OF_HAVE_BLOCKS - (void)asyncReadLineWithBlock: (of_stream_async_read_line_block_t)block { - return [self asyncReadLineWithEncoding: OF_STRING_ENCODING_UTF_8 - block: block]; + [self asyncReadLineWithEncoding: OF_STRING_ENCODING_UTF_8 + block: block]; } - (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding block: (of_stream_async_read_line_block_t)block { @@ -1497,10 +1497,15 @@ - (int)fileDescriptorForWriting { @throw [OFNotImplementedException exceptionWithClass: [self class] selector: _cmd]; } + +- (void)cancelAsyncRequests +{ + [OFRunLoop OF_cancelAsyncRequestsForStream: self]; +} - (void)close { @throw [OFNotImplementedException exceptionWithClass: [self class] selector: _cmd];