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
|
<OFRunLoopConnectDelegate>
{
OFSPXStreamSocket *_socket;
uint32_t _network;
unsigned char _node[IPX_NODE_LEN];
uint16_t _port;
#ifdef OF_HAVE_BLOCKS
OFSPXStreamSocketAsyncConnectBlock _block;
#endif
}
- (instancetype)initWithSocket: (OFSPXStreamSocket *)socket
network: (uint32_t)network
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
#ifdef OF_HAVE_BLOCKS
block: (OFSPXStreamSocketAsyncConnectBlock)block
#endif
;
- (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode;
@end
@implementation OFSPXStreamSocketAsyncConnectDelegate
- (instancetype)initWithSocket: (OFSPXStreamSocket *)sock
network: (uint32_t)network
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
#ifdef OF_HAVE_BLOCKS
block: (OFSPXStreamSocketAsyncConnectBlock)block
#endif
{
self = [super init];
@try {
_socket = [sock retain];
_network = network;
memcpy(_node, node, IPX_NODE_LEN);
_port = port;
#ifdef OF_HAVE_BLOCKS
_block = [block copy];
#endif
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_socket release];
#ifdef OF_HAVE_BLOCKS
[_block release];
#endif
[super dealloc];
}
- (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode
{
|
|
|
|
|
|
|
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
|
<OFRunLoopConnectDelegate>
{
OFSPXStreamSocket *_socket;
uint32_t _network;
unsigned char _node[IPX_NODE_LEN];
uint16_t _port;
#ifdef OF_HAVE_BLOCKS
OFSPXStreamSocketConnectedHandler _handler;
#endif
}
- (instancetype)initWithSocket: (OFSPXStreamSocket *)socket
network: (uint32_t)network
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
#ifdef OF_HAVE_BLOCKS
handler: (OFSPXStreamSocketConnectedHandler)handler
#endif
;
- (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode;
@end
@implementation OFSPXStreamSocketAsyncConnectDelegate
- (instancetype)initWithSocket: (OFSPXStreamSocket *)sock
network: (uint32_t)network
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
#ifdef OF_HAVE_BLOCKS
handler: (OFSPXStreamSocketConnectedHandler)handler
#endif
{
self = [super init];
@try {
_socket = [sock retain];
_network = network;
memcpy(_node, node, IPX_NODE_LEN);
_port = port;
#ifdef OF_HAVE_BLOCKS
_handler = [handler copy];
#endif
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_socket release];
#ifdef OF_HAVE_BLOCKS
[_handler release];
#endif
[super dealloc];
}
- (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode
{
|
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
id <OFSPXStreamSocketDelegate> delegate =
((OFSPXStreamSocket *)sock).delegate;
if (exception == nil)
((OFSPXStreamSocket *)sock).canBlock = true;
#ifdef OF_HAVE_BLOCKS
if (_block != NULL)
_block(exception);
else {
#endif
if ([delegate respondsToSelector:
@selector(socket:didConnectToNetwork:node:port:exception:)])
[delegate socket: _socket
didConnectToNetwork: _network
node: _node
|
|
|
|
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
id <OFSPXStreamSocketDelegate> delegate =
((OFSPXStreamSocket *)sock).delegate;
if (exception == nil)
((OFSPXStreamSocket *)sock).canBlock = true;
#ifdef OF_HAVE_BLOCKS
if (_handler != NULL)
_handler(_socket, _network, _node, _port, exception);
else {
#endif
if ([delegate respondsToSelector:
@selector(socket:didConnectToNetwork:node:port:exception:)])
[delegate socket: _socket
didConnectToNetwork: _network
node: _node
|
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
|
[[[[OFSPXStreamSocketAsyncConnectDelegate alloc]
initWithSocket: self
network: network
node: node
port: port
#ifdef OF_HAVE_BLOCKS
block: NULL
#endif
] autorelease] startWithRunLoopMode: runLoopMode];
objc_autoreleasePoolPop(pool);
}
#ifdef OF_HAVE_BLOCKS
- (void)asyncConnectToNetwork: (uint32_t)network
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
block: (OFSPXStreamSocketAsyncConnectBlock)block
{
[self asyncConnectToNetwork: network
node: node
port: port
runLoopMode: OFDefaultRunLoopMode
block: block];
}
- (void)asyncConnectToNetwork: (uint32_t)network
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
runLoopMode: (OFRunLoopMode)runLoopMode
block: (OFSPXStreamSocketAsyncConnectBlock)block
{
void *pool = objc_autoreleasePoolPush();
[[[[OFSPXStreamSocketAsyncConnectDelegate alloc]
initWithSocket: self
network: network
node: node
port: port
block: block
] autorelease] startWithRunLoopMode: runLoopMode];
objc_autoreleasePoolPop(pool);
}
#endif
- (OFSocketAddress)bindToNetwork: (uint32_t)network
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
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
|
[[[[OFSPXStreamSocketAsyncConnectDelegate alloc]
initWithSocket: self
network: network
node: node
port: port
#ifdef OF_HAVE_BLOCKS
handler: NULL
#endif
] autorelease] startWithRunLoopMode: runLoopMode];
objc_autoreleasePoolPop(pool);
}
#ifdef OF_HAVE_BLOCKS
- (void)asyncConnectToNetwork: (uint32_t)network
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
block: (OFSPXStreamSocketAsyncConnectBlock)block
{
OFSPXStreamSocketConnectedHandler handler = ^ (
OFSPXStreamSocket *socket, uint32_t network_,
const unsigned char node_[IPX_NODE_LEN], uint16_t port_,
id exception) {
block(exception);
};
[self asyncConnectToNetwork: network
node: node
port: port
runLoopMode: OFDefaultRunLoopMode
handler: handler];
}
- (void)asyncConnectToNetwork: (uint32_t)network
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
handler: (OFSPXStreamSocketConnectedHandler)handler
{
[self asyncConnectToNetwork: network
node: node
port: port
runLoopMode: OFDefaultRunLoopMode
handler: handler];
}
- (void)asyncConnectToNetwork: (uint32_t)network
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
runLoopMode: (OFRunLoopMode)runLoopMode
block: (OFSPXStreamSocketAsyncConnectBlock)block
{
OFSPXStreamSocketConnectedHandler handler = ^ (
OFSPXStreamSocket *socket, uint32_t network_,
const unsigned char node_[IPX_NODE_LEN], uint16_t port_,
id exception) {
block(exception);
};
[self asyncConnectToNetwork: network
node: node
port: port
runLoopMode: runLoopMode
handler: handler];
}
- (void)asyncConnectToNetwork: (uint32_t)network
node: (const unsigned char [IPX_NODE_LEN])node
port: (uint16_t)port
runLoopMode: (OFRunLoopMode)runLoopMode
handler: (OFSPXStreamSocketConnectedHandler)handler
{
void *pool = objc_autoreleasePoolPush();
[[[[OFSPXStreamSocketAsyncConnectDelegate alloc]
initWithSocket: self
network: network
node: node
port: port
handler: handler
] autorelease] startWithRunLoopMode: runLoopMode];
objc_autoreleasePoolPop(pool);
}
#endif
- (OFSocketAddress)bindToNetwork: (uint32_t)network
|