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
|
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
|
-
-
-
+
+
+
-
+
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
+
+
+
|
* @param buffer The buffer the packet has been written to
* @param length The length of the packet
* @param sender The address of the sender of the packet
* @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 (^of_udp_socket_async_receive_block_t)(OFUDPSocket *socket,
void *buffer, size_t length, of_socket_address_t sender,
id _Nullable exception);
typedef bool (^of_udp_socket_async_receive_block_t)(
OFUDPSocket *_Nonnull socket, void *_Nonnull buffer, size_t length,
const of_socket_address_t *_Nonnull sender, id _Nullable exception);
/*!
* @brief A block which is called when a packet has been sent.
*
* @param socket The UDP socket which sent a packet
* @param buffer A pointer to the buffer which was sent. This can be changed to
* @param data The data which was sent
* point to a different buffer to be used on the next send.
* @param bytesSent The number of bytes which have been sent. This matches the
* length specified on the asynchronous send if no exception
* was encountered.
* @param receiver The receiver for the UDP packet. This may be set to a new
* @param receiver The receiver for the UDP packet
* receiver to which the next packet is sent.
* @param exception An exception which occurred while reading or `nil` on
* success
* @return The length to repeat the send with or 0 if it should not repeat.
* @return The data to repeat the send with or nil if it should not repeat
* The buffer and receiver may be changed, so that every time a new
* buffer, length and receiver can be specified while the callback
* stays the same.
*/
typedef size_t (^of_udp_socket_async_send_block_t)(OFUDPSocket *socket,
const void *_Nonnull *_Nonnull buffer, size_t bytesSent,
of_socket_address_t *_Nonnull receiver, id exception);
typedef OFData *_Nullable (^of_udp_socket_async_send_data_block_t)(
OFUDPSocket *_Nonnull socket, OFData *_Nonnull data,
const of_socket_address_t *_Nonnull receiver, id _Nullable exception);
#endif
/*!
* @protocol OFUDPSocketDelegate OFUDPSocket.h ObjFW/OFUDPSocket.h
*
* @brief A delegate for OFUDPSocket.
*/
|
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
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
102
103
104
|
-
+
-
+
-
-
-
+
-
-
+
-
-
-
-
-
+
+
-
-
-
+
+
|
* @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: (OF_KINDOF(OFUDPSocket *))socket
didReceiveIntoBuffer: (void *)buffer
length: (size_t)length
sender: (of_socket_address_t)sender
sender: (const of_socket_address_t *_Nonnull)sender
exception: (nullable id)exception;
/*!
* @brief This which is called when a packet has been sent.
*
* @param socket The UDP socket which sent a packet
* @param buffer A pointer to the buffer which was sent. This can be changed to
* @param data The data which was sent
* point to a different buffer to be used on the next send.
* @param length The length of the buffer that has been sent
* @param receiver The receiver for the UDP packet. This may be set to a new
* @param receiver The receiver for the UDP packet
* receiver to which the next packet is sent.
* @param exception An exception that occurred while sending, or nil on success
* @return The length to repeat the send with or 0 if it should not repeat.
* @return The data to repeat the send with or nil if it should not repeat
* The buffer and receiver may be changed, so that every time a new
* buffer, length and receiver can be specified while the callback
* stays the same.
*/
- (size_t)socket: (OF_KINDOF(OFUDPSocket *))socket
didSendBuffer: (const void *_Nonnull *_Nonnull)buffer
- (nullable OFData *)socket: (OF_KINDOF(OFUDPSocket *))socket
didSendData: (OFData *)data
length: (size_t)length
receiver: (of_socket_address_t *_Nonnull)receiver
exception: (nullable id)exception;
receiver: (const of_socket_address_t *_Nonnull)receiver
exception: (nullable id)exception;
@end
/*!
* @class OFUDPSocket OFUDPSocket.h ObjFW/OFUDPSocket.h
*
* @brief A class which provides methods to create and use UDP sockets.
*
|
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
334
335
336
337
338
339
340
341
342
343
344
345
|
256
257
258
259
260
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
|
-
+
-
-
+
-
+
-
-
+
-
+
-
-
+
-
+
-
-
-
+
+
-
+
-
-
+
-
-
+
+
-
-
-
+
-
-
-
+
+
-
+
-
-
+
-
-
+
+
-
-
-
+
-
-
-
-
+
+
+
|
- (void)sendBuffer: (const void *)buffer
length: (size_t)length
receiver: (const of_socket_address_t *)receiver;
/*!
* @brief Asynchronously sends the specified datagram to the specified address.
*
* @param buffer The buffer to send as a datagram
* @param data The data to send as a datagram
* @param length The length of the buffer
* @param receiver A pointer to an @ref of_socket_address_t to which the
* datagram should be sent
* datagram should be sent. The receiver is copied.
*/
- (void)asyncSendBuffer: (const void *)buffer
- (void)asyncSendData: (OFData *)data
length: (size_t)length
receiver: (of_socket_address_t)receiver;
receiver: (const of_socket_address_t *)receiver;
/*!
* @brief Asynchronously sends the specified datagram to the specified address.
*
* @param buffer The buffer to send as a datagram
* @param data The data to send as a datagram
* @param length The length of the buffer
* @param receiver A pointer to an @ref of_socket_address_t to which the
* datagram should be sent
* datagram should be sent. The receiver is copied.
* @param runLoopMode The run loop mode in which to perform the async send
*/
- (void)asyncSendBuffer: (const void *)buffer
- (void)asyncSendData: (OFData *)data
length: (size_t)length
receiver: (of_socket_address_t)receiver
runLoopMode: (of_run_loop_mode_t)runLoopMode;
receiver: (const of_socket_address_t *)receiver
runLoopMode: (of_run_loop_mode_t)runLoopMode;
#ifdef OF_HAVE_BLOCKS
/*!
* @brief Asynchronously sends the specified datagram to the specified address.
*
* @param buffer The buffer to send as a datagram
* @param data The data to send as a datagram
* @param length The length of the buffer
* @param receiver A pointer to an @ref of_socket_address_t to which the
* datagram should be sent
* datagram should be sent. The receiver is copied.
* @param block The block to call when the packet has been sent. It should
* return the length for the next send with the same callback or 0
* if it should not repeat. The buffer and receiver may be
* return the data for the next send with the same callback or nil
* if it should not repeat.
* changed, so that every time a new buffer, length and receiver
* can be specified while the callback stays the same.
*/
- (void)asyncSendBuffer: (const void *)buffer
- (void)asyncSendData: (OFData *)data
length: (size_t)length
receiver: (of_socket_address_t)receiver
block: (of_udp_socket_async_send_block_t)block;
receiver: (const of_socket_address_t *)receiver
block: (of_udp_socket_async_send_data_block_t)block;
/*!
* @brief Asynchronously sends the specified datagram to the specified address.
*
* @param buffer The buffer to send as a datagram
* @param data The data to send as a datagram
* @param length The length of the buffer
* @param receiver A pointer to an @ref of_socket_address_t to which the
* datagram should be sent
* datagram should be sent. The receiver is copied.
* @param runLoopMode The run loop mode in which to perform the async send
* @param block The block to call when the packet has been sent. It should
* return the length for the next send with the same callback or 0
* if it should not repeat. The buffer and receiver may be
* return the data for the next send with the same callback or nil
* if it should not repeat.
* changed, so that every time a new buffer, length and receiver
* can be specified while the callback stays the same.
*/
- (void)asyncSendBuffer: (const void *)buffer
- (void)asyncSendData: (OFData *)data
length: (size_t)length
receiver: (of_socket_address_t)receiver
runLoopMode: (of_run_loop_mode_t)runLoopMode
block: (of_udp_socket_async_send_block_t)block;
receiver: (const of_socket_address_t *)receiver
runLoopMode: (of_run_loop_mode_t)runLoopMode
block: (of_udp_socket_async_send_data_block_t)block;
#endif
/*!
* @brief Cancels all pending asynchronous requests on the socket.
*/
- (void)cancelAsyncRequests;
|