@@ -14,12 +14,11 @@ */ #import "OFObject.h" #import "OFKernelEventObserver.h" #import "OFRunLoop.h" - -#import "socket.h" +#import "OFSocket.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @@ -33,11 +32,11 @@ * @param length The length 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 */ -typedef bool (^of_sequenced_packet_socket_async_receive_block_t)(size_t length, +typedef bool (^OFSequencedPacketSocketAsyncReceiveBlock)(size_t length, id _Nullable exception); /** * @brief A block which is called when a packet has been sent. * @@ -44,11 +43,11 @@ * @param data The data which was sent * @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 (^of_sequenced_packet_socket_async_send_data_block_t)( +typedef OFData *_Nullable (^OFSequencedPacketSocketAsyncSendDataBlock)( OFData *_Nonnull data, id _Nullable exception); /** * @brief A block which is called when the socket accepted a connection. * @@ -56,11 +55,11 @@ * @param exception An exception which occurred while accepting the socket or * `nil` on success * @return A bool whether the same block should be used for the next incoming * connection */ -typedef bool (^of_sequenced_packet_socket_async_accept_block_t)( +typedef bool (^OFSequencedPacketSocketAsyncAcceptBlock)( OFSequencedPacketSocket *acceptedSocket, id _Nullable exception); #endif /** * @protocol OFSequencedPacketSocketDelegate OFSequencedPacketSocket.h \ @@ -125,13 +124,13 @@ * was called to create one "instance" for every thread! */ @interface OFSequencedPacketSocket: OFObject { - of_socket_t _socket; + OFSocketHandle _socket; bool _canBlock, _listening; - of_socket_address_t _remoteAddress; + OFSocketAddress _remoteAddress; id _Nullable _delegate; OF_RESERVE_IVARS(OFSequencedPacketSocket, 4) } /** @@ -149,11 +148,11 @@ /** * @brief The remote address. * * @note This only works for accepted sockets! */ -@property (readonly, nonatomic) const of_socket_address_t *remoteAddress; +@property (readonly, nonatomic) const OFSocketAddress *remoteAddress; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are @@ -176,12 +175,11 @@ * * @param buffer The buffer to write the packet to * @param length The length of the buffer * @return The length of the received packet */ -- (size_t)receiveIntoBuffer: (void *)buffer - length: (size_t)length; +- (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Asynchronously receives a packet and stores it into the specified * buffer. * @@ -188,12 +186,11 @@ * If the buffer is too small, the receive operation fails. * * @param buffer The buffer to write the packet to * @param length The length of the buffer */ -- (void)asyncReceiveIntoBuffer: (void *)buffer - length: (size_t)length; +- (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Asynchronously receives a packet and stores it into the specified * buffer. * @@ -203,11 +200,11 @@ * @param length The length of the buffer * @param runLoopMode The run loop mode in which to perform the async receive */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length - runLoopMode: (of_run_loop_mode_t)runLoopMode; + runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously receives a packet and stores it into the specified * buffer. @@ -220,15 +217,13 @@ * block returns true, it will be called again with the same * buffer and maximum length when more packets have been received. * If you want the next method in the queue to handle the packet * received next, you need to return false from the method. */ -- (void) - asyncReceiveIntoBuffer: (void *)buffer - length: (size_t)length - block: (of_sequenced_packet_socket_async_receive_block_t) - block; +- (void)asyncReceiveIntoBuffer: (void *)buffer + length: (size_t)length + block: (OFSequencedPacketSocketAsyncReceiveBlock)block; /** * @brief Asynchronously receives a packet and stores it into the specified * buffer. * @@ -241,26 +236,23 @@ * block returns true, it will be called again with the same * buffer and maximum length when more packets have been received. * If you want the next method in the queue to handle the packet * received next, you need to return false from the method. */ -- (void) - asyncReceiveIntoBuffer: (void *)buffer - length: (size_t)length - runLoopMode: (of_run_loop_mode_t)runLoopMode - block: (of_sequenced_packet_socket_async_receive_block_t) - block; +- (void)asyncReceiveIntoBuffer: (void *)buffer + length: (size_t)length + runLoopMode: (OFRunLoopMode)runLoopMode + block: (OFSequencedPacketSocketAsyncReceiveBlock)block; #endif /** * @brief Sends the specified packet. * * @param buffer The buffer to send as a packet * @param length The length of the buffer */ -- (void)sendBuffer: (const void *)buffer - length: (size_t)length; +- (void)sendBuffer: (const void *)buffer length: (size_t)length; /** * @brief Asynchronously sends the specified packet. * * @param data The data to send as a packet @@ -271,12 +263,11 @@ * @brief Asynchronously sends the specified packet. * * @param data The data to send as a packet * @param runLoopMode The run loop mode in which to perform the async send */ -- (void)asyncSendData: (OFData *)data - runLoopMode: (of_run_loop_mode_t)runLoopMode; +- (void)asyncSendData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously sends the specified packet. * @@ -284,12 +275,11 @@ * @param block The block to call when the packet 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 - block: (of_sequenced_packet_socket_async_send_data_block_t) - block; + block: (OFSequencedPacketSocketAsyncSendDataBlock)block; /** * @brief Asynchronously sends the specified packet. * * @param data The data to send as a packet @@ -297,13 +287,12 @@ * @param block The block to call when the packet 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 - runLoopMode: (of_run_loop_mode_t)runLoopMode - block: (of_sequenced_packet_socket_async_send_data_block_t) - block; + runLoopMode: (OFRunLoopMode)runLoopMode + block: (OFSequencedPacketSocketAsyncSendDataBlock)block; #endif /** * @brief Listen on the socket. * @@ -331,33 +320,33 @@ /** * @brief Asynchronously accept an incoming connection. * * @param runLoopMode The run loop mode in which to perform the async accept */ -- (void)asyncAcceptWithRunLoopMode: (of_run_loop_mode_t)runLoopMode; +- (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously accept an incoming connection. * * @param block The block to execute when a new connection has been accepted. * Returns whether the next incoming connection should be accepted * by the specified block as well. */ -- (void)asyncAcceptWithBlock: - (of_sequenced_packet_socket_async_accept_block_t)block; +- (void)asyncAcceptWithBlock: (OFSequencedPacketSocketAsyncAcceptBlock)block; /** * @brief Asynchronously accept an incoming connection. * * @param runLoopMode The run loop mode in which to perform the async accept * @param block The block to execute when a new connection has been accepted. * Returns whether the next incoming connection should be accepted * by the specified block as well. */ -- (void)asyncAcceptWithRunLoopMode: (of_run_loop_mode_t)runLoopMode - block: (of_sequenced_packet_socket_async_accept_block_t)block; +- (void) + asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode + block: (OFSequencedPacketSocketAsyncAcceptBlock)block; #endif /** * @brief Cancels all pending asynchronous requests on the socket. */