ObjFW  Check-in [bed2db0fd3]

Overview
Comment:Fix compilation for Wii

This pretends that net_getsockopt() exists, which it does not yet. As
soon as it lands in libogc, this will work again.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: bed2db0fd3a484dc62252ee72c4422624a4a5eea1d5a155d9e7caa0a4e98345f
User & Date: js on 2018-08-26 18:39:28
Other Links: manifest | tags
Context
2018-08-26
21:06
socket.m: Set the sin_len field on Wii check-in: 8386b52824 user: js tags: trunk
18:39
Fix compilation for Wii check-in: bed2db0fd3 user: js tags: trunk
17:40
configure: Clean up flags for objfw-config check-in: 3155de66ff user: js tags: trunk
Changes

Modified src/OFStream.m from [222e2d5c1c] to [e66876a272].

25
26
27
28
29
30
31




32
33
34
35
36
37
38
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif





#include "platform.h"

#if !defined(OF_WINDOWS) && !defined(OF_MORPHOS)
# include <signal.h>
#endif








>
>
>
>







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif

#ifdef OF_HAVE_SOCKETS
# import "socket_helpers.h"
#endif

#include "platform.h"

#if !defined(OF_WINDOWS) && !defined(OF_MORPHOS)
# include <signal.h>
#endif

1670
1671
1672
1673
1674
1675
1676

1677
1678
1679
1680
1681
1682
1683
1684
{
#if defined(HAVE_FCNTL)
	bool readImplemented = false, writeImplemented = false;

	@try {
		int readFlags;


		readFlags = fcntl([(id)self fileDescriptorForReading], F_GETFL);

		readImplemented = true;

		if (readFlags == -1)
			@throw [OFSetOptionFailedException
			    exceptionWithObject: self
					  errNo: errno];







>
|







1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
{
#if defined(HAVE_FCNTL)
	bool readImplemented = false, writeImplemented = false;

	@try {
		int readFlags;

		readFlags =
		    fcntl([(id)self fileDescriptorForReading], F_GETFL, 0);

		readImplemented = true;

		if (readFlags == -1)
			@throw [OFSetOptionFailedException
			    exceptionWithObject: self
					  errNo: errno];
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
	} @catch (OFNotImplementedException *e) {
	}

	@try {
		int writeFlags;

		writeFlags =
		    fcntl([(id)self fileDescriptorForWriting], F_GETFL);

		writeImplemented = true;

		if (writeFlags == -1)
			@throw [OFSetOptionFailedException
			    exceptionWithObject: self
					  errNo: errno];







|







1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
	} @catch (OFNotImplementedException *e) {
	}

	@try {
		int writeFlags;

		writeFlags =
		    fcntl([(id)self fileDescriptorForWriting], F_GETFL, 0);

		writeImplemented = true;

		if (writeFlags == -1)
			@throw [OFSetOptionFailedException
			    exceptionWithObject: self
					  errNo: errno];

Modified src/OFTCPSocket.m from [aaa2b87b7c] to [3cac08541a].

335
336
337
338
339
340
341

342
343
344

345
346
347
348
349
350
351
		of_resolver_result_t *result = *iter;
		of_socket_address_t address;

		switch (result->family) {
		case AF_INET:
			address.family = OF_SOCKET_ADDRESS_FAMILY_IPV4;
			break;

		case AF_INET6:
			address.family = OF_SOCKET_ADDRESS_FAMILY_IPV6;
			break;

		default:
			errNo = EAFNOSUPPORT;
			continue;
		}

		if (result->addressLength > sizeof(address)) {
			errNo = EOVERFLOW;







>



>







335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
		of_resolver_result_t *result = *iter;
		of_socket_address_t address;

		switch (result->family) {
		case AF_INET:
			address.family = OF_SOCKET_ADDRESS_FAMILY_IPV4;
			break;
#ifdef AF_INET6
		case AF_INET6:
			address.family = OF_SOCKET_ADDRESS_FAMILY_IPV6;
			break;
#endif
		default:
			errNo = EAFNOSUPPORT;
			continue;
		}

		if (result->addressLength > sizeof(address)) {
			errNo = EOVERFLOW;

Modified src/OFUDPSocket.m from [22a70e2ff3] to [06139f0b65].

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
{
	return _blocking;
}

- (void)setBlocking: (bool)enable
{
#if defined(HAVE_FCNTL)
	int flags = fcntl(_socket, F_GETFL);

	if (flags == -1)
		@throw [OFSetOptionFailedException exceptionWithObject: self
								 errNo: errno];

	if (enable)
		flags &= ~O_NONBLOCK;







|







294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
{
	return _blocking;
}

- (void)setBlocking: (bool)enable
{
#if defined(HAVE_FCNTL)
	int flags = fcntl(_socket, F_GETFL, 0);

	if (flags == -1)
		@throw [OFSetOptionFailedException exceptionWithObject: self
								 errNo: errno];

	if (enable)
		flags &= ~O_NONBLOCK;

Modified src/socket.h from [acbe13b260] to [0a5ee032af].

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

#ifndef OF_HAVE_SOCKETS
# error No sockets available!
#endif

#include <stdbool.h>

#import "platform.h"

#ifdef OF_HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef OF_HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif







|







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

#ifndef OF_HAVE_SOCKETS
# error No sockets available!
#endif

#include <stdbool.h>

#import "OFString.h"

#ifdef OF_HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef OF_HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif

Modified src/socket_helpers.h from [44ead89dcb] to [9196eb16cc].

70
71
72
73
74
75
76
77


78


79
80
81
82
83
84
85
typedef uint32_t in_addr_t;
#endif

#ifdef OF_WII
# define accept(sock, addr, addrlen) net_accept(sock, addr, addrlen)
# define bind(sock, addr, addrlen) net_bind(sock, addr, addrlen)
# define closesocket(sock) net_close(sock)
# define connect(sock, addr, addrlen) net_connect(sock, addr, addrlen)


# define gethostbyname(name) net_gethostbyname(name)


# define h_errno 0
# define hstrerror(err) "unknown (no hstrerror)"
# define listen(sock, backlog) net_listen(sock, backlog)
# define poll(fds, nfds, timeout) net_poll(fds, nfds, timeout)
# define recv(sock, buf, len, flags) net_recv(sock, buf, len, flags)
# define recvfrom(sock, buf, len, flags, addr, addrlen) \
    net_recvfrom(sock, buf, len, flags, addr, addrlen)







|
>
>

>
>







70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
typedef uint32_t in_addr_t;
#endif

#ifdef OF_WII
# define accept(sock, addr, addrlen) net_accept(sock, addr, addrlen)
# define bind(sock, addr, addrlen) net_bind(sock, addr, addrlen)
# define closesocket(sock) net_close(sock)
# define connect(sock, addr, addrlen) \
    net_connect(sock, (struct sockaddr *)addr, addrlen)
# define fcntl(fd, cmd, flags) net_fcntl(fd, cmd, flags)
# define gethostbyname(name) net_gethostbyname(name)
# define getsockopt(sock, level, name, value, len) \
    net_getsockopt(sock, level, name, value, len)
# define h_errno 0
# define hstrerror(err) "unknown (no hstrerror)"
# define listen(sock, backlog) net_listen(sock, backlog)
# define poll(fds, nfds, timeout) net_poll(fds, nfds, timeout)
# define recv(sock, buf, len, flags) net_recv(sock, buf, len, flags)
# define recvfrom(sock, buf, len, flags, addr, addrlen) \
    net_recvfrom(sock, buf, len, flags, addr, addrlen)