19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#import "OFIPSocketAsyncConnector.h"
#import "OFData.h"
#import "OFTCPSocket.h"
#import "OFThread.h"
#import "OFTimer.h"
#import "OFConnectSocketFailedException.h"
#import "OFInvalidFormatException.h"
@implementation OFIPSocketAsyncConnector
- (instancetype)initWithSocket: (id)sock
host: (OFString *)host
port: (uint16_t)port
delegate: (id)delegate
|
|
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#import "OFIPSocketAsyncConnector.h"
#import "OFData.h"
#import "OFTCPSocket.h"
#import "OFThread.h"
#import "OFTimer.h"
#import "OFConnectIPSocketFailedException.h"
#import "OFInvalidFormatException.h"
@implementation OFIPSocketAsyncConnector
- (instancetype)initWithSocket: (id)sock
host: (OFString *)host
port: (uint16_t)port
delegate: (id)delegate
|
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
150
151
152
|
}
[self didConnect];
}
- (id)of_connectionFailedExceptionForErrNo: (int)errNo
{
return [OFConnectSocketFailedException 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 = [[OFConnectSocketFailedException alloc]
initWithHost: _host
port: _port
socket: _socket
errNo: errNo];
[self didConnect];
return;
}
|
|
|
|
|
|
|
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
150
151
152
|
}
[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;
OFSocketAddressSetPort(&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;
}
|
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
delegate: self];
return;
} else {
#endif
[_socket of_closeSocket];
if (_socketAddressesIndex >= _socketAddresses.count) {
_exception = [[OFConnectSocketFailedException
alloc] initWithHost: _host
port: _port
socket: _socket
errNo: errNo];
[self didConnect];
return;
}
|
|
|
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
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;
}
|