Differences From Artifact [2e3d49a6fe]:
- File
src/OFSCTPSocket.h
— part of check-in
[816c13da9b]
at
2024-05-01 23:23:46
on branch sctp
— OFSCTPSocket: Rename packet to message
Let's use the proper terminology for the protocol. (user: js, size: 14136) [annotate] [blame] [check-ins using]
To Artifact [48237f617c]:
- File
src/OFSCTPSocket.h
— part of check-in
[0fd2b1b4c8]
at
2024-05-04 20:05:40
on branch sctp
— OFSCTPSocket: Use a dictionary for message info
This is more extensible. Without this, extending it later would result
in an API and ABI breakage. (user: js, size: 13778) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 | #import "OFSequencedPacketSocket.h" #import "OFRunLoop.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFSCTPSocket; @class OFString; /** | > | > > > > > > | | > > > > > > > > > > > > > > | > > > > > > | > > > > > > > > > > < < | | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | #import "OFSequencedPacketSocket.h" #import "OFRunLoop.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFSCTPSocket; @class OFString; /** * @brief A key for the SCTP message info. * * Possible values are: * * * @ref OFSCTPStreamID * * @ref OFSCTPPPID * * @ref OFSCTPUnordered */ typedef OFConstantString *OFSCTPMessageInfoKey; /** * @brief A dictionary mapping keys of type @ref OFSCTPMessageInfoKey to their * values. */ typedef OFDictionary OF_GENERIC(OFSCTPMessageInfoKey, id) *OFSCTPMessageInfo; #ifdef __cplusplus extern "C" { #endif /** * @brief The SCTP stream ID for which the message was send / received. * * This is an `uint16_t` wrapped in an @ref OFNumber. */ extern const OFSCTPMessageInfoKey OFSCTPStreamID; /** * @brief The Payload Protocol Identifier for the message. * * This is an `uint32_t` wrapped in an @ref OFNumber. */ extern const OFSCTPMessageInfoKey OFSCTPPPID; /** * @brief Whether the message is send / received out of order. * * Possible values are an @ref OFNumber with either `true` or `false`. */ extern const OFSCTPMessageInfoKey OFSCTPUnordered; #ifdef __cplusplus } #endif #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when the socket connected. * * @param exception An exception which occurred while connecting the socket or * `nil` on success */ typedef void (^OFSCTPSocketAsyncConnectBlock)(id _Nullable exception); /** * @brief A block which is called when a message has been received. * * @param length The length of the message * @param info Information about the message, see @ref OFSCTPMessageInfo * @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, OFSCTPMessageInfo info, id _Nullable exception); /** * @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 |
︙ | ︙ | |||
92 93 94 95 96 97 98 | /** * @brief This method is called when a message has been received. * * @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 | < < | < < | < < | < < | | 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | /** * @brief This method is called when a message has been received. * * @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 info Information about the message, see @ref OFSCTPMessageInfo * @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 info: (nullable OFSCTPMessageInfo)info exception: (nullable id)exception; /** * @brief This method is called when a message has been sent. * * @param socket The SCTP socket which sent a message * @param data The data which was sent * @param info Information about the message, see @ref OFSCTPMessageInfo * @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 info: (nullable OFSCTPMessageInfo)info exception: (nullable id)exception; @end /** * @class OFSCTPSocket OFSCTPSocket.h ObjFW/OFSCTPSocket.h * * @brief A class which provides methods to create and use SCTP sockets in |
︙ | ︙ | |||
234 235 236 237 238 239 240 | * @brief Receives a message for the specified stream ID and stores it into the * specified buffer. * * If the buffer is too small, the message is truncated. * * @param buffer The buffer to write the message to * @param length The length of the buffer | < < | | | < | | | | | | | | | 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | * @brief Receives a message for the specified stream ID and stores it into the * specified buffer. * * If the buffer is too small, the message is truncated. * * @param buffer The buffer to write the message to * @param length The length of the buffer * @param info Information about the message, see @ref OFSCTPMessageInfo * @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 info: (__autoreleasing _Nullable OFSCTPMessageInfo *_Nullable)info; /** * @brief Asynchronously receives a message and stores it into the specified * buffer. * * If the buffer is too small, the message is truncated. * * @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 message and stores it into the specified * buffer. * * If the buffer is too small, the message is truncated. * * @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 length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously receives a message and stores it into the specified * buffer. * * If the buffer is too small, the message is truncated. * * @param buffer The buffer to write the message to * @param length The length of the buffer * @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 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 message and stores it into the specified * buffer. * * If the buffer is too small, the message is truncated. * * @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 |
︙ | ︙ | |||
320 321 322 323 324 325 326 | #endif /** * @brief Sends the specified message on the specified stream. * * @param buffer The buffer to send as a message * @param length The length of the buffer | < < | < < | < < | | < < < < < | < < | < < | < < | < < | < < | | 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | #endif /** * @brief Sends the specified message on the specified stream. * * @param buffer The buffer to send as a message * @param length The length of the buffer * @param info Information about the message, see @ref OFSCTPMessageInfo * @throw OFWriteFailedException Sending failed * @throw OFNotOpenException The socket is not open */ - (void)sendBuffer: (const void *)buffer length: (size_t)length info: (nullable OFSCTPMessageInfo)info; /** * @brief Asynchronously sends the specified message on the specified stream. * * @param data The data to send as a message * @param info Information about the message, see @ref OFSCTPMessageInfo */ - (void)asyncSendData: (OFData *)data info: (nullable OFSCTPMessageInfo)info; /** * @brief Asynchronously sends the specified message on the specified stream. * * @param data The data to send as a message * @param info Information about the message, see @ref OFSCTPMessageInfo * @param runLoopMode The run loop mode in which to perform the asynchronous * send */ - (void)asyncSendData: (OFData *)data info: (nullable OFSCTPMessageInfo)info runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously sends the specified message on the specified stream. * * @param data The data to send as a message * @param info Information about the message, see @ref OFSCTPMessageInfo * @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 info: (nullable OFSCTPMessageInfo)info block: (OFSCTPSocketAsyncSendDataBlock)block; /** * @brief Asynchronously sends the specified message on the specified stream. * * @param data The data to send as a message * @param info Information about the message, see @ref OFSCTPMessageInfo * @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 info: (nullable OFSCTPMessageInfo)info runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSCTPSocketAsyncSendDataBlock)block; #endif @end OF_ASSUME_NONNULL_END |