ObjFW  Diff

Differences From Artifact [94deb56f45]:

To Artifact [8771225ab8]:


197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
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
248
249
250
251
252
253
		@throw [OFConnectionFailedException newWithClass: isa
							    node: node
							 service: service];
}

- (void)bindService: (OFString*)service
	     onNode: (OFString*)node
	 withFamily: (int)family
{
	if (sock != INVALID_SOCKET)
		@throw [OFAlreadyConnectedException newWithClass: isa];

#ifndef HAVE_THREADSAFE_GETADDRINFO
	if (family != AF_INET)
		@throw [OFBindFailedException newWithClass: isa
						      node: node
						   service: service
						    family: family];
#endif

	if ((sock = socket(family, SOCK_STREAM, 0)) == INVALID_SOCKET)
		@throw [OFBindFailedException newWithClass: isa
						      node: node
						   service: service
						    family: family];

#ifdef HAVE_THREADSAFE_GETADDRINFO
	struct addrinfo hints, *res;

	memset(&hints, 0, sizeof(struct addrinfo));
	hints.ai_family = family;
	hints.ai_socktype = SOCK_STREAM;

	if (getaddrinfo([node cString], [service cString], &hints, &res)) {
		close(sock);
		sock = INVALID_SOCKET;
		@throw [OFAddressTranslationFailedException
		    newWithClass: isa
			    node: node
			 service: service];
	}





	if (bind(sock, res->ai_addr, res->ai_addrlen) == -1) {
		freeaddrinfo(res);
		close(sock);
		sock = INVALID_SOCKET;
		@throw [OFBindFailedException newWithClass: isa
						      node: node
						   service: service
						    family: family];
	}

	freeaddrinfo(res);
#else
	struct hostent *he;
	struct servent *se;
	struct sockaddr_in addr;







<




<
<
<
<
<
<
<
<
<
<
<
<
<
<




|


|
<
<




|
>
>
>
>







|
<







197
198
199
200
201
202
203

204
205
206
207














208
209
210
211
212
213
214
215


216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

233
234
235
236
237
238
239
		@throw [OFConnectionFailedException newWithClass: isa
							    node: node
							 service: service];
}

- (void)bindService: (OFString*)service
	     onNode: (OFString*)node

{
	if (sock != INVALID_SOCKET)
		@throw [OFAlreadyConnectedException newWithClass: isa];















#ifdef HAVE_THREADSAFE_GETADDRINFO
	struct addrinfo hints, *res;

	memset(&hints, 0, sizeof(struct addrinfo));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;

	if (getaddrinfo([node cString], [service cString], &hints, &res))


		@throw [OFAddressTranslationFailedException
		    newWithClass: isa
			    node: node
			 service: service];

	if ((sock = socket(res->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET)
		@throw [OFBindFailedException newWithClass: isa
						      node: node
						   service: service];

	if (bind(sock, res->ai_addr, res->ai_addrlen) == -1) {
		freeaddrinfo(res);
		close(sock);
		sock = INVALID_SOCKET;
		@throw [OFBindFailedException newWithClass: isa
						      node: node
						   service: service];

	}

	freeaddrinfo(res);
#else
	struct hostent *he;
	struct servent *se;
	struct sockaddr_in addr;
270
271
272
273
274
275
276
277
278
279
280
281
282
283
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
	if ((se = getservbyname([service cString], "TCP")) != NULL)
		port = se->s_port;
	else if ((port = OF_BSWAP16_IF_LE(strtol([service cString], NULL,
	    10))) == 0) {
# ifdef OF_THREADS
		[mutex unlock];
# endif
		close(sock);
		sock = INVALID_SOCKET;
		@throw [OFAddressTranslationFailedException
		    newWithClass: isa
			    node: node
			 service: service];
	}

	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = port;

	if (he->h_addrtype != AF_INET || he->h_addr_list[0] == NULL) {
# ifdef OF_THREADS
		[mutex unlock];
# endif
		close(sock);
		sock = INVALID_SOCKET;
		@throw [OFAddressTranslationFailedException
		    newWithClass: isa
			    node: node
			 service: service];
	}

	memcpy(&addr.sin_addr.s_addr, he->h_addr_list[0], he->h_length);

# ifdef OF_THREADS
	[mutex unlock];
# endif





	if (bind(sock, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
		close(sock);
		sock = INVALID_SOCKET;
		@throw [OFBindFailedException newWithClass: isa
						      node: node
						   service: service
						    family: family];
	}
#endif
}

- (void)listenWithBackLog: (int)backlog
{
	if (sock == INVALID_SOCKET)







<
<














<
<











>
>
>
>






|
<







256
257
258
259
260
261
262


263
264
265
266
267
268
269
270
271
272
273
274
275
276


277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298

299
300
301
302
303
304
305
	if ((se = getservbyname([service cString], "TCP")) != NULL)
		port = se->s_port;
	else if ((port = OF_BSWAP16_IF_LE(strtol([service cString], NULL,
	    10))) == 0) {
# ifdef OF_THREADS
		[mutex unlock];
# endif


		@throw [OFAddressTranslationFailedException
		    newWithClass: isa
			    node: node
			 service: service];
	}

	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = port;

	if (he->h_addrtype != AF_INET || he->h_addr_list[0] == NULL) {
# ifdef OF_THREADS
		[mutex unlock];
# endif


		@throw [OFAddressTranslationFailedException
		    newWithClass: isa
			    node: node
			 service: service];
	}

	memcpy(&addr.sin_addr.s_addr, he->h_addr_list[0], he->h_length);

# ifdef OF_THREADS
	[mutex unlock];
# endif
	if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
		@throw [OFBindFailedException newWithClass: isa
						      node: node
						   service: service];

	if (bind(sock, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
		close(sock);
		sock = INVALID_SOCKET;
		@throw [OFBindFailedException newWithClass: isa
						      node: node
						   service: service];

	}
#endif
}

- (void)listenWithBackLog: (int)backlog
{
	if (sock == INVALID_SOCKET)