Index: src/OFAsyncIPSocketConnector.h ================================================================== --- src/OFAsyncIPSocketConnector.h +++ src/OFAsyncIPSocketConnector.h @@ -36,21 +36,21 @@ { id _socket; OFString *_host; uint16_t _port; id _Nullable _delegate; - id _Nullable _block; + id _Nullable _handler; id _Nullable _exception; OFData *_Nullable _socketAddresses; size_t _socketAddressesIndex; } - (instancetype)initWithSocket: (id)sock host: (OFString *)host port: (uint16_t)port delegate: (nullable id)delegate - block: (nullable id)block; + handler: (nullable id)handler; - (void)didConnect; - (void)tryNextAddressWithRunLoopMode: (OFRunLoopMode)runLoopMode; - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode; @end Index: src/OFAsyncIPSocketConnector.m ================================================================== --- src/OFAsyncIPSocketConnector.m +++ src/OFAsyncIPSocketConnector.m @@ -36,20 +36,20 @@ @implementation OFAsyncIPSocketConnector - (instancetype)initWithSocket: (id)sock host: (OFString *)host port: (uint16_t)port delegate: (id)delegate - block: (id)block + handler: (id)handler { self = [super init]; @try { _socket = [sock retain]; _host = [host copy]; _port = port; _delegate = [delegate retain]; - _block = [block copy]; + _handler = [handler copy]; } @catch (id e) { [self release]; @throw e; } @@ -59,11 +59,11 @@ - (void)dealloc { [_socket release]; [_host release]; [_delegate release]; - [_block release]; + [_handler release]; [_exception release]; [_socketAddresses release]; [super dealloc]; } @@ -72,16 +72,17 @@ { if (_exception == nil) [_socket setCanBlock: true]; #ifdef OF_HAVE_BLOCKS - if (_block != NULL) { + if (_handler != NULL) { if ([_socket isKindOfClass: [OFTCPSocket class]]) - ((OFTCPSocketAsyncConnectBlock)_block)(_exception); + ((OFTCPSocketAsyncConnectBlock)_handler)(_exception); # ifdef OF_HAVE_SCTP else if ([_socket isKindOfClass: [OFSCTPSocket class]]) - ((OFSCTPSocketAsyncConnectBlock)_block)(_exception); + ((OFSCTPSocketConnectedHandler)_handler)(_socket, _host, + _port, _exception); # endif else OFEnsure(0); } else { #endif Index: src/OFDatagramSocket.h ================================================================== --- src/OFDatagramSocket.h +++ src/OFDatagramSocket.h @@ -53,11 +53,11 @@ * @param buffer The buffer the packet was stored in * @param length The length of the packet * @param sender The address of the sender of the packet * @param exception An exception which occurred while receiving or `nil` on * success - * @return A bool whether the same block should be used for the next receive + * @return A bool whether the same handler should be used for the next receive */ typedef bool (^OFDatagramSocketPacketReceivedHandler)(OFDatagramSocket *socket, void *buffer, size_t length, const OFSocketAddress *_Nonnull sender, id _Nullable exception); @@ -104,11 +104,11 @@ * @param buffer The buffer the packet has been written to * @param length The length of the packet * @param sender The address of the sender of the packet * @param exception An exception that occurred while receiving, or nil on * success - * @return A bool whether the same block should be used for the next receive + * @return A bool whether the same handler should be used for the next receive */ - (bool)socket: (OFDatagramSocket *)socket didReceiveIntoBuffer: (void *)buffer length: (size_t)length sender: (const OFSocketAddress *_Nonnull)sender Index: src/OFRunLoop+Private.h ================================================================== --- src/OFRunLoop+Private.h +++ src/OFRunLoop+Private.h @@ -141,19 +141,19 @@ + (void)of_addAsyncReceiveForSCTPSocket: (OFSCTPSocket *)socket buffer: (void *)buffer length: (size_t)length mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS - block: (nullable OFSCTPSocketAsyncReceiveBlock)block + handler: (nullable OFSCTPSocketMessageReceivedHandler)handler # endif delegate: (nullable id )delegate; + (void)of_addAsyncSendForSCTPSocket: (OFSCTPSocket *)socket data: (OFData *)data info: (OFSCTPMessageInfo)info mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS - block: (nullable OFSCTPSocketAsyncSendDataBlock)block + handler: (nullable OFSCTPSocketDataSentHandler)handler # endif delegate: (nullable id )delegate; # endif + (void)of_cancelAsyncRequestsForObject: (id)object mode: (OFRunLoopMode)mode; #endif Index: src/OFRunLoop.m ================================================================== --- src/OFRunLoop.m +++ src/OFRunLoop.m @@ -217,11 +217,11 @@ # ifdef OF_HAVE_SCTP @interface OFRunLoopSCTPReceiveQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS - OFSCTPSocketAsyncReceiveBlock _block; + OFSCTPSocketMessageReceivedHandler _handler; # endif void *_buffer; size_t _length; } @end @@ -228,11 +228,11 @@ @interface OFRunLoopSCTPSendQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS - OFSCTPSocketAsyncSendDataBlock _block; + OFSCTPSocketDataSentHandler _handler; # endif OFData *_data; OFSCTPMessageInfo _info; } @end @@ -1102,12 +1102,12 @@ length = 0; exception = e; } # ifdef OF_HAVE_BLOCKS - if (_block != NULL) - return _block(length, info, exception); + if (_handler != NULL) + return _handler(object, _buffer, length, info, exception); else { # endif if (![_delegate respondsToSelector: @selector( socket:didReceiveIntoBuffer:length:info:exception:)]) return false; @@ -1123,11 +1123,11 @@ } # ifdef OF_HAVE_BLOCKS - (void)dealloc { - [_block release]; + [_handler release]; [super dealloc]; } # endif @end @@ -1145,12 +1145,12 @@ } @catch (id e) { exception = e; } # ifdef OF_HAVE_BLOCKS - if (_block != NULL) { - newData = _block(exception); + if (_handler != NULL) { + newData = _handler(object, _data, _info, exception); if (newData == nil) return false; oldData = _data; @@ -1183,11 +1183,11 @@ } - (void)dealloc { # ifdef OF_HAVE_BLOCKS - [_block release]; + [_handler release]; # endif [_data release]; [_info release]; [super dealloc]; @@ -1531,24 +1531,25 @@ QUEUE_ITEM } # ifdef OF_HAVE_SCTP -+ (void)of_addAsyncReceiveForSCTPSocket: (OFSCTPSocket *)sock - buffer: (void *)buffer - length: (size_t)length - mode: (OFRunLoopMode)mode ++ (void) + of_addAsyncReceiveForSCTPSocket: (OFSCTPSocket *)sock + buffer: (void *)buffer + length: (size_t)length + mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS - block: (OFSCTPSocketAsyncReceiveBlock)block + handler: (OFSCTPSocketMessageReceivedHandler)handler # endif - delegate: (id )delegate + delegate: (id )delegate { NEW_READ(OFRunLoopSCTPReceiveQueueItem, sock, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS - queueItem->_block = [block copy]; + queueItem->_handler = [handler copy]; # endif queueItem->_buffer = buffer; queueItem->_length = length; QUEUE_ITEM @@ -1557,19 +1558,19 @@ + (void)of_addAsyncSendForSCTPSocket: (OFSCTPSocket *)sock data: (OFData *)data info: (OFSCTPMessageInfo)info mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS - block: (OFSCTPSocketAsyncSendDataBlock)block + handler: (OFSCTPSocketDataSentHandler)handler # endif delegate: (id )delegate { NEW_WRITE(OFRunLoopSCTPSendQueueItem, sock, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS - queueItem->_block = [block copy]; + queueItem->_handler = [handler copy]; # endif queueItem->_data = [data copy]; queueItem->_info = [info copy]; QUEUE_ITEM Index: src/OFSCTPSocket.h ================================================================== --- src/OFSCTPSocket.h +++ src/OFSCTPSocket.h @@ -72,38 +72,48 @@ } #endif #ifdef OF_HAVE_BLOCKS /** - * @brief A block which is called when the socket connected. + * @brief A handler which is called when the socket connected. * + * @param socket The socket which connected + * @param host The host connected to + * @param port The port on the host connected to * @param exception An exception which occurred while connecting the socket or * `nil` on success */ -typedef void (^OFSCTPSocketAsyncConnectBlock)(id _Nullable exception); +typedef void (^OFSCTPSocketConnectedHandler)(OFSCTPSocket *socket, + OFString *host, uint16_t port, id _Nullable exception); /** - * @brief A block which is called when a message has been received. + * @brief A handler which is called when a message has been received. * + * @param socket The SCTP socket which received a message + * @param buffer The buffer the message has been written to * @param length The length of the message * @param info Information about the message, see @ref OFSCTPMessageInfo * @param exception An exception which occurred while receiving or `nil` on * success - * @return A bool whether the same block should be used for the next receive + * @return A bool whether the same handler should be used for the next receive */ -typedef bool (^OFSCTPSocketAsyncReceiveBlock)(size_t length, - OFSCTPMessageInfo info, id _Nullable exception); +typedef bool (^OFSCTPSocketMessageReceivedHandler)(OFSCTPSocket *socket, + void *buffer, size_t length, OFSCTPMessageInfo _Nullable info, + id _Nullable exception); /** - * @brief A block which is called when a message has been sent. + * @brief A handler which is called when a message has been sent. * + * @param socket The SCTP socket which sent a message + * @param data The data which was sent + * @param info Information about the message, see @ref OFSCTPMessageInfo * @param exception An exception which occurred while reading or `nil` on * success * @return The data to repeat the send with or nil if it should not repeat */ -typedef OFData *_Nullable (^OFSCTPSocketAsyncSendDataBlock)( - id _Nullable exception); +typedef OFData *_Nullable (^OFSCTPSocketDataSentHandler)(OFSCTPSocket *socket, + OFData *data, OFSCTPMessageInfo _Nullable info, id _Nullable exception); #endif /** * @protocol OFSCTPSocketDelegate OFSCTPSocket.h ObjFW/ObjFW.h * @@ -132,11 +142,11 @@ * @param buffer The buffer the message has been written to * @param length The length of the message * @param info Information about the message, see @ref OFSCTPMessageInfo * @param exception An exception that occurred while receiving, or nil on * success - * @return A bool whether the same block should be used for the next receive + * @return A bool whether the same handler should be used for the next receive */ - (bool)socket: (OFSCTPSocket *)socket didReceiveIntoBuffer: (void *)buffer length: (size_t)length info: (nullable OFSCTPMessageInfo)info @@ -222,28 +232,30 @@ /** * @brief Asynchronously connect the OFSCTPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to - * @param block The block to execute once the connection has been established + * @param handler The handler to execute once the connection has been + * established */ - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port - block: (OFSCTPSocketAsyncConnectBlock)block; + handler: (OFSCTPSocketConnectedHandler)handler; /** * @brief Asynchronously connect the OFSCTPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to * @param runLoopMode The run loop mode in which to perform the async connect - * @param block The block to execute once the connection has been established + * @param handler The handler to execute once the connection has been + * established */ - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode - block: (OFSCTPSocketAsyncConnectBlock)block; + handler: (OFSCTPSocketConnectedHandler)handler; #endif /** * @brief Bind the socket to the specified host and port. * @@ -309,19 +321,21 @@ * * If the buffer is too small, the message is truncated. * * @param buffer The buffer to write the message to * @param length The length of the buffer - * @param block The block to call when the message has been received. If the - * block returns true, it will be called again with the same - * buffer and maximum length when more messages have been received. - * If you want the next method in the queue to handle the message - * received next, you need to return false from the method. + * @param handler The handler to call when the message has been received. If the + * handler returns true, it will be called again with the same + * buffer and maximum length when more messages have been + * received. If you want the next method in the queue to handle + * the message received next, you need to return false from the + * method. */ -- (void)asyncReceiveWithInfoIntoBuffer: (void *)buffer - length: (size_t)length - block: (OFSCTPSocketAsyncReceiveBlock)block; +- (void) + asyncReceiveWithInfoIntoBuffer: (void *)buffer + length: (size_t)length + handler: (OFSCTPSocketMessageReceivedHandler)handler; /** * @brief Asynchronously receives a message and stores it into the specified * buffer. * @@ -329,20 +343,22 @@ * * @param buffer The buffer to write the message to * @param length The length of the buffer * @param runLoopMode The run loop mode in which to perform the asynchronous * receive - * @param block The block to call when the message has been received. If the - * block returns true, it will be called again with the same - * buffer and maximum length when more messages have been received. - * If you want the next method in the queue to handle the message - * received next, you need to return false from the method. + * @param handler The handler to call when the message has been received. If the + * handler returns true, it will be called again with the same + * buffer and maximum length when more messages have been + * received. If you want the next method in the queue to handle + * the message received next, you need to return false from the + * method. */ -- (void)asyncReceiveWithInfoIntoBuffer: (void *)buffer - length: (size_t)length - runLoopMode: (OFRunLoopMode)runLoopMode - block: (OFSCTPSocketAsyncReceiveBlock)block; +- (void) + asyncReceiveWithInfoIntoBuffer: (void *)buffer + length: (size_t)length + runLoopMode: (OFRunLoopMode)runLoopMode + handler: (OFSCTPSocketMessageReceivedHandler)handler; #endif /** * @brief Sends the specified message on the specified stream. * @@ -380,32 +396,32 @@ /** * @brief Asynchronously sends the specified message on the specified stream. * * @param data The data to send as a message * @param info Information about the message, see @ref OFSCTPMessageInfo - * @param block The block to call when the message has been sent. It should - * return the data for the next send with the same callback or nil - * if it should not repeat. + * @param handler The handler to call when the message has been sent. It should + * return the data for the next send with the same callback or + * nil if it should not repeat. */ - (void)asyncSendData: (OFData *)data info: (nullable OFSCTPMessageInfo)info - block: (OFSCTPSocketAsyncSendDataBlock)block; + handler: (OFSCTPSocketDataSentHandler)handler; /** * @brief Asynchronously sends the specified message on the specified stream. * * @param data The data to send as a message * @param info Information about the message, see @ref OFSCTPMessageInfo * @param runLoopMode The run loop mode in which to perform the asynchronous * send - * @param block The block to call when the message has been sent. It should - * return the data for the next send with the same callback or nil - * if it should not repeat. + * @param handler The handler to call when the message has been sent. It should + * return the data for the next send with the same callback or + * nil if it should not repeat. */ - (void)asyncSendData: (OFData *)data info: (nullable OFSCTPMessageInfo)info runLoopMode: (OFRunLoopMode)runLoopMode - block: (OFSCTPSocketAsyncSendDataBlock)block; + handler: (OFSCTPSocketDataSentHandler)handler; #endif @end OF_ASSUME_NONNULL_END Index: src/OFSCTPSocket.m ================================================================== --- src/OFSCTPSocket.m +++ src/OFSCTPSocket.m @@ -203,31 +203,31 @@ [[[[OFAsyncIPSocketConnector alloc] initWithSocket: self host: host port: port delegate: _delegate - block: NULL + handler: NULL ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port - block: (OFSCTPSocketAsyncConnectBlock)block + handler: (OFSCTPSocketConnectedHandler)handler { [self asyncConnectToHost: host port: port runLoopMode: OFDefaultRunLoopMode - block: block]; + handler: handler]; } - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode - block: (OFSCTPSocketAsyncConnectBlock)block + handler: (OFSCTPSocketConnectedHandler)handler { void *pool = objc_autoreleasePoolPush(); if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyOpenException exceptionWithObject: self]; @@ -235,11 +235,11 @@ [[[[OFAsyncIPSocketConnector alloc] initWithSocket: self host: host port: port delegate: nil - block: block] autorelease] + handler: handler] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #endif @@ -432,37 +432,38 @@ [OFRunLoop of_addAsyncReceiveForSCTPSocket: self buffer: buffer length: length mode: runLoopMode # ifdef OF_HAVE_BLOCKS - block: NULL + handler: NULL # endif delegate: _delegate]; } #ifdef OF_HAVE_BLOCKS -- (void)asyncReceiveWithInfoIntoBuffer: (void *)buffer - length: (size_t)length - block: (OFSCTPSocketAsyncReceiveBlock)block +- (void) + asyncReceiveWithInfoIntoBuffer: (void *)buffer + length: (size_t)length + handler: (OFSCTPSocketMessageReceivedHandler)handler { [self asyncReceiveWithInfoIntoBuffer: buffer length: length runLoopMode: OFDefaultRunLoopMode - block: block]; + handler: handler]; } - (void) asyncReceiveWithInfoIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode - block: (OFSCTPSocketAsyncReceiveBlock)block + handler: (OFSCTPSocketMessageReceivedHandler)handler { [OFRunLoop of_addAsyncReceiveForSCTPSocket: self buffer: buffer length: length mode: runLoopMode - block: block + handler: handler delegate: nil]; } #endif - (void)sendBuffer: (const void *)buffer length: (size_t)length @@ -536,36 +537,36 @@ [OFRunLoop of_addAsyncSendForSCTPSocket: self data: data info: info mode: runLoopMode # ifdef OF_HAVE_BLOCKS - block: NULL + handler: NULL # endif delegate: _delegate]; } #ifdef OF_HAVE_BLOCKS - (void)asyncSendData: (OFData *)data info: (OFSCTPMessageInfo)info - block: (OFSCTPSocketAsyncSendDataBlock)block + handler: (OFSCTPSocketDataSentHandler)handler { [self asyncSendData: data info: info runLoopMode: OFDefaultRunLoopMode - block: block]; + handler: handler]; } - (void)asyncSendData: (OFData *)data info: (OFSCTPMessageInfo)info runLoopMode: (OFRunLoopMode)runLoopMode - block: (OFSCTPSocketAsyncSendDataBlock)block + handler: (OFSCTPSocketDataSentHandler)handler { [OFRunLoop of_addAsyncSendForSCTPSocket: self data: data info: info mode: runLoopMode - block: block + handler: handler delegate: nil]; } #endif - (void)setCanDelaySendingMessages: (bool)canDelaySendingMessages Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -242,11 +242,11 @@ [[[[OFAsyncIPSocketConnector alloc] initWithSocket: self host: host port: port delegate: delegate - block: NULL + handler: NULL ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } @@ -283,11 +283,11 @@ [[[[OFAsyncIPSocketConnector alloc] initWithSocket: self host: host port: port delegate: delegate - block: (delegate == nil ? block : NULL)] autorelease] + handler: (delegate == nil ? block : NULL)] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #endif