ObjFW  Diff

Differences From Artifact [63e1f39b43]:

To Artifact [8b23b2fea4]:


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
15
16
17
18
19
20
21



22
23
24
25
26
27
28







-
-
-








#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"

68
69
70
71
72
73
74
75
76

77
78
79
80
81
82
83

84
85
86
87
88
89
90
65
66
67
68
69
70
71


72





73

74
75
76
77
78
79
80
81







-
-
+
-
-
-
-
-

-
+







{
	if (_exception == nil)
		[_socket setCanBlock: true];

#ifdef OF_HAVE_BLOCKS
	if (_block != NULL) {
		if ([_socket isKindOfClass: [OFTCPSocket class]])
			((of_tcp_socket_async_connect_block_t)_block)(
			    _exception);
			((OFTCPSocketAsyncConnectBlock)_block)(_exception);
# ifdef OF_HAVE_SCTP
		else if ([_socket isKindOfClass: [OFSCTPSocket class]])
			((of_sctp_socket_async_connect_block_t)_block)(
			    _exception);
# endif
		else
			OF_ENSURE(0);
			OFEnsure(0);
	} else {
#endif
		if ([_delegate respondsToSelector:
		    @selector(socket:didConnectToHost:port:exception:)])
			[_delegate socket: _socket
			    didConnectToHost: _host
					port: _port
137
138
139
140
141
142
143
144

145
146

147
148
149
150

151
152
153
154
155
156
157
128
129
130
131
132
133
134

135
136

137
138
139
140

141
142
143
144
145
146
147
148







-
+

-
+



-
+







{
	return [OFConnectionFailedException exceptionWithHost: _host
							 port: _port
						       socket: _socket
							errNo: errNo];
}

- (void)tryNextAddressWithRunLoopMode: (of_run_loop_mode_t)runLoopMode
- (void)tryNextAddressWithRunLoopMode: (OFRunLoopMode)runLoopMode
{
	of_socket_address_t address = *(const of_socket_address_t *)
	OFSocketAddress address = *(const OFSocketAddress *)
	    [_socketAddresses itemAtIndex: _socketAddressesIndex++];
	int errNo;

	of_socket_address_set_port(&address, _port);
	OFSocketAddressSetPort(&address, _port);

	if (![_socket of_createSocketForAddress: &address errNo: &errNo]) {
		if (_socketAddressesIndex >= _socketAddresses.count) {
			_exception = [[OFConnectionFailedException alloc]
			    initWithHost: _host
				    port: _port
				  socket: _socket
228
229
230
231
232
233
234
235

236
237
238
239

240
241
242
243
244
245
246
247
248
249
250
251
252
253

254
255
256
257
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







-
+


-
-
+













-
+





	_socketAddresses = [addresses copy];

	[self tryNextAddressWithRunLoopMode:
	    [OFRunLoop currentRunLoop].currentMode];
}

- (void)startWithRunLoopMode: (of_run_loop_mode_t)runLoopMode
- (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode
{
	@try {
		of_socket_address_t address =
		    of_socket_address_parse_ip(_host, _port);
		OFSocketAddress address = OFSocketAddressParseIP(_host, _port);

		_socketAddresses = [[OFData alloc]
		    initWithItems: &address
			    count: 1
			 itemSize: sizeof(address)];

		[self tryNextAddressWithRunLoopMode: runLoopMode];
		return;
	} @catch (OFInvalidFormatException *e) {
	}

	[[OFThread DNSResolver]
	    asyncResolveAddressesForHost: _host
			   addressFamily: OF_SOCKET_ADDRESS_FAMILY_ANY
			   addressFamily: OFSocketAddressFamilyAny
			     runLoopMode: runLoopMode
				delegate: self];
}
@end