31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# include <arpa/inet.h>
# include <netdb.h>
#endif
#import "OFTCPSocket.h"
#import "OFTCPSocket+SOCKS5.h"
#import "OFString.h"
#import "OFAcceptFailedException.h"
#import "OFAlreadyConnectedException.h"
#import "OFAddressTranslationFailedException.h"
#import "OFBindFailedException.h"
#import "OFConnectionFailedException.h"
#import "OFInvalidArgumentException.h"
|
>
>
>
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# include <arpa/inet.h>
# include <netdb.h>
#endif
#import "OFTCPSocket.h"
#import "OFTCPSocket+SOCKS5.h"
#import "OFString.h"
#import "OFThread.h"
#import "OFTimer.h"
#import "OFRunLoop.h"
#import "OFAcceptFailedException.h"
#import "OFAlreadyConnectedException.h"
#import "OFAddressTranslationFailedException.h"
#import "OFBindFailedException.h"
#import "OFConnectionFailedException.h"
#import "OFInvalidArgumentException.h"
|
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
host: host
port: port];
if (SOCKS5Host != nil)
[self _SOCKS5ConnectToHost: destinationHost
port: destinationPort];
}
- (uint16_t)bindToHost: (OFString*)host
port: (uint16_t)port
{
union {
struct sockaddr_storage storage;
struct sockaddr_in in;
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
host: host
port: port];
if (SOCKS5Host != nil)
[self _SOCKS5ConnectToHost: destinationHost
port: destinationPort];
}
#ifdef OF_HAVE_BLOCKS
- (void)asyncConnectToHost: (OFString*)host
port: (uint16_t)port
block: (of_tcpsocket_async_connect_block_t)block
{
void *pool = objc_autoreleasePoolPush();
OFRunLoop *runLoop = [OFRunLoop currentRunLoop];
[[OFThread threadWithObject: self
block: ^ (id s) {
void *pool2 = objc_autoreleasePoolPush();
OFThread *connectThread = [OFThread currentThread];
OFTimer *timer;
[s connectToHost: host
port: port];
timer = [OFTimer timerWithTimeInterval: 0
repeats: NO
block: ^ {
[connectThread join];
block(s);
}];
[runLoop addTimer: timer];
objc_autoreleasePoolPop(pool2);
return nil;
}] start];
objc_autoreleasePoolPop(pool);
}
#endif
- (uint16_t)bindToHost: (OFString*)host
port: (uint16_t)port
{
union {
struct sockaddr_storage storage;
struct sockaddr_in in;
|