@@ -14,10 +14,11 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFStreamSocket.h" +#import "OFRunLoop.h" #import "socket.h" OF_ASSUME_NONNULL_BEGIN @@ -168,10 +169,29 @@ port: (uint16_t)port target: (id)target selector: (SEL)selector context: (nullable id)context; +/*! + * @brief Asynchronously connect the OFTCPSocket 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 target The target on which to call the selector once the connection + * has been established + * @param selector The selector to call on the target. The signature must be + * `void (OFTCPSocket *socket, id context, id exception)`. + * @param context A context object to pass along to the target + */ +- (void)asyncConnectToHost: (OFString *)host + port: (uint16_t)port + runLoopMode: (of_run_loop_mode_t)runLoopMode + target: (id)target + selector: (SEL)selector + context: (nullable id)context; + #ifdef OF_HAVE_BLOCKS /*! * @brief Asynchronously connect the OFTCPSocket to the specified destination. * * @param host The host to connect to @@ -179,10 +199,23 @@ * @param block The block to execute once the connection has been established */ - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port block: (of_tcp_socket_async_connect_block_t)block; + +/*! + * @brief Asynchronously connect the OFTCPSocket 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 + */ +- (void)asyncConnectToHost: (OFString *)host + port: (uint16_t)port + runLoopMode: (of_run_loop_mode_t)runLoopMode + block: (of_tcp_socket_async_connect_block_t)block; #endif /*! * @brief Bind the socket to the specified host and port. * @@ -228,19 +261,48 @@ */ - (void)asyncAcceptWithTarget: (id)target selector: (SEL)selector context: (nullable id)context; +/*! + * @brief Asynchronously accept an incoming connection. + * + * @param runLoopMode The run loop mode in which to perform the async accept + * @param target The target on which to execute the selector when a new + * connection has been accepted. The method returns whether the + * next incoming connection should be accepted by the specified + * block as well. + * @param selector The selector to call on the target. The signature must be + * `bool (OFTCPSocket *socket, OFTCPSocket *acceptedSocket, + * id context, id exception)`. + * @param context A context object to pass along to the target + */ +- (void)asyncAcceptWithRunLoopMode: (of_run_loop_mode_t)runLoopMode + target: (id)target + selector: (SEL)selector + context: (nullable id)context; + #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_tcp_socket_async_accept_block_t)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_tcp_socket_async_accept_block_t)block; #endif @end #ifdef __cplusplus extern "C" {