Index: src/OFSPXSocket.h ================================================================== --- src/OFSPXSocket.h +++ src/OFSPXSocket.h @@ -87,10 +87,12 @@ * * @param network The network on which the node to connect to is * @param node The node to connect to * @param port The port (sometimes also called socket number) on the node to * connect to + * @throw OFConnectionFailedException Connecting failed + * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (void)connectToNetwork: (uint32_t)network node: (unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; @@ -156,10 +158,12 @@ * @brief Bind the socket to the specified network, node and port. * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @return The address on which this socket can be reached + * @throw OFConnectionFailedException Binding failed + * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (OFSocketAddress)bindToPort: (uint16_t)port; @end OF_ASSUME_NONNULL_END Index: src/OFSPXStreamSocket.h ================================================================== --- src/OFSPXStreamSocket.h +++ src/OFSPXStreamSocket.h @@ -88,10 +88,12 @@ * * @param network The network on which the node to connect to is * @param node The node to connect to * @param port The port (sometimes also called socket number) on the node to * connect to + * @throw OFConnectionFailedException Connecting failed + * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (void)connectToNetwork: (uint32_t)network node: (unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; @@ -161,10 +163,12 @@ * @brief Bind the socket to the specified network, node and port. * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @return The address on which this socket can be reached + * @throw OFConnectionFailedException Binding failed + * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (OFSocketAddress)bindToPort: (uint16_t)port; @end OF_ASSUME_NONNULL_END Index: src/OFSequencedPacketSocket.h ================================================================== --- src/OFSequencedPacketSocket.h +++ src/OFSequencedPacketSocket.h @@ -134,10 +134,12 @@ /** * @brief Whether the socket can block. * * By default, a socket can block. + * + * @throw OFSetOptionFailedException The option could not be set */ @property (nonatomic) bool canBlock; /** * @brief Whether the socket is a listening socket. @@ -146,10 +148,13 @@ /** * @brief The remote address. * * @note This only works for accepted sockets! + * + * @throw OFNotOpenException The socket is not open + * @throw OFInvalidArgumentException The socket has no remote address */ @property (readonly, nonatomic) const OFSocketAddress *remoteAddress; /** * @brief The delegate for asynchronous operations on the socket. @@ -173,10 +178,12 @@ * 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 * @return The length of the received packet + * @throw OFReadFailedException Receiving failed + * @throw OFNotOpenException The socket is not open */ - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Asynchronously receives a packet and stores it into the specified @@ -246,10 +253,12 @@ /** * @brief Sends the specified packet. * * @param buffer The buffer to send as a packet * @param length The length of the buffer + * @throw OFWriteFailedException Sending failed + * @throw OFNotOpenException The socket is not open */ - (void)sendBuffer: (const void *)buffer length: (size_t)length; /** * @brief Asynchronously sends the specified packet. @@ -294,22 +303,29 @@ /** * @brief Listen on the socket. * * @param backlog Maximum length for the queue of pending connections. + * @throw OFListenFailedException Listening failed + * @throw OFNotOpenException The socket is not open */ - (void)listenWithBacklog: (int)backlog; /** * @brief Listen on the socket. + * + * @throw OFListenFailedException Listening failed + * @throw OFNotOpenException The socket is not open */ - (void)listen; /** * @brief Accept an incoming connection. * * @return An autoreleased sequenced packet socket for the accepted connection. + * @throw OFAcceptFailedException Accepting failed + * @throw OFNotOpenException The socket is not open */ - (instancetype)accept; /** * @brief Asynchronously accept an incoming connection. @@ -352,10 +368,12 @@ - (void)cancelAsyncRequests; /** * @brief Closes the socket so that it can neither receive nor send any more * datagrams. + * + * @throw OFNotOpenException The socket is not open */ - (void)close; @end OF_ASSUME_NONNULL_END Index: src/OFSequencedPacketSocket.m ================================================================== --- src/OFSequencedPacketSocket.m +++ src/OFSequencedPacketSocket.m @@ -316,18 +316,21 @@ _listening = true; } - (instancetype)accept { - OFSequencedPacketSocket *client = - [[[[self class] alloc] init] autorelease]; + OFSequencedPacketSocket *client; #if (!defined(HAVE_PACCEPT) && !defined(HAVE_ACCEPT4)) || !defined(SOCK_CLOEXEC) # if defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; # endif #endif + if (_socket == OFInvalidSocketHandle) + @throw [OFNotOpenException exceptionWithObject: self]; + + client = [[[[self class] alloc] init] autorelease]; client->_remoteAddress.length = (socklen_t)sizeof(client->_remoteAddress.sockaddr); #if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC) if ((client->_socket = paccept(_socket,