13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
* file.
*/
#include "config.h"
#include <errno.h>
#import "OFIPSocketAsyncConnector.h"
#import "OFData.h"
#ifdef OF_HAVE_SCTP
# import "OFSCTPSocket.h"
#endif
#import "OFTCPSocket.h"
#import "OFThread.h"
#import "OFTimer.h"
#import "OFConnectionFailedException.h"
#import "OFInvalidFormatException.h"
@implementation OFIPSocketAsyncConnector
- (instancetype)initWithSocket: (id)sock
host: (OFString *)host
port: (uint16_t)port
delegate: (id)delegate
block: (id)block
{
self = [super init];
|
|
|
|
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
* file.
*/
#include "config.h"
#include <errno.h>
#import "OFAsyncIPSocketConnector.h"
#import "OFData.h"
#ifdef OF_HAVE_SCTP
# import "OFSCTPSocket.h"
#endif
#import "OFTCPSocket.h"
#import "OFThread.h"
#import "OFTimer.h"
#import "OFConnectIPSocketFailedException.h"
#import "OFInvalidFormatException.h"
@implementation OFAsyncIPSocketConnector
- (instancetype)initWithSocket: (id)sock
host: (OFString *)host
port: (uint16_t)port
delegate: (id)delegate
block: (id)block
{
self = [super init];
|
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
}
[self didConnect];
}
- (id)of_connectionFailedExceptionForErrNo: (int)errNo
{
return [OFConnectionFailedException exceptionWithHost: _host
port: _port
socket: _socket
errNo: errNo];
}
- (void)tryNextAddressWithRunLoopMode: (OFRunLoopMode)runLoopMode
{
OFSocketAddress address = *(const OFSocketAddress *)
[_socketAddresses itemAtIndex: _socketAddressesIndex++];
int errNo;
OFSocketAddressSetPort(&address, _port);
if (![_socket of_createSocketForAddress: &address errNo: &errNo]) {
if (_socketAddressesIndex >= _socketAddresses.count) {
_exception = [[OFConnectionFailedException alloc]
initWithHost: _host
port: _port
socket: _socket
errNo: errNo];
[self didConnect];
return;
}
|
|
|
|
|
|
|
|
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
}
[self didConnect];
}
- (id)of_connectionFailedExceptionForErrNo: (int)errNo
{
return [OFConnectIPSocketFailedException exceptionWithHost: _host
port: _port
socket: _socket
errNo: errNo];
}
- (void)tryNextAddressWithRunLoopMode: (OFRunLoopMode)runLoopMode
{
OFSocketAddress address = *(const OFSocketAddress *)
[_socketAddresses itemAtIndex: _socketAddressesIndex++];
int errNo;
OFSocketAddressSetIPPort(&address, _port);
if (![_socket of_createSocketForAddress: &address errNo: &errNo]) {
if (_socketAddressesIndex >= _socketAddresses.count) {
_exception = [[OFConnectIPSocketFailedException alloc]
initWithHost: _host
port: _port
socket: _socket
errNo: errNo];
[self didConnect];
return;
}
|
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
delegate: self];
return;
} else {
#endif
[_socket of_closeSocket];
if (_socketAddressesIndex >= _socketAddresses.count) {
_exception = [[OFConnectionFailedException
alloc] initWithHost: _host
port: _port
socket: _socket
errNo: errNo];
[self didConnect];
return;
}
|
|
|
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
delegate: self];
return;
} else {
#endif
[_socket of_closeSocket];
if (_socketAddressesIndex >= _socketAddresses.count) {
_exception = [[OFConnectIPSocketFailedException
alloc] initWithHost: _host
port: _port
socket: _socket
errNo: errNo];
[self didConnect];
return;
}
|