ObjFW  Diff

Differences From Artifact [ec4b8afafc]:

  • File src/OFStreamObserver.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: 9186) [annotate] [blame] [check-ins using]

To Artifact [2bcf8ed1eb]:

  • File src/OFStreamObserver.m — part of check-in [ca113e0145] at 2013-06-13 02:03:13 on branch trunk — Don't bind to port 0 on the Wii.

    Instead, a decreasing variable is used now. This should be safe, as
    nothing else should be binding ports while homebrew code is running. The
    only problem that could arise is when code manually binds to very high
    port numbers.

    This also solves the problem that getsockname() is not available on the
    Wii, as we know the port now anyway.

    And while we're at it, this also adds struct sockaddr_storage. (user: js, size: 9311) [annotate] [blame] [check-ins using]


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#import "macros.h"

#ifdef __wii__
# define BOOL OGC_BOOL
# include <network.h>
# undef BOOL
# define bind(sock, addr, addrlen) net_bind(sock, addr, addrlen)
# define getsockname(sock, addr, addrlen) net_getsockname(sock, addr, addrlen)
# define sendto(sock, buf, len, flags, addr, addrlen) \
	net_sendto(sock, buf, len, flags, addr, addrlen)
# define socket(domain, type, proto) net_socket(domain, type, proto)
#endif

enum {
	QUEUE_ADD = 0,







<







58
59
60
61
62
63
64

65
66
67
68
69
70
71
#import "macros.h"

#ifdef __wii__
# define BOOL OGC_BOOL
# include <network.h>
# undef BOOL
# define bind(sock, addr, addrlen) net_bind(sock, addr, addrlen)

# define sendto(sock, buf, len, flags, addr, addrlen) \
	net_sendto(sock, buf, len, flags, addr, addrlen)
# define socket(domain, type, proto) net_socket(domain, type, proto)
#endif

enum {
	QUEUE_ADD = 0,
111
112
113
114
115
116
117

118

119
120
121
122
123
124
125
- init
{
	self = [super init];

	@try {
#ifndef OF_HAVE_PIPE
		struct sockaddr_in cancelAddr2;

		socklen_t cancelAddrLen;

#endif

		_readStreams = [[OFMutableArray alloc] init];
		_writeStreams = [[OFMutableArray alloc] init];
		_queue = [[OFMutableArray alloc] init];
		_queueInfo = [[OFDataArray alloc]
		    initWithItemSize: sizeof(int)];







>

>







110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
- init
{
	self = [super init];

	@try {
#ifndef OF_HAVE_PIPE
		struct sockaddr_in cancelAddr2;
# ifndef __wii__
		socklen_t cancelAddrLen;
# endif
#endif

		_readStreams = [[OFMutableArray alloc] init];
		_writeStreams = [[OFMutableArray alloc] init];
		_queue = [[OFMutableArray alloc] init];
		_queueInfo = [[OFDataArray alloc]
		    initWithItemSize: sizeof(int)];
141
142
143
144
145
146
147






148
149
150
151
152
153
154

155
156
157
158
159

160
161
162
163
164
165
166
			@throw [OFInitializationFailedException
			    exceptionWithClass: [self class]];

		_cancelAddr.sin_family = AF_INET;
		_cancelAddr.sin_port = 0;
		_cancelAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
		cancelAddr2 = _cancelAddr;







		if (bind(_cancelFD[0], (struct sockaddr*)&_cancelAddr,
		    sizeof(_cancelAddr)) || bind(_cancelFD[1],
		    (struct sockaddr*)&cancelAddr2, sizeof(cancelAddr2)))
			@throw [OFInitializationFailedException
			    exceptionWithClass: [self class]];


		cancelAddrLen = sizeof(_cancelAddr);
		if (getsockname(_cancelFD[0], (struct sockaddr*)&_cancelAddr,
		    &cancelAddrLen))
			@throw [OFInitializationFailedException
			    exceptionWithClass: [self class]];

#endif

		_maxFD = _cancelFD[0];
		_FDToStream = [self allocMemoryWithSize: sizeof(OFStream*)
						  count: _maxFD + 1];
		_FDToStream[_cancelFD[0]] = nil;








>
>
>
>
>
>







>





>







142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
			@throw [OFInitializationFailedException
			    exceptionWithClass: [self class]];

		_cancelAddr.sin_family = AF_INET;
		_cancelAddr.sin_port = 0;
		_cancelAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
		cancelAddr2 = _cancelAddr;

# ifdef __wii__
		/* The Wii does not accept port 0 as "choose any free port" */
		_cancelAddr.sin_port = 65533;
		cancelAddr2.sin_port = 65534;
# endif

		if (bind(_cancelFD[0], (struct sockaddr*)&_cancelAddr,
		    sizeof(_cancelAddr)) || bind(_cancelFD[1],
		    (struct sockaddr*)&cancelAddr2, sizeof(cancelAddr2)))
			@throw [OFInitializationFailedException
			    exceptionWithClass: [self class]];

# ifndef __wii__
		cancelAddrLen = sizeof(_cancelAddr);
		if (getsockname(_cancelFD[0], (struct sockaddr*)&_cancelAddr,
		    &cancelAddrLen))
			@throw [OFInitializationFailedException
			    exceptionWithClass: [self class]];
# endif
#endif

		_maxFD = _cancelFD[0];
		_FDToStream = [self allocMemoryWithSize: sizeof(OFStream*)
						  count: _maxFD + 1];
		_FDToStream[_cancelFD[0]] = nil;