summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Schleifer <js@heap.zone>2019-01-07 23:59:58 +0100
committerJonathan Schleifer <js@heap.zone>2019-01-07 23:59:58 +0100
commita081a818743240b117afcc8ee54df273c724e271 (patch)
tree69e5712d7831c90e709e874e904d53d5e0610eca
parent35588392ae9d1c67068b08e22b90fc24baec7ce6 (diff)
Partially fix sockets on Nintendo 3DS/Wii
This does not fully fix it yet, but at least the socket tests in the test suite pass on 3DS now.
-rw-r--r--configure.ac2
-rw-r--r--src/OFRunLoop+Private.h2
-rw-r--r--src/OFRunLoop.m6
-rw-r--r--src/OFTCPSocket+Private.h2
-rw-r--r--src/OFTCPSocket.m24
-rw-r--r--src/OFUDPSocket.m2
-rw-r--r--src/socket.h2
-rw-r--r--src/socket.m20
-rw-r--r--src/socket_helpers.h2
9 files changed, 47 insertions, 15 deletions
diff --git a/configure.ac b/configure.ac
index ef9e9bbc..9d5338d4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -784,7 +784,7 @@ AC_TRY_COMPILE([
case "$host_cpu" in
arm* | earm*)
- AC_MSG_CHECKING(if VFP2 or above is available)
+ AC_MSG_CHECKING(for VFP2 or above)
AC_TRY_COMPILE([], [
#if !defined(__arm64__) && !defined(__aarch64__) && \
!defined(__ARM64_ARCH_8__)
diff --git a/src/OFRunLoop+Private.h b/src/OFRunLoop+Private.h
index 0bdbc999..bdcdfee9 100644
--- a/src/OFRunLoop+Private.h
+++ b/src/OFRunLoop+Private.h
@@ -84,10 +84,12 @@ OF_ASSUME_NONNULL_BEGIN
block
# endif
delegate: (nullable id <OFStreamDelegate>)delegate;
+# if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
+ (void)of_addAsyncConnectForTCPSocket: (OFTCPSocket *)socket
mode: (of_run_loop_mode_t)mode
delegate: (id <OFTCPSocketDelegate_Private>)
delegate;
+# endif
+ (void)of_addAsyncAcceptForTCPSocket: (OFTCPSocket *)socket
mode: (of_run_loop_mode_t)mode
# ifdef OF_HAVE_BLOCKS
diff --git a/src/OFRunLoop.m b/src/OFRunLoop.m
index 99ad8768..ff7cfada 100644
--- a/src/OFRunLoop.m
+++ b/src/OFRunLoop.m
@@ -136,8 +136,10 @@ static OFRunLoop *mainRunLoop = nil;
}
@end
+# if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
@interface OFRunLoop_ConnectQueueItem: OFRunLoop_QueueItem
@end
+# endif
@interface OFRunLoop_AcceptQueueItem: OFRunLoop_QueueItem
{
@@ -602,6 +604,7 @@ static OFRunLoop *mainRunLoop = nil;
}
@end
+# if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
@implementation OFRunLoop_ConnectQueueItem
- (bool)handleObject: (id)object
{
@@ -623,6 +626,7 @@ static OFRunLoop *mainRunLoop = nil;
return false;
}
@end
+# endif
@implementation OFRunLoop_AcceptQueueItem
- (bool)handleObject: (id)object
@@ -943,6 +947,7 @@ static OFRunLoop *mainRunLoop = nil;
QUEUE_ITEM
}
+# if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
+ (void)of_addAsyncConnectForTCPSocket: (OFTCPSocket *)stream
mode: (of_run_loop_mode_t)mode
delegate: (id <OFTCPSocketDelegate_Private>)
@@ -954,6 +959,7 @@ static OFRunLoop *mainRunLoop = nil;
QUEUE_ITEM
}
+# endif
+ (void)of_addAsyncAcceptForTCPSocket: (OFTCPSocket *)stream
mode: (of_run_loop_mode_t)mode
diff --git a/src/OFTCPSocket+Private.h b/src/OFTCPSocket+Private.h
index 04d02a3a..82e28948 100644
--- a/src/OFTCPSocket+Private.h
+++ b/src/OFTCPSocket+Private.h
@@ -20,7 +20,9 @@
OF_ASSUME_NONNULL_BEGIN
@interface OFTCPSocket ()
+#ifndef OF_WII
@property (readonly, nonatomic) int of_socketError;
+#endif
- (bool)of_createSocketForAddress: (const of_socket_address_t *)address
errNo: (int *)errNo;
diff --git a/src/OFTCPSocket.m b/src/OFTCPSocket.m
index 3eab87f6..0f5f9964 100644
--- a/src/OFTCPSocket.m
+++ b/src/OFTCPSocket.m
@@ -266,16 +266,32 @@ static uint16_t defaultSOCKS5Port = 1080;
return;
}
+#if defined(OF_NINTENDO_3DS) || defined(OF_WII)
+ /*
+ * On Wii and 3DS, connect() fails if non-blocking is enabled.
+ *
+ * Additionally, on Wii, there is no getsockopt(), so it would not be
+ * possible to get the error (or success) after connecting anyway.
+ *
+ * So for now, connecting is blocking on Wii and 3DS.
+ *
+ * FIXME: Use a different thread as a work around.
+ */
+ [_socket setBlocking: true];
+#else
[_socket setBlocking: false];
+#endif
if (![_socket of_connectSocketToAddress: &address
errNo: &errNo]) {
+#if !defined(OF_NINTENDO_3DS) && !defined(OF_WII)
if (errNo == EINPROGRESS) {
[OFRunLoop of_addAsyncConnectForTCPSocket: _socket
mode: runLoopMode
delegate: self];
return;
} else {
+#endif
[_socket of_closeSocket];
if (_socketAddressesIndex >= [_socketAddresses count]) {
@@ -290,9 +306,15 @@ static uint16_t defaultSOCKS5Port = 1080;
[self tryNextAddressWithRunLoopMode: runLoopMode];
return;
+#if !defined(OF_NINTENDO_3DS) && !defined(OF_WII)
}
+#endif
}
+#if defined(OF_NINTENDO_3DS) || defined(OF_WII)
+ [_socket setBlocking: false];
+#endif
+
[self didConnect];
}
@@ -663,6 +685,7 @@ static uint16_t defaultSOCKS5Port = 1080;
_socket = INVALID_SOCKET;
}
+#ifndef OF_WII
- (int)of_socketError
{
int errNo;
@@ -674,6 +697,7 @@ static uint16_t defaultSOCKS5Port = 1080;
return errNo;
}
+#endif
- (void)connectToHost: (OFString *)host
port: (uint16_t)port
diff --git a/src/OFUDPSocket.m b/src/OFUDPSocket.m
index 804f14c9..94ab1d80 100644
--- a/src/OFUDPSocket.m
+++ b/src/OFUDPSocket.m
@@ -154,7 +154,7 @@
#endif
#if defined(OF_WII) || defined(OF_NINTENDO_3DS)
- if (port != 0) {
+ if (of_socket_address_get_port(address) != 0) {
#endif
if (bind(_socket, &address->sockaddr.sockaddr,
address->length) != 0) {
diff --git a/src/socket.h b/src/socket.h
index c4bd1f78..b754998a 100644
--- a/src/socket.h
+++ b/src/socket.h
@@ -132,7 +132,7 @@ extern "C" {
#endif
extern bool of_socket_init(void);
extern int of_socket_errno(void);
-# ifndef OF_WII
+# if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
extern int of_getsockname(of_socket_t sock, struct sockaddr *restrict addr,
socklen_t *restrict addrLen);
# endif
diff --git a/src/socket.m b/src/socket.m
index d51e2611..0e261885 100644
--- a/src/socket.m
+++ b/src/socket.m
@@ -241,10 +241,10 @@ of_socket_address_parse_ipv4(OFString *IPv4, uint16_t port)
memset(&ret, '\0', sizeof(ret));
ret.family = OF_SOCKET_ADDRESS_FAMILY_IPV4;
-#ifndef OF_WII
- ret.length = sizeof(ret.sockaddr.in);
-#else
+#if defined(OF_WII) || defined(OF_NINTENDO_3DS)
ret.length = 8;
+#else
+ ret.length = sizeof(ret.sockaddr.in);
#endif
addrIn->sin_family = AF_INET;
@@ -405,12 +405,12 @@ of_socket_address_equal(const of_socket_address_t *address1,
switch (address1->family) {
case OF_SOCKET_ADDRESS_FAMILY_IPV4:
-#ifndef OF_WII
- if (address1->length < (socklen_t)sizeof(struct sockaddr_in) ||
- address2->length < (socklen_t)sizeof(struct sockaddr_in))
+#if defined(OF_WII) || defined(OF_NINTENDO_3DS)
+ if (address1->length < 8 || address2->length < 8)
@throw [OFInvalidArgumentException exception];
#else
- if (address1->length < 8 || address2->length < 8)
+ if (address1->length < (socklen_t)sizeof(struct sockaddr_in) ||
+ address2->length < (socklen_t)sizeof(struct sockaddr_in))
@throw [OFInvalidArgumentException exception];
#endif
@@ -456,11 +456,11 @@ of_socket_address_hash(const of_socket_address_t *address)
switch (address->family) {
case OF_SOCKET_ADDRESS_FAMILY_IPV4:
-#ifndef OF_WII
- if (address->length < (socklen_t)sizeof(struct sockaddr_in))
+#if defined(OF_WII) || defined(OF_NINTENDO_3DS)
+ if (address->length < 8)
@throw [OFInvalidArgumentException exception];
#else
- if (address->length < 8)
+ if (address->length < (socklen_t)sizeof(struct sockaddr_in))
@throw [OFInvalidArgumentException exception];
#endif
diff --git a/src/socket_helpers.h b/src/socket_helpers.h
index 8940e7e5..04574594 100644
--- a/src/socket_helpers.h
+++ b/src/socket_helpers.h
@@ -68,8 +68,6 @@ typedef uint32_t in_addr_t;
# define connect(sock, addr, addrlen) \
net_connect(sock, (struct sockaddr *)addr, addrlen)
# define fcntl(fd, cmd, flags) net_fcntl(fd, cmd, flags)
-# 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)