ObjFW  Diff

Differences From Artifact [3c90c2bfad]:

To Artifact [b7f838da94]:


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"

#import "socket.h"
#import "socket_helpers.h"
#import "resolver.h"

#ifdef __wii__
static uint16_t freePort = 65532;
#endif

#ifdef OF_HAVE_THREADS
@interface OFUDPSocket_ResolveThread: OFThread
{
	OFThread *_sourceThread;
	OFString *_host;
	uint16_t _port;
	id _target;







<
<
<
<







37
38
39
40
41
42
43




44
45
46
47
48
49
50
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"

#import "socket.h"
#import "socket_helpers.h"
#import "resolver.h"





#ifdef OF_HAVE_THREADS
@interface OFUDPSocket_ResolveThread: OFThread
{
	OFThread *_sourceThread;
	OFString *_host;
	uint16_t _port;
	id _target;
399
400
401
402
403
404
405



406


407
408

409







410
411
412
413
414
415
416
# endif
	} addr;
	socklen_t addrLen;
#endif

#ifdef __wii__
	if (port == 0)



		port = freePort--;


#endif


	results = of_resolve_host(host, port, SOCK_DGRAM);







	@try {
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
		int flags;
#endif

		if ((_socket = socket(results[0]->family,
		    results[0]->type | SOCK_CLOEXEC,







>
>
>
|
>
>


>
|
>
>
>
>
>
>
>







395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# endif
	} addr;
	socklen_t addrLen;
#endif

#ifdef __wii__
	if (port == 0)
		port = of_socket_port_find(SOCK_DGRAM);
	else if (!of_socket_port_register(port, SOCK_DGRAM))
		@throw [OFBindFailedException exceptionWithHost: host
							   port: port
							 socket: self
							  errNo: EADDRINUSE];
#endif

	@try {
		results = of_resolve_host(host, port, SOCK_DGRAM);
	} @catch (id e) {
#ifdef __wii__
		of_socket_port_free(port, SOCK_DGRAM);
#endif
		@throw e;
	}

	@try {
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
		int flags;
#endif

		if ((_socket = socket(results[0]->family,
		    results[0]->type | SOCK_CLOEXEC,
434
435
436
437
438
439
440





441
442
443
444
445



446

447
448
449
450
451
452
453
			_socket = INVALID_SOCKET;

			@throw [OFBindFailedException exceptionWithHost: host
								   port: port
								 socket: self
								  errNo: errNo];
		}





	} @finally {
		of_resolver_free(results);
	}

	if (port > 0)



		return port;


#ifndef __wii__
	addrLen = (socklen_t)sizeof(addr.storage);
	if (of_getsockname(_socket, (struct sockaddr*)&addr.storage,
	    &addrLen) != 0) {
		int errNo = of_socket_errno();








>
>
>
>
>




|
>
>
>

>







443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
			_socket = INVALID_SOCKET;

			@throw [OFBindFailedException exceptionWithHost: host
								   port: port
								 socket: self
								  errNo: errNo];
		}
	} @catch (id e) {
#ifdef __wii__
		of_socket_port_free(port, SOCK_DGRAM);
#endif
		@throw e;
	} @finally {
		of_resolver_free(results);
	}

	if (port > 0) {
#ifdef __wii__
		_port = port;
#endif
		return port;
	}

#ifndef __wii__
	addrLen = (socklen_t)sizeof(addr.storage);
	if (of_getsockname(_socket, (struct sockaddr*)&addr.storage,
	    &addrLen) != 0) {
		int errNo = of_socket_errno();

603
604
605
606
607
608
609
610







611
- (void)close
{
	if (_socket == INVALID_SOCKET)
		@throw [OFNotOpenException exceptionWithObject: self];

	close(_socket);
	_socket = INVALID_SOCKET;
}







@end







|
>
>
>
>
>
>
>

621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
- (void)close
{
	if (_socket == INVALID_SOCKET)
		@throw [OFNotOpenException exceptionWithObject: self];

	close(_socket);
	_socket = INVALID_SOCKET;

#ifdef __wii__
	if (_port > 0) {
		of_socket_port_free(_port, SOCK_DGRAM);
		_port = 0;
	}
#endif
}
@end