ObjFW  Diff

Differences From Artifact [4199e0da2a]:

To Artifact [4800955ec9]:

  • File src/OFTCPSocket.m — part of check-in [ffb91daffe] at 2013-06-11 23:33:16 on branch trunk — Initial sockets support for the Wii.

    Not functional yet due to bugs in the SDK.
    Bugs found so far:

    * Binding to port 0 fails instead of choosing a free port.
    * gethostbyname() does not work for IPs.
    * getsockname() is missing.
    * struct sockaddr_storage is missing.

    I have not decided yet whether I fix those bugs in the SDK (I already
    implemented getsockname() and added struct sockaddr_stroage and it seems
    to work) or if I work around them in ObjFW. This will mainly depend on
    how cooperative the developers of the Wii SDK are. (user: js, size: 17114) [annotate] [blame] [check-ins using]


81
82
83
84
85
86
87













88
89
90
91
92
93
94

static OFMutex *mutex = nil;
#endif

#ifdef _WIN32
# define close(sock) closesocket(sock)
#endif














/* References for static linking */
void _references_to_categories_of_OFTCPSocket(void)
{
	_OFTCPSocket_SOCKS5_reference = 1;
}








>
>
>
>
>
>
>
>
>
>
>
>
>







81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

static OFMutex *mutex = nil;
#endif

#ifdef _WIN32
# define close(sock) closesocket(sock)
#endif

#ifdef __wii__
# define accept(sock, addr, addrlen) net_accept(sock, addr, addrlen)
# define bind(sock, addr, addrlen) net_bind(sock, addr, addrlen)
# define close(sock) net_close(sock)
# define connect(sock, addr, addrlen) net_connect(sock, addr, addrlen)
# define gethostbyname(name) net_gethostbyname(name)
# define getsockname(sock, addr, addrlen) net_getsockname(sock, addr, addrlen)
# define listen(sock, backlog) net_listen(sock, backlog)
# define setsockopt(sock, level, name, value, len) \
	net_setsockopt(sock, level, name, value, len)
# define socket(domain, type, proto) net_socket(domain, type, proto)
#endif

/* References for static linking */
void _references_to_categories_of_OFTCPSocket(void)
{
	_OFTCPSocket_SOCKS5_reference = 1;
}

487
488
489
490
491
492
493

494

495
496
497
498
499
500
501
- (uint16_t)bindToHost: (OFString*)host
		  port: (uint16_t)port
{
	const int one = 1;
	union {
		struct sockaddr_storage storage;
		struct sockaddr_in in;

		struct sockaddr_in6 in6;

	} addr;
	socklen_t addrLen;

	if (_socket != INVALID_SOCKET)
		@throw [OFAlreadyConnectedException
		    exceptionWithClass: [self class]
				socket: self];







>

>







500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
- (uint16_t)bindToHost: (OFString*)host
		  port: (uint16_t)port
{
	const int one = 1;
	union {
		struct sockaddr_storage storage;
		struct sockaddr_in in;
#ifdef AF_INET6
		struct sockaddr_in6 in6;
#endif
	} addr;
	socklen_t addrLen;

	if (_socket != INVALID_SOCKET)
		@throw [OFAlreadyConnectedException
		    exceptionWithClass: [self class]
				socket: self];
616
617
618
619
620
621
622

623
624

625
626
627
628
629
630
631
							  socket: self
							    host: host
							    port: port];
	}

	if (addr.storage.ss_family == AF_INET)
		return OF_BSWAP16_IF_LE(addr.in.sin_port);

	if (addr.storage.ss_family == AF_INET6)
		return OF_BSWAP16_IF_LE(addr.in6.sin6_port);


	close(_socket);
	_socket = INVALID_SOCKET;
	@throw [OFBindFailedException exceptionWithClass: [self class]
						  socket: self
						    host: host
						    port: port];







>


>







631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
							  socket: self
							    host: host
							    port: port];
	}

	if (addr.storage.ss_family == AF_INET)
		return OF_BSWAP16_IF_LE(addr.in.sin_port);
#ifdef AF_INET6
	if (addr.storage.ss_family == AF_INET6)
		return OF_BSWAP16_IF_LE(addr.in6.sin6_port);
#endif

	close(_socket);
	_socket = INVALID_SOCKET;
	@throw [OFBindFailedException exceptionWithClass: [self class]
						  socket: self
						    host: host
						    port: port];