Index: src/OFRunLoop+Private.h ================================================================== --- src/OFRunLoop+Private.h +++ src/OFRunLoop+Private.h @@ -138,11 +138,11 @@ delegate: (nullable id )delegate; + (void)of_addAsyncSendForSCTPSocket: (OFSCTPSocket *)socket data: (OFData *)data streamID: (uint16_t)streamID PPID: (uint32_t)PPID - flags: (OFSCTPPacketFlags)flags + flags: (OFSCTPMessageFlags)flags mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFSCTPSocketAsyncSendDataBlock)block # endif delegate: (nullable id )delegate; Index: src/OFRunLoop.m ================================================================== --- src/OFRunLoop.m +++ src/OFRunLoop.m @@ -222,11 +222,11 @@ OFSCTPSocketAsyncSendDataBlock _block; # endif OFData *_data; uint16_t _streamID; uint32_t _PPID; - OFSCTPPacketFlags _flags; + OFSCTPMessageFlags _flags; } @end # endif #endif @@ -1040,11 +1040,11 @@ - (bool)handleObject: (id)object { size_t length; uint16_t streamID; uint32_t PPID; - OFSCTPPacketFlags flags; + OFSCTPMessageFlags flags; id exception = nil; @try { length = [object receiveIntoBuffer: _buffer length: _length @@ -1486,11 +1486,11 @@ + (void)of_addAsyncSendForSCTPSocket: (OFSCTPSocket *)sock data: (OFData *)data streamID: (uint16_t)streamID PPID: (uint32_t)PPID - flags: (OFSCTPPacketFlags)flags + flags: (OFSCTPMessageFlags)flags mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFSCTPSocketAsyncSendDataBlock)block # endif delegate: (id )delegate Index: src/OFSCTPSocket.h ================================================================== --- src/OFSCTPSocket.h +++ src/OFSCTPSocket.h @@ -26,16 +26,16 @@ @class OFSCTPSocket; @class OFString; /** - * @brief Flags for an SCTP packet. + * @brief Flags for an SCTP message. */ typedef enum { - /** The packet is sent / received out of order. */ - OFSCTPPacketUnordered = 1 -} OFSCTPPacketFlags; + /** The message is sent / received out of order. */ + OFSCTPMessageUnordered = 1 +} OFSCTPMessageFlags; #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when the socket connected. * @@ -43,25 +43,25 @@ * `nil` on success */ typedef void (^OFSCTPSocketAsyncConnectBlock)(id _Nullable exception); /** - * @brief A block which is called when a packet has been received. + * @brief A block which is called when a message has been received. * - * @param length The length of the packet + * @param length The length of the message * @param streamID The stream ID for the message * @param PPID The Payload Protocol Identifier for the message - * @param flags Flags for the packet + * @param flags Flags for the message * @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 (^OFSCTPSocketAsyncReceiveBlock)(size_t length, uint16_t streamID, - uint32_t PPID, OFSCTPPacketFlags flags, id _Nullable exception); + uint32_t PPID, OFSCTPMessageFlags flags, id _Nullable exception); /** - * @brief A block which is called when a packet has been sent. + * @brief A block which is called when a message has been 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 */ @@ -89,46 +89,46 @@ didConnectToHost: (OFString *)host port: (uint16_t)port exception: (nullable id)exception; /** - * @brief This method is called when a packet has been received. + * @brief This method is called when a message has been received. * - * @param socket The sequenced packet socket which received a packet - * @param buffer The buffer the packet has been written to - * @param length The length of the packet + * @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 streamID The stream ID for the message * @param PPID The Payload Protocol Identifier for the message - * @param flags Flags for the packet + * @param flags Flags for the message * @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 */ - (bool)socket: (OFSCTPSocket *)socket didReceiveIntoBuffer: (void *)buffer length: (size_t)length streamID: (uint16_t)streamID PPID: (uint32_t)PPID - flags: (OFSCTPPacketFlags)flags + flags: (OFSCTPMessageFlags)flags exception: (nullable id)exception; /** - * @brief This method is called when a packet has been sent. + * @brief This method is called when a message has been sent. * - * @param socket The sequenced packet socket which sent a packet + * @param socket The SCTP socket which sent a message * @param data The data which was sent * @param streamID The stream ID for the message * @param PPID The Payload Protocol Identifier for the message - * @param flags Flags for the packet + * @param flags Flags for the message * @param exception An exception that occurred while sending, or nil on success * @return The data to repeat the send with or nil if it should not repeat */ - (nullable OFData *)socket: (OFSCTPSocket *)socket didSendData: (OFData *)data streamID: (uint16_t)streamID PPID: (uint32_t)PPID - flags: (OFSCTPPacketFlags)flags + flags: (OFSCTPMessageFlags)flags exception: (nullable id)exception; @end /** * @class OFSCTPSocket OFSCTPSocket.h ObjFW/OFSCTPSocket.h @@ -143,17 +143,17 @@ { OF_RESERVE_IVARS(OFSCTPSocket, 4) } /** - * @brief Whether sending packets can be delayed. Setting this to NO sets + * @brief Whether sending messages can be delayed. Setting this to NO sets * SCTP_NODELAY on the socket. * * @throw OFGetOptionFailedException The option could not be retrieved * @throw OFSetOptionFailedException The option could not be set */ -@property (nonatomic) bool canDelaySendingPackets; +@property (nonatomic) bool canDelaySendingMessages; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are @@ -229,49 +229,49 @@ * @throw OFAlreadyOpenException The socket is already connected or bound */ - (OFSocketAddress)bindToHost: (OFString *)host port: (uint16_t)port; /** - * @brief Receives a packet for the specified stream and stores it into the + * @brief Receives a message for the specified stream ID and stores it into the * specified buffer. * - * If the buffer is too small, the packet is truncated. + * If the buffer is too small, the message is truncated. * - * @param buffer The buffer to write the packet to + * @param buffer The buffer to write the message to * @param length The length of the buffer * @param streamID The stream ID for the message * @param PPID The Payload Protocol Identifier for the message - * @param flags Flags for the packet - * @return The length of the received packet + * @param flags Flags for the message + * @return The length of the received message * @throw OFReadFailedException Receiving failed * @throw OFNotOpenException The socket is not open */ - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length streamID: (nullable uint16_t *)streamID PPID: (nullable uint32_t *)PPID - flags: (nullable OFSCTPPacketFlags *)flags; + flags: (nullable OFSCTPMessageFlags *)flags; /** - * @brief Asynchronously receives a packet with stream ID and PPID and stores + * @brief Asynchronously receives a message with stream ID and PPID and stores * it into the specified buffer. * - * If the buffer is too small, the packet is truncated. + * If the buffer is too small, the message is truncated. * - * @param buffer The buffer to write the packet to + * @param buffer The buffer to write the message to * @param length The length of the buffer */ - (void)asyncReceiveWithInfoIntoBuffer: (void *)buffer length: (size_t)length; /** - * @brief Asynchronously receives a packet with stream ID and PPID and stores + * @brief Asynchronously receives a message with stream ID and PPID and stores * it into the specified buffer. * - * If the buffer is too small, the packet is truncated. + * If the buffer is too small, the message is truncated. * - * @param buffer The buffer to write the packet to + * @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 */ - (void)asyncReceiveWithInfoIntoBuffer: (void *)buffer @@ -278,131 +278,131 @@ length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** - * @brief Asynchronously receives a packet with stream ID and PPID and stores + * @brief Asynchronously receives a message with stream ID and PPID and stores * it into the specified buffer. * - * If the buffer is too small, the packet is truncated. + * If the buffer is too small, the message is truncated. * - * @param buffer The buffer to write the packet to + * @param buffer The buffer to write the message to * @param length The length of the buffer - * @param block The block to call when the packet has been received. If the + * @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 packets have been received. - * If you want the next method in the queue to handle the packet + * 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; /** - * @brief Asynchronously receives a packet with stream ID and PPID and stores + * @brief Asynchronously receives a message with stream ID and PPID and stores * it into the specified buffer. * - * If the buffer is too small, the packet is truncated. + * If the buffer is too small, the message is truncated. * - * @param buffer The buffer to write the packet to + * @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 packet has been received. If the + * @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 packets have been received. - * If you want the next method in the queue to handle the packet + * 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; #endif /** - * @brief Sends the specified packet on the specified stream. + * @brief Sends the specified message on the specified stream. * - * @param buffer The buffer to send as a packet + * @param buffer The buffer to send as a message * @param length The length of the buffer * @param streamID The stream ID for the message * @param PPID The Payload Protocol Identifier for the message - * @param flags Flags for the packet + * @param flags Flags for the message * @throw OFWriteFailedException Sending failed * @throw OFNotOpenException The socket is not open */ - (void)sendBuffer: (const void *)buffer length: (size_t)length streamID: (uint16_t)streamID PPID: (uint32_t)PPID - flags: (OFSCTPPacketFlags)flags; + flags: (OFSCTPMessageFlags)flags; /** - * @brief Asynchronously sends the specified packet on the specified stream. + * @brief Asynchronously sends the specified message on the specified stream. * - * @param data The data to send as a packet + * @param data The data to send as a message * @param streamID The stream ID for the message * @param PPID The Payload Protocol Identifier for the message - * @param flags Flags for the packet + * @param flags Flags for the message */ - (void)asyncSendData: (OFData *)data streamID: (uint16_t)streamID PPID: (uint32_t)PPID - flags: (OFSCTPPacketFlags)flags; + flags: (OFSCTPMessageFlags)flags; /** - * @brief Asynchronously sends the specified packet on the specified stream. + * @brief Asynchronously sends the specified message on the specified stream. * - * @param data The data to send as a packet + * @param data The data to send as a message * @param streamID The stream ID for the message * @param PPID The Payload Protocol Identifier for the message - * @param flags Flags for the packet + * @param flags Flags for the message * @param runLoopMode The run loop mode in which to perform the asynchronous * send */ - (void)asyncSendData: (OFData *)data streamID: (uint16_t)streamID PPID: (uint32_t)PPID - flags: (OFSCTPPacketFlags)flags + flags: (OFSCTPMessageFlags)flags runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** - * @brief Asynchronously sends the specified packet on the specified stream. + * @brief Asynchronously sends the specified message on the specified stream. + * + * @param data The data to send as a message + * @param streamID The stream ID for the message + * @param PPID The Payload Protocol Identifier for the message + * @param flags Flags for the message + * @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. + */ +- (void)asyncSendData: (OFData *)data + streamID: (uint16_t)streamID + PPID: (uint32_t)PPID + flags: (OFSCTPMessageFlags)flags + block: (OFSCTPSocketAsyncSendDataBlock)block; + +/** + * @brief Asynchronously sends the specified message on the specified stream. * - * @param data The data to send as a packet + * @param data The data to send as a message * @param streamID The stream ID for the message * @param PPID The Payload Protocol Identifier for the message - * @param flags Flags for the packet - * @param block The block to call when the packet has been sent. It should + * @param flags Flags for the message + * @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. */ - (void)asyncSendData: (OFData *)data streamID: (uint16_t)streamID PPID: (uint32_t)PPID - flags: (OFSCTPPacketFlags)flags - block: (OFSCTPSocketAsyncSendDataBlock)block; - -/** - * @brief Asynchronously sends the specified packet on the specified stream. - * - * @param data The data to send as a packet - * @param streamID The stream ID for the message - * @param PPID The Payload Protocol Identifier for the message - * @param flags Flags for the packet - * @param runLoopMode The run loop mode in which to perform the asynchronous - * send - * @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 - streamID: (uint16_t)streamID - PPID: (uint32_t)PPID - flags: (OFSCTPPacketFlags)flags + flags: (OFSCTPMessageFlags)flags runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSCTPSocketAsyncSendDataBlock)block; #endif @end OF_ASSUME_NONNULL_END Index: src/OFSCTPSocket.m ================================================================== --- src/OFSCTPSocket.m +++ src/OFSCTPSocket.m @@ -354,11 +354,11 @@ - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length streamID: (uint16_t *)streamID PPID: (uint32_t *)PPID - flags: (OFSCTPPacketFlags *)flags + flags: (OFSCTPMessageFlags *)flags { ssize_t ret; struct iovec iov = { .iov_base = buffer, .iov_len = length @@ -397,11 +397,11 @@ *flags = 0; if (infotype == SCTP_RECVV_RCVINFO && rcvinfoSize >= (socklen_t)sizeof(rcvinfo) && rcvinfo.rcv_flags & SCTP_UNORDERED) - *flags |= OFSCTPPacketUnordered; + *flags |= OFSCTPMessageUnordered; } return ret; } @@ -460,11 +460,11 @@ - (void)sendBuffer: (const void *)buffer length: (size_t)length streamID: (uint16_t)streamID PPID: (uint32_t)PPID - flags: (OFSCTPPacketFlags)flags + flags: (OFSCTPMessageFlags)flags { ssize_t bytesWritten; struct iovec iov = { .iov_base = (void *)buffer, .iov_len = length @@ -471,11 +471,11 @@ }; struct sctp_sndinfo sndinfo = { .snd_sid = streamID, .snd_ppid = PPID, .snd_flags = - ((flags & OFSCTPPacketUnordered) ? SCTP_UNORDERED : 0), + ((flags & OFSCTPMessageUnordered) ? SCTP_UNORDERED : 0), }; if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; @@ -498,11 +498,11 @@ } - (void)asyncSendData: (OFData *)data streamID: (uint16_t)streamID PPID: (uint32_t)PPID - flags: (OFSCTPPacketFlags)flags + flags: (OFSCTPMessageFlags)flags { [self asyncSendData: data streamID: streamID PPID: PPID flags: flags @@ -510,11 +510,11 @@ } - (void)asyncSendData: (OFData *)data streamID: (uint16_t)streamID PPID: (uint32_t)PPID - flags: (OFSCTPPacketFlags)flags + flags: (OFSCTPMessageFlags)flags runLoopMode: (OFRunLoopMode)runLoopMode { [OFRunLoop of_addAsyncSendForSCTPSocket: self data: data streamID: streamID @@ -529,12 +529,12 @@ #ifdef OF_HAVE_BLOCKS - (void)asyncSendData: (OFData *)data streamID: (uint16_t)streamID PPID: (uint32_t)PPID - flags: (OFSCTPPacketFlags)flags - block: (OFSequencedPacketSocketAsyncSendDataBlock)block + flags: (OFSCTPMessageFlags)flags + block: (OFSCTPSocketAsyncSendDataBlock)block { [self asyncSendData: data streamID: streamID PPID: PPID flags: flags @@ -543,13 +543,13 @@ } - (void)asyncSendData: (OFData *)data streamID: (uint16_t)streamID PPID: (uint32_t)PPID - flags: (OFSCTPPacketFlags)flags + flags: (OFSCTPMessageFlags)flags runLoopMode: (OFRunLoopMode)runLoopMode - block: (OFSequencedPacketSocketAsyncSendDataBlock)block + block: (OFSCTPSocketAsyncSendDataBlock)block { [OFRunLoop of_addAsyncSendForSCTPSocket: self data: data streamID: streamID PPID: PPID @@ -558,22 +558,22 @@ block: block delegate: nil]; } #endif -- (void)setCanDelaySendingPackets: (bool)canDelaySendingPackets +- (void)setCanDelaySendingMessages: (bool)canDelaySendingMessages { - int v = !canDelaySendingPackets; + int v = !canDelaySendingMessages; if (setsockopt(_socket, IPPROTO_SCTP, SCTP_NODELAY, (char *)&v, (socklen_t)sizeof(v)) != 0) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: _OFSocketErrNo()]; } -- (bool)canDelaySendingPackets +- (bool)canDelaySendingMessages { int v; socklen_t len = sizeof(v); if (getsockopt(_socket, IPPROTO_SCTP, SCTP_NODELAY, Index: tests/OFSCTPSocketTests.m ================================================================== --- tests/OFSCTPSocketTests.m +++ tests/OFSCTPSocketTests.m @@ -34,11 +34,11 @@ OFSCTPSocket *server, *client, *accepted; OFSocketAddress address; char buffer[6]; uint16_t streamID; uint32_t PPID; - OFSCTPPacketFlags flags; + OFSCTPMessageFlags flags; server = [OFSCTPSocket socket]; client = [OFSCTPSocket socket]; @try { @@ -63,18 +63,18 @@ [client sendBuffer: "Hello!" length: 6 streamID: 1 PPID: 1234 - flags: OFSCTPPacketUnordered]; + flags: OFSCTPMessageUnordered]; [accepted receiveIntoBuffer: buffer length: 6 streamID: &streamID PPID: &PPID flags: &flags]; OTAssertEqual(memcmp(buffer, "Hello!", 6), 0); OTAssertEqual(streamID, 1); OTAssertEqual(PPID, 1234); - OTAssertTrue(flags & OFSCTPPacketUnordered); + OTAssertTrue(flags & OFSCTPMessageUnordered); } @end