@@ -43,10 +43,11 @@ @interface OFRunLoop_QueueItem: OFObject { @public id _target; SEL _selector; + id _context; } - (bool)handleForObject: (id)object; @end @@ -109,10 +110,11 @@ } - (void)dealloc { [_target release]; + [_context release]; [super dealloc]; } @end @@ -133,17 +135,17 @@ # ifdef OF_HAVE_BLOCKS if (_block != NULL) return _block(object, _buffer, length, exception); else { # endif - bool (*func)(id, SEL, OFStream *, void *, size_t, + bool (*func)(id, SEL, OFStream *, void *, size_t, id, OFException *) = (bool (*)(id, SEL, OFStream *, void *, - size_t, OFException *)) + size_t, id, OFException *)) [_target methodForSelector: _selector]; return func(_target, _selector, object, _buffer, length, - exception); + _context, exception); # ifdef OF_HAVE_BLOCKS } # endif } @@ -184,17 +186,17 @@ _readLength = 0; return true; } else { # endif - bool (*func)(id, SEL, OFStream *, void *, size_t, + bool (*func)(id, SEL, OFStream *, void *, size_t, id, OFException *) = (bool (*)(id, SEL, OFStream *, void *, - size_t, OFException *)) + size_t, id, OFException *)) [_target methodForSelector: _selector]; if (!func(_target, _selector, object, _buffer, _readLength, - exception)) + _context, exception)) return false; _readLength = 0; return true; # ifdef OF_HAVE_BLOCKS @@ -231,15 +233,16 @@ # ifdef OF_HAVE_BLOCKS if (_block != NULL) return _block(object, line, exception); else { # endif - bool (*func)(id, SEL, OFStream *, OFString *, OFException *) = - (bool (*)(id, SEL, OFStream *, OFString *, OFException *)) - [_target methodForSelector: _selector]; + bool (*func)(id, SEL, OFStream *, OFString *, id, + OFException *) = (bool (*)(id, SEL, OFStream *, OFString *, + id, OFException *))[_target methodForSelector: _selector]; - return func(_target, _selector, object, line, exception); + return func(_target, _selector, object, line, _context, + exception); # ifdef OF_HAVE_BLOCKS } # endif } @@ -269,16 +272,17 @@ # ifdef OF_HAVE_BLOCKS if (_block != NULL) return _block(object, newSocket, exception); else { # endif - bool (*func)(id, SEL, OFTCPSocket *, OFTCPSocket *, + bool (*func)(id, SEL, OFTCPSocket *, OFTCPSocket *, id, OFException *) = (bool (*)(id, SEL, OFTCPSocket *, - OFTCPSocket *, OFException *)) + OFTCPSocket *, id, OFException *)) [_target methodForSelector: _selector]; - return func(_target, _selector, object, newSocket, exception); + return func(_target, _selector, object, newSocket, _context, + exception); # ifdef OF_HAVE_BLOCKS } # endif } @@ -312,17 +316,17 @@ if (_block != NULL) return _block(object, _buffer, length, address, exception); else { # endif bool (*func)(id, SEL, OFUDPSocket *, void *, size_t, - of_udp_socket_address_t address, OFException *) = + of_udp_socket_address_t address, id, OFException *) = (bool (*)(id, SEL, OFUDPSocket *, void *, size_t, - of_udp_socket_address_t, OFException *)) + of_udp_socket_address_t, id, OFException *)) [_target methodForSelector: _selector]; return func(_target, _selector, object, _buffer, length, - address, exception); + address, _context, exception); # ifdef OF_HAVE_BLOCKS } # endif } @@ -383,14 +387,16 @@ + (void)of_addAsyncReadForStream: (OFStream *)stream buffer: (void *)buffer length: (size_t)length target: (id)target selector: (SEL)selector + context: (id)context { ADD_READ(OFRunLoop_ReadQueueItem, stream, { queueItem->_target = [target retain]; queueItem->_selector = selector; + queueItem->_context = [context retain]; queueItem->_buffer = buffer; queueItem->_length = length; }) } @@ -397,52 +403,60 @@ + (void)of_addAsyncReadForStream: (OFStream *)stream buffer: (void *)buffer exactLength: (size_t)exactLength target: (id)target selector: (SEL)selector + context: (id)context { ADD_READ(OFRunLoop_ExactReadQueueItem, stream, { queueItem->_target = [target retain]; queueItem->_selector = selector; + queueItem->_context = [context retain]; queueItem->_buffer = buffer; queueItem->_exactLength = exactLength; }) } + (void)of_addAsyncReadLineForStream: (OFStream *)stream encoding: (of_string_encoding_t)encoding target: (id)target selector: (SEL)selector + context: (id)context { ADD_READ(OFRunLoop_ReadLineQueueItem, stream, { queueItem->_target = [target retain]; queueItem->_selector = selector; + queueItem->_context = [context retain]; queueItem->_encoding = encoding; }) } + (void)of_addAsyncAcceptForTCPSocket: (OFTCPSocket *)stream target: (id)target selector: (SEL)selector + context: (id)context { ADD_READ(OFRunLoop_AcceptQueueItem, stream, { queueItem->_target = [target retain]; queueItem->_selector = selector; + queueItem->_context = [context retain]; }) } + (void)of_addAsyncReceiveForUDPSocket: (OFUDPSocket *)socket buffer: (void *)buffer length: (size_t)length target: (id)target selector: (SEL)selector + context: (id)context { ADD_READ(OFRunLoop_UDPReceiveQueueItem, socket, { - queueItem->_buffer = buffer; - queueItem->_length = length; queueItem->_target = [target retain]; queueItem->_selector = selector; + queueItem->_context = [context retain]; + queueItem->_buffer = buffer; + queueItem->_length = length; }) } # ifdef OF_HAVE_BLOCKS + (void)of_addAsyncReadForStream: (OFStream *)stream