ObjFW  Diff

Differences From Artifact [2de1fb049a]:

To Artifact [3b9e3e0a34]:


381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
		if ((_socket = socket(results[0]->family, results[0]->type,
		    results[0]->protocol)) == INVALID_SOCKET)
			@throw [OFBindFailedException exceptionWithHost: host
								   port: port
								 socket: self];

		if (setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR,
		    (const char*)&one, sizeof(one)))
			@throw [OFSetOptionFailedException
			    exceptionWithStream: self];

		if (bind(_socket, results[0]->address,
		    results[0]->addressLength) == -1) {
			close(_socket);
			_socket = INVALID_SOCKET;
			@throw [OFBindFailedException exceptionWithHost: host
								   port: port
								 socket: self];
		}
	} @finally {
		of_resolver_free(results);
	}

	if (port > 0)
		return port;

#ifndef __wii__
	addrLen = sizeof(addr.storage);
	if (getsockname(_socket, (struct sockaddr*)&addr.storage, &addrLen)) {
		close(_socket);
		_socket = INVALID_SOCKET;
		@throw [OFBindFailedException exceptionWithHost: host
							   port: port
							 socket: self];
	}







|



















|







381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
		if ((_socket = socket(results[0]->family, results[0]->type,
		    results[0]->protocol)) == INVALID_SOCKET)
			@throw [OFBindFailedException exceptionWithHost: host
								   port: port
								 socket: self];

		if (setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR,
		    (const char*)&one, (socklen_t)sizeof(one)))
			@throw [OFSetOptionFailedException
			    exceptionWithStream: self];

		if (bind(_socket, results[0]->address,
		    results[0]->addressLength) == -1) {
			close(_socket);
			_socket = INVALID_SOCKET;
			@throw [OFBindFailedException exceptionWithHost: host
								   port: port
								 socket: self];
		}
	} @finally {
		of_resolver_free(results);
	}

	if (port > 0)
		return port;

#ifndef __wii__
	addrLen = (socklen_t)sizeof(addr.storage);
	if (getsockname(_socket, (struct sockaddr*)&addr.storage, &addrLen)) {
		close(_socket);
		_socket = INVALID_SOCKET;
		@throw [OFBindFailedException exceptionWithHost: host
							   port: port
							 socket: self];
	}
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462

- (instancetype)accept
{
	OFTCPSocket *client = [[[[self class] alloc] init] autorelease];

	client->_address = [client
	    allocMemoryWithSize: sizeof(struct sockaddr_storage)];
	client->_addressLength = sizeof(struct sockaddr_storage);

	if ((client->_socket = accept(_socket, client->_address,
	   &client->_addressLength)) == INVALID_SOCKET)
		@throw [OFAcceptFailedException exceptionWithSocket: self];

	assert(client->_addressLength <= sizeof(struct sockaddr_storage));








|







448
449
450
451
452
453
454
455
456
457
458
459
460
461
462

- (instancetype)accept
{
	OFTCPSocket *client = [[[[self class] alloc] init] autorelease];

	client->_address = [client
	    allocMemoryWithSize: sizeof(struct sockaddr_storage)];
	client->_addressLength = (socklen_t)sizeof(struct sockaddr_storage);

	if ((client->_socket = accept(_socket, client->_address,
	   &client->_addressLength)) == INVALID_SOCKET)
		@throw [OFAcceptFailedException exceptionWithSocket: self];

	assert(client->_addressLength <= sizeof(struct sockaddr_storage));

489
490
491
492
493
494
495
496

497
498
499
500
501
502
503
}
#endif

- (void)setKeepAlivesEnabled: (bool)enable
{
	int v = enable;

	if (setsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&v, sizeof(v)))

		@throw [OFSetOptionFailedException exceptionWithStream: self];
}

- (OFString*)remoteAddress
{
	OFString *ret;








|
>







489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
}
#endif

- (void)setKeepAlivesEnabled: (bool)enable
{
	int v = enable;

	if (setsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE,
	    (char*)&v, (socklen_t)sizeof(v)))
		@throw [OFSetOptionFailedException exceptionWithStream: self];
}

- (OFString*)remoteAddress
{
	OFString *ret;