ObjFW  Diff

Differences From Artifact [a2237d54c6]:

To Artifact [09c7bbbcdf]:


1
2
3
4

5
6
7
8
9
10
11
1



2
3
4
5
6
7
8
9

-
-
-
+







/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019, 2020
 *   Jonathan Schleifer <js@nil.im>
 * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
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
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87
88

89

90
91
92
93
94
95
96







-
+








-
+
-







			    _exception);
		else
			OF_ENSURE(0);
	} else {
#endif
		if ([_delegate respondsToSelector:
		    @selector(socket:didConnectToHost:port:exception:)])
			[_delegate    socket: _socket
			[_delegate socket: _socket
			    didConnectToHost: _host
					port: _port
				   exception: _exception];
#ifdef OF_HAVE_BLOCKS
	}
#endif
}

- (void)of_socketDidConnect: (id)sock
- (void)of_socketDidConnect: (id)sock exception: (id)exception
		  exception: (id)exception
{
	if (exception != nil) {
		/*
		 * self might be retained only by the pending async requests,
		 * which we're about to cancel.
		 */
		[[self retain] autorelease];
115
116
117
118
119
120
121
122

123
124
125
126
127
128
129
130
112
113
114
115
116
117
118

119

120
121
122
123
124
125
126







-
+
-







			    @selector(tryNextAddressWithRunLoopMode:);
			OFTimer *timer = [OFTimer
			    timerWithTimeInterval: 0
					   target: self
					 selector: selector
					   object: runLoop.currentMode
					  repeats: false];
			[runLoop addTimer: timer
			[runLoop addTimer: timer forMode: runLoop.currentMode];
				  forMode: runLoop.currentMode];
		}

		return;
	}

	[self didConnect];
}
141
142
143
144
145
146
147
148

149
150
151
152
153
154
155
156
137
138
139
140
141
142
143

144

145
146
147
148
149
150
151







-
+
-







{
	of_socket_address_t address = *(const of_socket_address_t *)
	    [_socketAddresses itemAtIndex: _socketAddressesIndex++];
	int errNo;

	of_socket_address_set_port(&address, _port);

	if (![_socket of_createSocketForAddress: &address
	if (![_socket of_createSocketForAddress: &address errNo: &errNo]) {
					  errNo: &errNo]) {
		if (_socketAddressesIndex >= _socketAddresses.count) {
			_exception = [[OFConnectionFailedException alloc]
			    initWithHost: _host
				    port: _port
				  socket: _socket
				   errNo: errNo];
			[self didConnect];
173
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188
168
169
170
171
172
173
174

175

176
177
178
179
180
181
182







-
+
-







	 * FIXME: Use a different thread as a work around.
	 */
	[_socket setCanBlock: true];
#else
	[_socket setCanBlock: false];
#endif

	if (![_socket of_connectSocketToAddress: &address
	if (![_socket of_connectSocketToAddress: &address errNo: &errNo]) {
					  errNo: &errNo]) {
#if !defined(OF_NINTENDO_3DS) && !defined(OF_WII)
		if (errNo == EINPROGRESS) {
			[OFRunLoop of_addAsyncConnectForSocket: _socket
							  mode: runLoopMode
						      delegate: self];
			return;
		} else {