︙ | | |
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
-
+
|
@end
# endif
@interface OFRunLoopAcceptQueueItem: OFRunLoopQueueItem
{
@public
# ifdef OF_HAVE_BLOCKS
id _block;
id _handler;
# endif
}
@end
@interface OFRunLoopDatagramReceiveQueueItem: OFRunLoopQueueItem
{
@public
|
︙ | | |
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
-
+
-
+
|
}
@end
@interface OFRunLoopPacketReceiveQueueItem: OFRunLoopQueueItem
{
@public
# ifdef OF_HAVE_BLOCKS
OFSequencedPacketSocketAsyncReceiveBlock _block;
OFSequencedPacketSocketPacketReceivedHandler _handler;
# endif
void *_buffer;
size_t _length;
}
@end
@interface OFRunLoopPacketSendQueueItem: OFRunLoopQueueItem
{
@public
# ifdef OF_HAVE_BLOCKS
OFSequencedPacketSocketAsyncSendDataBlock _block;
OFSequencedPacketSocketDataSentHandler _handler;
# endif
OFData *_data;
}
@end
# ifdef OF_HAVE_SCTP
@interface OFRunLoopSCTPReceiveQueueItem: OFRunLoopQueueItem
|
︙ | | |
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
|
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
|
-
+
-
+
-
-
+
+
-
+
|
acceptedSocket = [object accept];
} @catch (id e) {
acceptedSocket = nil;
exception = e;
}
# ifdef OF_HAVE_BLOCKS
if (_block != NULL) {
if (_handler != NULL) {
if ([object isKindOfClass: [OFStreamSocket class]])
return ((OFStreamSocketAsyncAcceptBlock)_block)(
return ((OFStreamSocketAsyncAcceptBlock)_handler)(
acceptedSocket, exception);
else if ([object isKindOfClass:
[OFSequencedPacketSocket class]])
return ((OFSequencedPacketSocketAsyncAcceptBlock)
_block)(acceptedSocket, exception);
return ((OFSequencedPacketSocketAcceptedHandler)
_handler)(object, acceptedSocket, exception);
else
OFEnsure(0);
} else {
# endif
if (![_delegate respondsToSelector:
@selector(socket:didAcceptSocket:exception:)])
return false;
return [_delegate socket: object
didAcceptSocket: acceptedSocket
exception: exception];
# ifdef OF_HAVE_BLOCKS
}
# endif
}
# ifdef OF_HAVE_BLOCKS
- (void)dealloc
{
[_block release];
[_handler release];
[super dealloc];
}
# endif
@end
@implementation OFRunLoopDatagramReceiveQueueItem
|
︙ | | |
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
|
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
|
-
-
+
+
-
+
-
-
+
+
|
length = [object receiveIntoBuffer: _buffer length: _length];
} @catch (id e) {
length = 0;
exception = e;
}
# ifdef OF_HAVE_BLOCKS
if (_block != NULL)
return _block(length, exception);
if (_handler != NULL)
return _handler(object, _buffer, length, exception);
else {
# endif
if (![_delegate respondsToSelector: @selector(
socket:didReceiveIntoBuffer:length:exception:)])
return false;
return [_delegate socket: object
didReceiveIntoBuffer: _buffer
length: length
exception: exception];
# ifdef OF_HAVE_BLOCKS
}
# endif
}
# ifdef OF_HAVE_BLOCKS
- (void)dealloc
{
[_block release];
[_handler release];
[super dealloc];
}
# endif
@end
@implementation OFRunLoopPacketSendQueueItem
- (bool)handleObject: (id)object
{
id exception = nil;
OFData *newData, *oldData;
@try {
[object sendBuffer: _data.items
length: _data.count * _data.itemSize];
} @catch (id e) {
exception = e;
}
# ifdef OF_HAVE_BLOCKS
if (_block != NULL) {
newData = _block(exception);
if (_handler != NULL) {
newData = _handler(object, _data, exception);
if (newData == nil)
return false;
oldData = _data;
_data = [newData copy];
[oldData release];
|
︙ | | |
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
|
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
|
-
+
|
}
# endif
}
- (void)dealloc
{
# ifdef OF_HAVE_BLOCKS
[_block release];
[_handler release];
# endif
[_data release];
[super dealloc];
}
@end
|
︙ | | |
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
|
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
|
-
+
-
+
|
QUEUE_ITEM
}
# endif
+ (void)of_addAsyncAcceptForSocket: (id)sock
mode: (OFRunLoopMode)mode
block: (id)block
handler: (id)handler
delegate: (id)delegate
{
NEW_READ(OFRunLoopAcceptQueueItem, sock, mode)
queueItem->_delegate = [delegate retain];
# ifdef OF_HAVE_BLOCKS
queueItem->_block = [block copy];
queueItem->_handler = [handler copy];
# endif
QUEUE_ITEM
}
+ (void)of_addAsyncReceiveForDatagramSocket: (OFDatagramSocket *)sock
buffer: (void *)buffer
|
︙ | | |
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
|
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
|
-
+
-
+
-
+
-
+
|
+ (void)of_addAsyncReceiveForSequencedPacketSocket: (OFSequencedPacketSocket *)
sock
buffer: (void *)buffer
length: (size_t)length
mode: (OFRunLoopMode)mode
# ifdef OF_HAVE_BLOCKS
block: (OFSequencedPacketSocketAsyncReceiveBlock)block
handler: (OFSequencedPacketSocketPacketReceivedHandler)handler
# endif
delegate: (id <OFSequencedPacketSocketDelegate>)delegate
{
NEW_READ(OFRunLoopPacketReceiveQueueItem, sock, mode)
queueItem->_delegate = [delegate retain];
# ifdef OF_HAVE_BLOCKS
queueItem->_block = [block copy];
queueItem->_handler = [handler copy];
# endif
queueItem->_buffer = buffer;
queueItem->_length = length;
QUEUE_ITEM
}
+ (void)of_addAsyncSendForSequencedPacketSocket: (OFSequencedPacketSocket *)sock
data: (OFData *)data
mode: (OFRunLoopMode)mode
# ifdef OF_HAVE_BLOCKS
block: (OFSequencedPacketSocketAsyncSendDataBlock)block
handler: (OFSequencedPacketSocketDataSentHandler)handler
# endif
delegate: (id <OFSequencedPacketSocketDelegate>)delegate
{
NEW_WRITE(OFRunLoopPacketSendQueueItem, sock, mode)
queueItem->_delegate = [delegate retain];
# ifdef OF_HAVE_BLOCKS
queueItem->_block = [block copy];
queueItem->_handler = [handler copy];
# endif
queueItem->_data = [data copy];
QUEUE_ITEM
}
# ifdef OF_HAVE_SCTP
|
︙ | | |
︙ | | |
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
|
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
|
@class OFData;
@class OFSequencedPacketSocket;
#ifdef OF_HAVE_BLOCKS
/**
* @brief A block which is called when a packet has been received.
*
* @deprecated Use @ref OFSequencedPacketSocketPacketReceivedHandler instead.
*
* @param length The length 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 (^OFSequencedPacketSocketAsyncReceiveBlock)(size_t length,
id _Nullable exception)
OF_DEPRECATED(ObjFW, 1, 2,
"Use OFSequencedPacketSocketPacketReceivedHandler instead");
/**
* @brief A handler which is called when a packet 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 exception An exception which occurred while receiving or `nil` on
* success
* @return A bool whether the same handler should be used for the next receive
*/
typedef bool (^OFSequencedPacketSocketPacketReceivedHandler)(
OFSequencedPacketSocket *socket, void *buffer, size_t length,
id _Nullable exception);
/**
* @brief A block which is called when a packet has been sent.
*
* @deprecated Use @ref OFSequencedPacketSocketDataSentHandler instead.
*
* @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
*/
typedef OFData *_Nullable (^OFSequencedPacketSocketAsyncSendDataBlock)(
id _Nullable exception);
id _Nullable exception)
OF_DEPRECATED(ObjFW, 1, 2,
"Use OFSequencedPacketSocketDataSentHandler instead");
/**
* @brief A handler which is called when a packet has been sent.
*
* @param socket The sequenced packet socket which sent a packet
* @param data The data which was 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
*/
typedef OFData *_Nullable (^OFSequencedPacketSocketDataSentHandler)(
OFSequencedPacketSocket *socket, OFData *data, id _Nullable exception);
/**
* @brief A block which is called when the socket accepted a connection.
*
* @deprecated Use OFSequencedPacketSocketAcceptedHandler instead.
*
* @param acceptedSocket The socket which has been accepted
* @param exception An exception which occurred while accepting the socket or
* `nil` on success
* @return A bool whether the same block should be used for the next incoming
* connection
*/
typedef bool (^OFSequencedPacketSocketAsyncAcceptBlock)(
OFSequencedPacketSocket *acceptedSocket, id _Nullable exception);
OFSequencedPacketSocket *acceptedSocket, id _Nullable exception)
OF_DEPRECATED(ObjFW, 1, 2,
"Use OFSequencedPacketSocketAcceptedHandler instead");
/**
* @brief A handler which is called when the socket accepted a connection.
*
* @param socket The socket which accepted the connection
* @param acceptedSocket The socket which has been accepted
* @param exception An exception which occurred while accepting the socket or
* `nil` on success
* @return A bool whether the same handler should be used for the next incoming
* connection
*/
typedef bool (^OFSequencedPacketSocketAcceptedHandler)(
OFSequencedPacketSocket *socket, OFSequencedPacketSocket *acceptedSocket,
id _Nullable exception);
#endif
/**
* @protocol OFSequencedPacketSocketDelegate OFSequencedPacketSocket.h
* ObjFW/ObjFW.h
*
* @brief A delegate for OFSequencedPacketSocket.
*/
@protocol OFSequencedPacketSocketDelegate <OFObject>
@optional
/**
* @brief This method is called when a packet 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 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
* @return A bool whether the same handler should be used for the next receive
*/
- (bool)socket: (OFSequencedPacketSocket *)socket
didReceiveIntoBuffer: (void *)buffer
length: (size_t)length
exception: (nullable id)exception;
/**
|
︙ | | |
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
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
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
|
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
runLoopMode: (OFRunLoopMode)runLoopMode;
#ifdef OF_HAVE_BLOCKS
/**
* @brief Asynchronously receives a packet and stores it into the specified
* buffer.
*
* @deprecated Use @ref asyncReceiveIntoBuffer:lenght:handler: instead.
*
* 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
* @param block The block to call when the packet 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
* received next, you need to return false from the method.
*/
- (void)asyncReceiveIntoBuffer: (void *)buffer
length: (size_t)length
block: (OFSequencedPacketSocketAsyncReceiveBlock)block;
block: (OFSequencedPacketSocketAsyncReceiveBlock)block
OF_DEPRECATED(ObjFW, 1, 2,
"Use -[asyncReceiveIntoBuffer:lenght:handler:] instead");
/**
* @brief Asynchronously receives a packet and stores it into the specified
* buffer.
*
* 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
* @param handler The handler to call when the packet has been received. If the
* handler 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 received next, you need to return false from the
* method.
*/
- (void)asyncReceiveIntoBuffer: (void *)buffer
length: (size_t)length
handler: (OFSequencedPacketSocketPacketReceivedHandler)
handler;
/**
* @brief Asynchronously receives a packet and stores it into the specified
* buffer.
*
* @deprecated Use @ref asyncReceiveIntoBuffer:length:runLoopMode:handler:
* instead.
*
* 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
* @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
* 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
* received next, you need to return false from the method.
*/
- (void)asyncReceiveIntoBuffer: (void *)buffer
length: (size_t)length
runLoopMode: (OFRunLoopMode)runLoopMode
block: (OFSequencedPacketSocketAsyncReceiveBlock)block;
block: (OFSequencedPacketSocketAsyncReceiveBlock)block
OF_DEPRECATED(ObjFW, 1, 2,
"Use -[asyncReceiveIntoBuffer:length:runLoopMode:handler:] instead");
/**
* @brief Asynchronously receives a packet and stores it into the specified
* buffer.
*
* 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
* @param runLoopMode The run loop mode in which to perform the asynchronous
* receive
* @param handler The handler to call when the packet has been received. If the
* handler 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 received next, you need to return false from the
* method.
*/
- (void)asyncReceiveIntoBuffer: (void *)buffer
length: (size_t)length
runLoopMode: (OFRunLoopMode)runLoopMode
handler: (OFSequencedPacketSocketPacketReceivedHandler)
handler;
#endif
/**
* @brief Sends the specified packet.
*
* @param buffer The buffer to send as a packet
* @param length The length of the buffer
|
︙ | | |
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
|
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
|
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
*/
- (void)asyncSendData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode;
#ifdef OF_HAVE_BLOCKS
/**
* @brief Asynchronously sends the specified packet.
*
* @deprecated Use @ref asyncSendData:handler: instead.
*
* @param data The data to send as a packet
* @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
block: (OFSequencedPacketSocketAsyncSendDataBlock)block;
block: (OFSequencedPacketSocketAsyncSendDataBlock)block
OF_DEPRECATED(ObjFW, 1, 2, "Use -[asyncSendData:handler:] instead");
/**
* @brief Asynchronously sends the specified packet.
*
* @param data The data to send as a packet
* @param handler The handler 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
handler: (OFSequencedPacketSocketDataSentHandler)handler;
/**
* @brief Asynchronously sends the specified packet.
*
* @deprecated Use @ref asyncSendData:runLoopMode:handler: instead.
*
* @param data The data to send as a 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
runLoopMode: (OFRunLoopMode)runLoopMode
block: (OFSequencedPacketSocketAsyncSendDataBlock)block;
block: (OFSequencedPacketSocketAsyncSendDataBlock)block
OF_DEPRECATED(ObjFW, 1, 2,
"Use -[asyncSendData:runLoopMode:handler:] instead");
/**
* @brief Asynchronously sends the specified packet.
*
* @param data The data to send as a packet
* @param runLoopMode The run loop mode in which to perform the asynchronous
* send
* @param handler The handler 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
runLoopMode: (OFRunLoopMode)runLoopMode
handler: (OFSequencedPacketSocketDataSentHandler)handler;
#endif
/**
* @brief Listen on the socket.
*
* @param backlog Maximum length for the queue of pending connections.
* @throw OFListenOnSocketFailedException Listening failed
|
︙ | | |
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
|
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
|
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
* accept
*/
- (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode;
#ifdef OF_HAVE_BLOCKS
/**
* @brief Asynchronously accept an incoming connection.
*
* @deprecated Use @ref asyncAcceptWithHandler: instead.
*
* @param block The block to execute when a new connection has been accepted.
* Returns whether the next incoming connection should be accepted
* by the specified block as well.
*/
- (void)asyncAcceptWithBlock: (OFSequencedPacketSocketAsyncAcceptBlock)block;
- (void)asyncAcceptWithBlock: (OFSequencedPacketSocketAsyncAcceptBlock)block
OF_DEPRECATED(ObjFW, 1, 2, "Use -[asyncAcceptWithHandler:] instead");
/**
* @brief Asynchronously accept an incoming connection.
*
* @param handler The handler to execute when a new connection has been
* accepted. Returns whether the next incoming connection
* should be accepted by the specified handler as well.
*/
- (void)asyncAcceptWithHandler: (OFSequencedPacketSocketAcceptedHandler)handler;
/**
* @brief Asynchronously accept an incoming connection.
*
* @deprecated Use @ref asyncAcceptWithRunLoopMode:handler: instead.
*
* @param runLoopMode The run loop mode in which to perform the asynchronous
* accept
* @param block The block to execute when a new connection has been accepted.
* Returns whether the next incoming connection should be accepted
* by the specified block as well.
*/
- (void)
asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
block: (OFSequencedPacketSocketAsyncAcceptBlock)block;
block: (OFSequencedPacketSocketAsyncAcceptBlock)block
OF_DEPRECATED(ObjFW, 1, 2,
"Use -[asyncAcceptWithRunLoopMode:handler:] instead");
/**
* @brief Asynchronously accept an incoming connection.
*
* @param runLoopMode The run loop mode in which to perform the asynchronous
* accept
* @param handler The handler to execute when a new connection has been
* accepted. Returns whether the next incoming connection
* should be accepted by the specified handler as well.
*/
- (void)
asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
handler: (OFSequencedPacketSocketAcceptedHandler)handler;
#endif
/**
* @brief Cancels all pending asynchronous requests on the socket.
*/
- (void)cancelAsyncRequests;
|
︙ | | |
︙ | | |
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
|
runLoopMode: (OFRunLoopMode)runLoopMode
{
[OFRunLoop of_addAsyncReceiveForSequencedPacketSocket: self
buffer: buffer
length: length
mode: runLoopMode
# ifdef OF_HAVE_BLOCKS
block: NULL
handler: NULL
# endif
delegate: _delegate];
}
#ifdef OF_HAVE_BLOCKS
- (void)asyncReceiveIntoBuffer: (void *)buffer
length: (size_t)length
block: (OFSequencedPacketSocketAsyncReceiveBlock)block
{
OFSequencedPacketSocketPacketReceivedHandler handler = ^ (
OFSequencedPacketSocket *socket, void *buffer_, size_t length_,
id exception) {
return block(length_, exception);
};
[self asyncReceiveIntoBuffer: buffer
length: length
runLoopMode: OFDefaultRunLoopMode
handler: handler];
}
- (void)asyncReceiveIntoBuffer: (void *)buffer
length: (size_t)length
handler: (OFSequencedPacketSocketPacketReceivedHandler)
handler
{
[self asyncReceiveIntoBuffer: buffer
length: length
runLoopMode: OFDefaultRunLoopMode
block: block];
handler: handler];
}
- (void)
asyncReceiveIntoBuffer: (void *)buffer
length: (size_t)length
runLoopMode: (OFRunLoopMode)runLoopMode
block: (OFSequencedPacketSocketAsyncReceiveBlock)block
{
OFSequencedPacketSocketPacketReceivedHandler handler = ^ (
OFSequencedPacketSocket *socket, void *buffer_, size_t length_,
id exception) {
return block(length_, exception);
};
[OFRunLoop of_addAsyncReceiveForSequencedPacketSocket: self
buffer: buffer
length: length
mode: runLoopMode
handler: handler
delegate: nil];
}
- (void)asyncReceiveIntoBuffer: (void *)buffer
length: (size_t)length
runLoopMode: (OFRunLoopMode)runLoopMode
handler: (OFSequencedPacketSocketPacketReceivedHandler)
handler
{
[OFRunLoop of_addAsyncReceiveForSequencedPacketSocket: self
buffer: buffer
length: length
mode: runLoopMode
block: block
handler: handler
delegate: nil];
}
#endif
- (void)sendBuffer: (const void *)buffer length: (size_t)length
{
if (_socket == OFInvalidSocketHandle)
|
︙ | | |
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
|
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
-
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
|
- (void)asyncSendData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode
{
[OFRunLoop of_addAsyncSendForSequencedPacketSocket: self
data: data
mode: runLoopMode
# ifdef OF_HAVE_BLOCKS
block: NULL
handler: NULL
# endif
delegate: _delegate];
}
#ifdef OF_HAVE_BLOCKS
- (void)asyncSendData: (OFData *)data
block: (OFSequencedPacketSocketAsyncSendDataBlock)block
{
OFSequencedPacketSocketDataSentHandler handler = ^ (
OFSequencedPacketSocket *socket, OFData *data_, id exception) {
return block(exception);
};
[self asyncSendData: data
runLoopMode: OFDefaultRunLoopMode
handler: handler];
}
block: block];
- (void)asyncSendData: (OFData *)data
handler: (OFSequencedPacketSocketDataSentHandler)handler
{
[self asyncSendData: data
runLoopMode: OFDefaultRunLoopMode
handler: handler];
}
- (void)asyncSendData: (OFData *)data
runLoopMode: (OFRunLoopMode)runLoopMode
block: (OFSequencedPacketSocketAsyncSendDataBlock)block
{
OFSequencedPacketSocketDataSentHandler handler = ^ (
OFSequencedPacketSocket *socket, OFData *data_, id exception) {
return block(exception);
};
[self asyncSendData: data
runLoopMode: runLoopMode
handler: handler];
}
- (void)asyncSendData: (OFData *)data
runLoopMode: (OFRunLoopMode)runLoopMode
handler: (OFSequencedPacketSocketDataSentHandler)handler
{
[OFRunLoop of_addAsyncSendForSequencedPacketSocket: self
data: data
mode: runLoopMode
block: block
handler: handler
delegate: nil];
}
#endif
- (void)listen
{
[self listenWithBacklog: SOMAXCONN];
|
︙ | | |
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
|
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
|
-
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
|
[self asyncAcceptWithRunLoopMode: OFDefaultRunLoopMode];
}
- (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
{
[OFRunLoop of_addAsyncAcceptForSocket: self
mode: runLoopMode
block: NULL
handler: NULL
delegate: _delegate];
}
#ifdef OF_HAVE_BLOCKS
- (void)asyncAcceptWithBlock: (OFSequencedPacketSocketAsyncAcceptBlock)block
{
OFSequencedPacketSocketAcceptedHandler handler = ^ (
OFSequencedPacketSocket *socket,
OFSequencedPacketSocket *acceptedSocket, id exception) {
return block(acceptedSocket, exception);
};
[self asyncAcceptWithRunLoopMode: OFDefaultRunLoopMode block: block];
[self asyncAcceptWithRunLoopMode: OFDefaultRunLoopMode
handler: handler];
}
- (void)asyncAcceptWithHandler: (OFSequencedPacketSocketAcceptedHandler)handler
{
[self asyncAcceptWithRunLoopMode: OFDefaultRunLoopMode
handler: handler];
}
- (void)
asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
block: (OFSequencedPacketSocketAsyncAcceptBlock)block
{
OFSequencedPacketSocketAcceptedHandler handler = ^ (
OFSequencedPacketSocket *socket,
OFSequencedPacketSocket *acceptedSocket, id exception) {
return block(acceptedSocket, exception);
};
[self asyncAcceptWithRunLoopMode: runLoopMode
handler: handler];
}
- (void)
asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
handler: (OFSequencedPacketSocketAcceptedHandler)handler
{
[OFRunLoop of_addAsyncAcceptForSocket: self
mode: runLoopMode
block: block
handler: handler
delegate: nil];
}
#endif
- (const OFSocketAddress *)remoteAddress
{
if (_socket == OFInvalidSocketHandle)
|
︙ | | |