︙ | | |
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
-
+
|
* FIXME: Errors are not reported to the user.
*/
@interface OFHTTPServer ()
- (bool)of_socket: (OFTCPSocket *)socket
didAcceptSocket: (OFTCPSocket *)clientSocket
context: (id)context
exception: (OFException *)exception;
exception: (id)exception;
@end
static const char *
statusCodeToString(short code)
{
switch (code) {
case 100:
|
︙ | | |
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
-
+
-
+
|
}
- initWithSocket: (OFTCPSocket *)socket
server: (OFHTTPServer *)server;
- (bool)socket: (OFTCPSocket *)socket
didReadLine: (OFString *)line
context: (id)context
exception: (OFException *)exception;
exception: (id)exception;
- (bool)parseProlog: (OFString *)line;
- (bool)parseHeaders: (OFString *)line;
- (bool)socket: (OFTCPSocket *)socket
didReadIntoBuffer: (char *)buffer
length: (size_t)length
context: (id)context
exception: (OFException *)exception;
exception: (id)exception;
- (bool)sendErrorAndClose: (short)statusCode;
- (void)createResponse;
@end
@implementation OFHTTPServer_Connection
- initWithSocket: (OFTCPSocket *)socket
server: (OFHTTPServer *)server
|
︙ | | |
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
|
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
|
-
+
|
[super dealloc];
}
- (bool)socket: (OFTCPSocket *)socket
didReadLine: (OFString *)line
context: (id)context
exception: (OFException *)exception
exception: (id)exception
{
if (line == nil || exception != nil)
return false;
@try {
switch (_state) {
case AWAITING_PROLOG:
|
︙ | | |
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
|
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
|
-
+
|
return true;
}
- (bool)socket: (OFTCPSocket *)socket
didReadIntoBuffer: (char *)buffer
length: (size_t)length
context: (id)context
exception: (OFException *)exception
exception: (id)exception
{
if ([socket isAtEndOfStream] || exception != nil)
return false;
[_body addItems: buffer
count: length];
|
︙ | | |
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
|
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
|
-
+
|
[_listeningSocket release];
_listeningSocket = nil;
}
- (bool)of_socket: (OFTCPSocket *)socket
didAcceptSocket: (OFTCPSocket *)clientSocket
context: (id)context
exception: (OFException *)exception
exception: (id)exception
{
OFHTTPServer_Connection *connection;
if (exception != nil) {
if ([_delegate respondsToSelector:
@selector(server:didReceiveExceptionOnListeningSocket:)])
return [_delegate server: self
|
︙ | | |
︙ | | |
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
143
144
145
146
147
148
149
|
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
143
144
145
146
147
148
|
-
+
-
+
-
-
+
+
-
|
}
@end
@implementation OFRunLoop_ReadQueueItem
- (bool)handleForObject: (id)object
{
size_t length;
OFException *exception = nil;
id exception = nil;
@try {
length = [object readIntoBuffer: _buffer
length: _length];
} @catch (OFException *e) {
} @catch (id e) {
length = 0;
exception = e;
}
# ifdef OF_HAVE_BLOCKS
if (_block != NULL)
return _block(object, _buffer, length, exception);
else {
# endif
bool (*func)(id, SEL, OFStream *, void *, size_t, id,
OFException *) = (bool (*)(id, SEL, OFStream *, void *,
bool (*func)(id, SEL, OFStream *, void *, size_t, id, id) =
(bool (*)(id, SEL, OFStream *, void *, size_t, id, id))
size_t, id, OFException *))
[_target methodForSelector: _selector];
return func(_target, _selector, object, _buffer, length,
_context, exception);
# ifdef OF_HAVE_BLOCKS
}
# endif
|
︙ | | |
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
-
+
-
+
-
-
+
+
-
|
# endif
@end
@implementation OFRunLoop_ExactReadQueueItem
- (bool)handleForObject: (id)object
{
size_t length;
OFException *exception = nil;
id exception = nil;
@try {
length = [object readIntoBuffer: (char *)_buffer + _readLength
length: _exactLength - _readLength];
} @catch (OFException *e) {
} @catch (id e) {
length = 0;
exception = e;
}
_readLength += length;
if (_readLength != _exactLength && ![object isAtEndOfStream] &&
exception == nil)
return true;
# ifdef OF_HAVE_BLOCKS
if (_block != NULL) {
if (!_block(object, _buffer, _readLength, exception))
return false;
_readLength = 0;
return true;
} else {
# endif
bool (*func)(id, SEL, OFStream *, void *, size_t, id,
OFException *) = (bool (*)(id, SEL, OFStream *, void *,
bool (*func)(id, SEL, OFStream *, void *, size_t, id, id) =
(bool (*)(id, SEL, OFStream *, void *, size_t, id, id))
size_t, id, OFException *))
[_target methodForSelector: _selector];
if (!func(_target, _selector, object, _buffer, _readLength,
_context, exception))
return false;
_readLength = 0;
|
︙ | | |
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
|
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
|
-
+
-
+
-
-
-
+
+
+
|
# endif
@end
@implementation OFRunLoop_ReadLineQueueItem
- (bool)handleForObject: (id)object
{
OFString *line;
OFException *exception = nil;
id exception = nil;
@try {
line = [object tryReadLineWithEncoding: _encoding];
} @catch (OFException *e) {
} @catch (id e) {
line = nil;
exception = e;
}
if (line == nil && ![object isAtEndOfStream] && exception == nil)
return true;
# ifdef OF_HAVE_BLOCKS
if (_block != NULL)
return _block(object, line, exception);
else {
# endif
bool (*func)(id, SEL, OFStream *, OFString *, id,
OFException *) = (bool (*)(id, SEL, OFStream *, OFString *,
id, OFException *))[_target methodForSelector: _selector];
bool (*func)(id, SEL, OFStream *, OFString *, id, id) =
(bool (*)(id, SEL, OFStream *, OFString *, id, id))
[_target methodForSelector: _selector];
return func(_target, _selector, object, line, _context,
exception);
# ifdef OF_HAVE_BLOCKS
}
# endif
}
|
︙ | | |
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
|
254
255
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
|
-
+
-
+
-
-
+
+
-
|
# endif
@end
@implementation OFRunLoop_AcceptQueueItem
- (bool)handleForObject: (id)object
{
OFTCPSocket *newSocket;
OFException *exception = nil;
id exception = nil;
@try {
newSocket = [object accept];
} @catch (OFException *e) {
} @catch (id e) {
newSocket = nil;
exception = e;
}
# ifdef OF_HAVE_BLOCKS
if (_block != NULL)
return _block(object, newSocket, exception);
else {
# endif
bool (*func)(id, SEL, OFTCPSocket *, OFTCPSocket *, id,
OFException *) = (bool (*)(id, SEL, OFTCPSocket *,
bool (*func)(id, SEL, OFTCPSocket *, OFTCPSocket *, id, id) =
(bool (*)(id, SEL, OFTCPSocket *, OFTCPSocket *, id, id))
OFTCPSocket *, id, OFException *))
[_target methodForSelector: _selector];
return func(_target, _selector, object, newSocket, _context,
exception);
# ifdef OF_HAVE_BLOCKS
}
# endif
|
︙ | | |
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
|
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
|
-
+
-
+
-
+
-
+
|
@end
@implementation OFRunLoop_UDPReceiveQueueItem
- (bool)handleForObject: (id)object
{
size_t length;
of_udp_socket_address_t address;
OFException *exception = nil;
id exception = nil;
@try {
length = [object receiveIntoBuffer: _buffer
length: _length
sender: &address];
} @catch (OFException *e) {
} @catch (id e) {
length = 0;
exception = e;
}
# ifdef OF_HAVE_BLOCKS
if (_block != NULL)
return _block(object, _buffer, length, address, exception);
else {
# endif
bool (*func)(id, SEL, OFUDPSocket *, void *, size_t,
of_udp_socket_address_t address, id, OFException *) =
of_udp_socket_address_t address, id, id) =
(bool (*)(id, SEL, OFUDPSocket *, void *, size_t,
of_udp_socket_address_t, id, OFException *))
of_udp_socket_address_t, id, id))
[_target methodForSelector: _selector];
return func(_target, _selector, object, _buffer, length,
address, _context, exception);
# ifdef OF_HAVE_BLOCKS
}
# endif
|
︙ | | |
︙ | | |
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
|
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
|
-
-
+
-
+
|
OF_ASSUME_NONNULL_BEGIN
/*! @file */
@class OFStream;
@class OFData;
@class OFException;
#if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_BLOCKS)
/*!
* @brief A block which is called when data was read from the stream.
*
* @param stream The stream on which data was read
* @param buffer A buffer with the data that has been read
* @param length The length of the data that has been read
* @param exception An exception which occurred while reading or `nil` on
* success
* @return A bool whether the same block should be used for the next read
*/
typedef bool (^of_stream_async_read_block_t)(OFStream *stream, void *buffer,
size_t length, OFException *_Nullable exception);
size_t length, id _Nullable exception);
/*!
* @brief A block which is called when a line was read from the stream.
*
* @param stream The stream on which a line was read
* @param line The line which has been read or `nil` when the end of stream
* occurred
* @param exception An exception which occurred while reading or `nil` on
* success
* @return A bool whether the same block should be used for the next read
*/
typedef bool (^of_stream_async_read_line_block_t)(OFStream *stream,
OFString *_Nullable line, OFException *_Nullable exception);
OFString *_Nullable line, id _Nullable exception);
#endif
/*!
* @class OFStream OFStream.h ObjFW/OFStream.h
*
* @brief A base class for different types of streams.
*
|
︙ | | |
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
-
+
|
* data has been received. If the method returns true, it will be
* called again with the same buffer and maximum length when more
* data has been received. If you want the next method in the
* queue to handle the data received next, you need to return
* false from the method.
* @param selector The selector to call on the target. The signature must be
* `bool (OFStream *stream, void *buffer, size_t length,
* id context, OFException *exception)`.
* id context, id exception)`.
*/
- (void)asyncReadIntoBuffer: (void *)buffer
length: (size_t)length
target: (id)target
selector: (SEL)selector
context: (nullable id)context;
|
︙ | | |
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
-
+
|
* data has been received. If the method returns true, it will be
* called again with the same buffer and exact length when more
* data has been received. If you want the next method in the
* queue to handle the data received next, you need to return
* false from the method.
* @param selector The selector to call on the target. The signature must be
* `bool (OFStream *stream, void *buffer, size_t size,
* id context, OFException *exception)`.
* id context, id exception)`.
*/
- (void)asyncReadIntoBuffer: (void *)buffer
exactLength: (size_t)length
target: (id)target
selector: (SEL)selector
context: (nullable id)context;
|
︙ | | |
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
|
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
|
-
+
-
-
+
+
|
* @param target The target on which to call the selector when the data has
* been received. If the method returns true, it will be called
* again when the next line has been received. If you want the
* next method in the queue to handle the next line, you need to
* return false from the method
* @param selector The selector to call on the target. The signature must be
* `bool (OFStream *stream, OFString *line, id context,
* OFException *exception)`.
* id exception)`.
*/
- (void)asyncReadLineWithTarget: (id)target
selector: (SEL)selector
context: (nullable id)context;
/*!
* @brief Asynchronously reads with the specified encoding until a newline,
* `\0`, end of stream or an exception occurs.
*
* @note The stream must implement @ref fileDescriptorForReading and return a
* valid file descriptor in order for this to work!
*
* @param encoding The encoding used by the stream
* @param target The target on which to call the selector when the data has
* been received. If the method returns true, it will be called
* again when the next line has been received. If you want the
* next method in the queue to handle the next line, you need to
* return false from the method
* @param selector The selector to call on the target. The signature must be
* `bool (OFStream *stream, OFString *line,
* id context, OFException *exception)`.
* `bool (OFStream *stream, OFString *line, id context,
* id exception)`.
*/
- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
target: (id)target
selector: (SEL)selector
context: (nullable id)context;
# ifdef OF_HAVE_BLOCKS
|
︙ | | |
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
|
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
|
-
+
|
* @brief Writes everything in the write buffer to the stream.
*/
- (void)flushWriteBuffer;
/*!
* @brief Writes from a buffer into the stream.
*
* @param buffer The buffer from which the data is written to the stream
* @param buffer The buffer from which the data is written into the stream
* @param length The length of the data that should be written
*/
- (void)writeBuffer: (const void *)buffer
length: (size_t)length;
/*!
* @brief Writes a uint8_t into the stream.
|
︙ | | |
︙ | | |
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
|
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
|
-
+
-
+
|
* @brief A block which is called when the socket connected.
*
* @param socket The socket which connected
* @param exception An exception which occurred while connecting the socket or
* `nil` on success
*/
typedef void (^of_tcp_socket_async_connect_block_t)(OFTCPSocket *socket,
OFException *_Nullable exception);
id _Nullable exception);
/*!
* @brief A block 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 block should be used for the next incoming
* connection
*/
typedef bool (^of_tcp_socket_async_accept_block_t)(OFTCPSocket *socket,
OFTCPSocket *acceptedSocket, OFException *_Nullable exception);
OFTCPSocket *acceptedSocket, id _Nullable exception);
#endif
/*!
* @class OFTCPSocket OFTCPSocket.h ObjFW/OFTCPSocket.h
*
* @brief A class which provides methods to create and use TCP sockets.
*
|
︙ | | |
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
-
+
-
|
* @brief Asynchronously connect the OFTCPSocket to the specified destination.
*
* @param host The host to connect to
* @param port The port on the host to connect to
* @param target The target on which to call the selector once the connection
* has been established
* @param selector The selector to call on the target. The signature must be
* `void (OFTCPSocket *socket, id context,
* `void (OFTCPSocket *socket, id context, id exception)`.
* OFException *exception)`.
*/
- (void)asyncConnectToHost: (OFString *)host
port: (uint16_t)port
target: (id)target
selector: (SEL)selector
context: (nullable id)context;
|
︙ | | |
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
-
+
|
*
* @param target The target on which to execute the selector when a new
* connection has been accepted. The method returns whether the
* next incoming connection should be accepted by the specified
* block as well.
* @param selector The selector to call on the target. The signature must be
* `bool (OFTCPSocket *socket, OFTCPSocket *acceptedSocket,
* id context, OFException *exception)`.
* id context, id exception)`.
*/
- (void)asyncAcceptWithTarget: (id)target
selector: (SEL)selector
context: (nullable id)context;
#ifdef OF_HAVE_BLOCKS
/*!
|
︙ | | |
︙ | | |
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
-
+
|
uint16_t _port;
id _target;
SEL _selector;
id _context;
# ifdef OF_HAVE_BLOCKS
of_tcp_socket_async_connect_block_t _block;
# endif
OFException *_exception;
id _exception;
}
- initWithSourceThread: (OFThread *)sourceThread
socket: (OFTCPSocket *)socket
host: (OFString *)host
port: (uint16_t)port
target: (id)target
|
︙ | | |
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
-
-
+
+
-
+
|
[self join];
# ifdef OF_HAVE_BLOCKS
if (_block != NULL)
_block(_socket, _exception);
else {
# endif
void (*func)(id, SEL, OFTCPSocket *, id, OFException *) =
(void (*)(id, SEL, OFTCPSocket *, id, OFException *))
void (*func)(id, SEL, OFTCPSocket *, id, id) =
(void (*)(id, SEL, OFTCPSocket *, id, id))
[_target methodForSelector: _selector];
func(_target, _selector, _socket, _context, _exception);
# ifdef OF_HAVE_BLOCKS
}
# endif
}
- (id)main
{
void *pool = objc_autoreleasePoolPush();
@try {
[_socket connectToHost: _host
port: _port];
} @catch (OFException *e) {
} @catch (id e) {
_exception = [e retain];
}
[self performSelector: @selector(didConnect)
onThread: _sourceThread
waitUntilDone: false];
|
︙ | | |
︙ | | |
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
-
|
#import "socket.h"
OF_ASSUME_NONNULL_BEGIN
/*! @file */
@class OFUDPSocket;
@class OFException;
/*!
* @struct of_udp_socket_address_t OFUDPSocket.h ObjFW/OFUDPSocket.h
*
* @brief A struct which represents a host / port pair for a UDP socket.
*/
typedef struct {
|
︙ | | |
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
|
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
|
-
+
-
-
+
|
* @param host The host that has been resolved
* @param port The port of the host / port pair
* @param address The address of the resolved host / port pair
* @param exception An exception which occurred while resolving or `nil` on
* success
*/
typedef void (^of_udp_socket_async_resolve_block_t)(OFString *host,
uint16_t port, of_udp_socket_address_t address,
uint16_t port, of_udp_socket_address_t address, id _Nullable exception);
OFException *_Nullable exception);
/*!
* @brief A block which is called when a packet has been received.
*
* @param socket The UDP which received a packet
* @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_udp_socket_address_t sender,
OFException *_Nullable exception);
id _Nullable exception);
#endif
/*!
* @class OFUDPSocket OFUDPSocket.h ObjFW/OFUDPSocket.h
*
* @brief A class which provides methods to create and use UDP sockets.
*
|
︙ | | |
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
-
+
-
|
*
* @param host The host to resolve
* @param port The port for the resulting address
* @param target The target on which to call the selector once the host has been
* resolved
* @param selector The selector to call on the target. The signature must be
* `void (OFString *host, uint16_t port,
* of_udp_socket_address_t address, id context,
* of_udp_socket_address_t address, id context, id exception)`.
* OFException *exception)`.
*/
+ (void)asyncResolveAddressForHost: (OFString *)host
port: (uint16_t)port
target: (id)target
selector: (SEL)selector
context: (nullable id)context;
|
︙ | | |
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
-
+
-
|
* datagram has been received. If the method returns true, it
* will be called again with the same buffer and maximum length
* when more datagrams have been received. If you want the next
* method in the queue to handle the datagram received next, you
* need to return false from the method.
* @param selector The selector to call on the target. The signature must be
* `bool (OFUDPSocket *socket, void *buffer, size_t length,
* of_udp_socket_address_t, id context,
* of_udp_socket_address_t, id context, id exception)`.
* OFException *exception)`.
*/
- (void)asyncReceiveIntoBuffer: (void *)buffer
length: (size_t)length
target: (id)target
selector: (SEL)selector
context: (nullable id)context;
|
︙ | | |
︙ | | |
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
-
+
|
id _target;
SEL _selector;
id _context;
# ifdef OF_HAVE_BLOCKS
of_udp_socket_async_resolve_block_t _block;
# endif
of_udp_socket_address_t _address;
OFException *_exception;
id _exception;
}
- initWithSourceThread: (OFThread *)sourceThread
host: (OFString *)host
port: (uint16_t)port
target: (id)target
selector: (SEL)selector
|
︙ | | |
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
-
+
-
+
-
+
|
# ifdef OF_HAVE_BLOCKS
if (_block != NULL)
_block(_host, _port, _address, _exception);
else {
# endif
void (*func)(id, SEL, OFString *, uint16_t,
of_udp_socket_address_t, id, OFException *) =
of_udp_socket_address_t, id, id) =
(void (*)(id, SEL, OFString *, uint16_t,
of_udp_socket_address_t, id, OFException *))
of_udp_socket_address_t, id, id))
[_target methodForSelector: _selector];
func(_target, _selector, _host, _port, _address, _context,
_exception);
# ifdef OF_HAVE_BLOCKS
}
# endif
}
- (id)main
{
void *pool = objc_autoreleasePoolPush();
@try {
[OFUDPSocket resolveAddressForHost: _host
port: _port
address: &_address];
} @catch (OFException *e) {
} @catch (id e) {
_exception = e;
}
[self performSelector: @selector(didResolve)
onThread: _sourceThread
waitUntilDone: false];
|
︙ | | |