Index: src/OFSPXSocket.h ================================================================== --- src/OFSPXSocket.h +++ src/OFSPXSocket.h @@ -158,12 +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 OFBindFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (OFSocketAddress)bindToPort: (uint16_t)port; @end OF_ASSUME_NONNULL_END Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -215,10 +215,12 @@ /** * @brief Whether the stream can block. * * By default, a stream can block. * On Win32, setting this currently only works for sockets! + * + * @throw OFSetOptionFailedException The option could not be set */ @property (nonatomic) bool canBlock; /** * @brief The delegate for asynchronous operations on the stream. @@ -262,10 +264,12 @@ * * @param buffer The buffer into which the data is read * @param length The length of the data that should be read. * The buffer *must* be *at least* this big! * @throw OFReadFailedException Reading failed + * @throw OFTruncatedDataException The end of the stream was reached before + * reading the specified amount * @throw OFNotOpenException The stream is not open */ - (void)readIntoBuffer: (void *)buffer exactLength: (size_t)length; #ifdef OF_HAVE_SOCKETS @@ -476,10 +480,12 @@ * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint8_t from the stream * @throw OFReadFailedException Reading failed + * @throw OFTruncatedDataException The end of the stream was reached before + * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint8_t)readInt8; /** @@ -488,10 +494,12 @@ * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint16_t from the stream in native endianess * @throw OFReadFailedException Reading failed + * @throw OFTruncatedDataException The end of the stream was reached before + * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint16_t)readBigEndianInt16; /** @@ -500,10 +508,12 @@ * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint32_t from the stream in the native endianess * @throw OFReadFailedException Reading failed + * @throw OFTruncatedDataException The end of the stream was reached before + * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint32_t)readBigEndianInt32; /** @@ -512,10 +522,12 @@ * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint64_t from the stream in the native endianess * @throw OFReadFailedException Reading failed + * @throw OFTruncatedDataException The end of the stream was reached before + * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint64_t)readBigEndianInt64; /** @@ -524,10 +536,12 @@ * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A float from the stream in the native endianess * @throw OFReadFailedException Reading failed + * @throw OFTruncatedDataException The end of the stream was reached before + * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (float)readBigEndianFloat; /** @@ -536,10 +550,12 @@ * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A double from the stream in the native endianess * @throw OFReadFailedException Reading failed + * @throw OFTruncatedDataException The end of the stream was reached before + * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (double)readBigEndianDouble; /** @@ -548,10 +564,12 @@ * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint16_t from the stream in native endianess * @throw OFReadFailedException Reading failed + * @throw OFTruncatedDataException The end of the stream was reached before + * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint16_t)readLittleEndianInt16; /** @@ -560,10 +578,12 @@ * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint32_t from the stream in the native endianess * @throw OFReadFailedException Reading failed + * @throw OFTruncatedDataException The end of the stream was reached before + * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint32_t)readLittleEndianInt32; /** @@ -572,10 +592,12 @@ * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint64_t from the stream in the native endianess * @throw OFReadFailedException Reading failed + * @throw OFTruncatedDataException The end of the stream was reached before + * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint64_t)readLittleEndianInt64; /** @@ -584,10 +606,12 @@ * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A float from the stream in the native endianess * @throw OFReadFailedException Reading failed + * @throw OFTruncatedDataException The end of the stream was reached before + * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (float)readLittleEndianFloat; /** @@ -596,10 +620,12 @@ * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A double from the stream in the native endianess * @throw OFReadFailedException Reading failed + * @throw OFTruncatedDataException The end of the stream was reached before + * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (double)readLittleEndianDouble; /** @@ -610,10 +636,12 @@ * Otherwise you will get an exception! * * @param count The number of items to read * @return OFData with count items. * @throw OFReadFailedException Reading failed + * @throw OFTruncatedDataException The end of the stream was reached before + * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (OFData *)readDataWithCount: (size_t)count; /** @@ -625,10 +653,12 @@ * * @param itemSize The size of each item * @param count The number of items to read * @return OFData with count items. * @throw OFReadFailedException Reading failed + * @throw OFTruncatedDataException The end of the stream was reached before + * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (OFData *)readDataWithItemSize: (size_t)itemSize count: (size_t)count; /** @@ -655,10 +685,12 @@ * @param length The length (in bytes) of the string to read from the stream * @return A string with the specified length * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding + * @throw OFTruncatedDataException The end of the stream was reached before + * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (OFString *)readStringWithLength: (size_t)length; /** @@ -676,10 +708,12 @@ * @param length The length (in bytes) of the string to read from the stream * @return A string with the specified length * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding + * @throw OFTruncatedDataException The end of the stream was reached before + * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (OFString *)readStringWithLength: (size_t)length encoding: (OFStringEncoding)encoding; Index: src/OFStreamSocket.h ================================================================== --- src/OFStreamSocket.h +++ src/OFStreamSocket.h @@ -78,10 +78,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. @@ -101,22 +104,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 OFStreamSocket for the accepted connection. + * @throw OFAcceptFailedException Accepting failed + * @throw OFNotOpenException The socket is not open */ - (instancetype)accept; /** * @brief Asynchronously accept an incoming connection. Index: src/OFTCPSocket.h ================================================================== --- src/OFTCPSocket.h +++ src/OFTCPSocket.h @@ -81,10 +81,13 @@ #if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) /** * @brief Whether the socket sends keep alives for the connection. * * @warning This is not available on the Wii or Nintendo 3DS! + * + * @throw OFSetOptionFailedException The option could not be set + * @throw OFGetOptionFailedException The option could not be gotten */ @property (nonatomic) bool sendsKeepAlives; #endif #ifndef OF_WII @@ -91,10 +94,13 @@ /** * @brief Whether sending segments can be delayed. Setting this to `false` sets * TCP_NODELAY on the socket. * * @warning This is not available on the Wii! + * + * @throw OFSetOptionFailedException The option could not be set + * @throw OFGetOptionFailedException The option could not be gotten */ @property (nonatomic) bool canDelaySendingSegments; #endif /** @@ -148,10 +154,12 @@ /** * @brief Connects the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to + * @throw OFConnectionFailedException Connecting failed + * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (void)connectToHost: (OFString *)host port: (uint16_t)port; /** * @brief Asynchronously connects the OFTCPSocket to the specified destination. @@ -204,10 +212,12 @@ * @param host The host to bind to. Use `@"0.0.0.0"` for IPv4 or `@"::"` for * IPv6 to bind to all. * @param port The port to bind to. If the port is 0, an unused port will be * chosen, which can be obtained using the return value. * @return The port the socket was bound to + * @throw OFBindFailedException Binding failed + * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port; @end OF_ASSUME_NONNULL_END Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -219,13 +219,10 @@ runLoopMode: (OFRunLoopMode)runLoopMode { void *pool = objc_autoreleasePoolPush(); id delegate; - if (_socket != OFInvalidSocketHandle) - @throw [OFAlreadyConnectedException exceptionWithSocket: self]; - if (_SOCKS5Host != nil) { delegate = [[[OFTCPSocketSOCKS5Connector alloc] initWithSocket: self host: host port: port @@ -267,13 +264,10 @@ block: (OFTCPSocketAsyncConnectBlock)block { void *pool = objc_autoreleasePoolPush(); id delegate = nil; - if (_socket != OFInvalidSocketHandle) - @throw [OFAlreadyConnectedException exceptionWithSocket: self]; - if (_SOCKS5Host != nil) { delegate = [[[OFTCPSocketSOCKS5Connector alloc] initWithSocket: self host: host port: port