summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Schleifer <js@webkeks.org>2013-06-12 01:29:20 +0200
committerJonathan Schleifer <js@webkeks.org>2013-06-12 01:33:16 +0200
commitad34240647f41339912ae9c835bf72aa8af9c061 (patch)
tree0d5c1ca250218d98a92aeb0a67eb8f6560bf810c
parentbd29e8fc4d98cc413027b7b55919a9e4f07aad3a (diff)
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.
-rw-r--r--.gitignore1
-rw-r--r--configure.ac4
-rw-r--r--src/OFStreamObserver.h6
-rw-r--r--src/OFStreamObserver.m15
-rw-r--r--src/OFStreamObserver_poll.m10
-rw-r--r--src/OFStreamSocket.m18
-rw-r--r--src/OFTCPSocket.h6
-rw-r--r--src/OFTCPSocket.m17
-rw-r--r--tests/Makefile3
-rw-r--r--tests/TestsAppDelegate.m13
10 files changed, 81 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 06b3c19b..6ed52fae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,7 @@
.deps
aclocal.m4
autom4te.cache
+boot.dol
build
buildsys.mk
config.h
diff --git a/configure.ac b/configure.ac
index 7684bed9..013b328d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -638,6 +638,10 @@ AS_IF([test x"$enable_sockets" != x"no"], [
;;
esac
+ AS_IF([test x"$with_wii" = x"yes"], [
+ AC_SUBST(OFSTREAMOBSERVER_POLL_M, "OFStreamObserver_poll.m")
+ ])
+
AC_MSG_CHECKING(for getaddrinfo)
AC_TRY_COMPILE([
#include <stddef.h>
diff --git a/src/OFStreamObserver.h b/src/OFStreamObserver.h
index 7cdca77c..0834cd3c 100644
--- a/src/OFStreamObserver.h
+++ b/src/OFStreamObserver.h
@@ -28,6 +28,12 @@
# include <winsock2.h>
#endif
+#ifdef __wii__
+# define BOOL OGC_BOOL
+# include <network.h>
+# undef BOOL
+#endif
+
@class OFStream;
@class OFMutableArray;
@class OFMutableDictionary;
diff --git a/src/OFStreamObserver.m b/src/OFStreamObserver.m
index 5d6272b2..ff1ee014 100644
--- a/src/OFStreamObserver.m
+++ b/src/OFStreamObserver.m
@@ -40,7 +40,7 @@
#ifdef HAVE_KQUEUE
# import "OFStreamObserver_kqueue.h"
#endif
-#ifdef HAVE_POLL_H
+#if defined(HAVE_POLL_H) || defined(__wii__)
# import "OFStreamObserver_poll.h"
#endif
#if defined(HAVE_SYS_SELECT_H) || defined(_WIN32)
@@ -57,6 +57,17 @@
#import "autorelease.h"
#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,
QUEUE_REMOVE = 1,
@@ -79,7 +90,7 @@ enum {
return [super alloc];
}
-#elif defined(HAVE_POLL_H)
+#elif defined(HAVE_POLL_H) || defined(__wii__)
+ alloc
{
if (self == [OFStreamObserver class])
diff --git a/src/OFStreamObserver_poll.m b/src/OFStreamObserver_poll.m
index ea218dd6..50cf85f6 100644
--- a/src/OFStreamObserver_poll.m
+++ b/src/OFStreamObserver_poll.m
@@ -32,6 +32,16 @@
#import "autorelease.h"
#import "macros.h"
+#ifdef __wii__
+# define BOOL OGC_BOOL
+# include <network.h>
+# undef BOOL
+# define poll(fds, nfds, timeout) net_poll(fds, nfds, timeout)
+# define pollfd pollsd
+# define fd socket
+typedef u32 nfds_t;
+#endif
+
@implementation OFStreamObserver_poll
- init
{
diff --git a/src/OFStreamSocket.m b/src/OFStreamSocket.m
index fa9889e4..2b00976c 100644
--- a/src/OFStreamSocket.m
+++ b/src/OFStreamSocket.m
@@ -37,6 +37,14 @@
#import "OFSetOptionFailedException.h"
#import "OFWriteFailedException.h"
+#ifdef __wii__
+# define BOOL OGC_BOOL
+# include <network.h>
+# undef BOOL
+# define recv(sock, buf, len, flags) net_recv(sock, buf, len, flags)
+# define send(sock, buf, len, flags) net_send(sock, buf, len, flags)
+#endif
+
#ifndef INVALID_SOCKET
# define INVALID_SOCKET -1
#endif
@@ -46,19 +54,25 @@
#endif
@implementation OFStreamSocket
-#ifdef _WIN32
+ (void)initialize
{
+#ifdef _WIN32
WSADATA wsa;
+#endif
if (self != [OFStreamSocket class])
return;
+#if defined(_WIN32)
if (WSAStartup(MAKEWORD(2, 0), &wsa))
@throw [OFInitializationFailedException
exceptionWithClass: self];
-}
+#elif defined(__wii__)
+ if (net_init() < 0)
+ @throw [OFInitializationFailedException
+ exceptionWithClass: self];
#endif
+}
+ (instancetype)socket
{
diff --git a/src/OFTCPSocket.h b/src/OFTCPSocket.h
index ffcc548d..d9e7b9a6 100644
--- a/src/OFTCPSocket.h
+++ b/src/OFTCPSocket.h
@@ -33,6 +33,12 @@
# include <ws2tcpip.h>
#endif
+#ifdef __wii__
+# define BOOL OGC_BOOL
+# include <network.h>
+# undef BOOL
+#endif
+
/*! @file */
@class OFTCPSocket;
diff --git a/src/OFTCPSocket.m b/src/OFTCPSocket.m
index 2ca78e4c..b7ba01de 100644
--- a/src/OFTCPSocket.m
+++ b/src/OFTCPSocket.m
@@ -86,6 +86,19 @@ static OFMutex *mutex = nil;
# 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)
{
@@ -491,7 +504,9 @@ static uint16_t defaultSOCKS5Port = 1080;
union {
struct sockaddr_storage storage;
struct sockaddr_in in;
+#ifdef AF_INET6
struct sockaddr_in6 in6;
+#endif
} addr;
socklen_t addrLen;
@@ -620,8 +635,10 @@ static uint16_t defaultSOCKS5Port = 1080;
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;
diff --git a/tests/Makefile b/tests/Makefile
index 8c93d1b6..dc7f024b 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -93,6 +93,9 @@ EBOOT.PBP: ${PROG_NOINST}
psp-strip ${PROG_NOINST}
pack-pbp $@ PARAM.SFO NULL NULL NULL NULL NULL ${PROG_NOINST} NULL
+boot.dol: ${PROG_NOINST}
+ elf2dol ${PROG_NOINST} $@
+
include ../buildsys.mk
CPPFLAGS += -I../src -I../src/exceptions -I../src/runtime -I.. -DSTDOUT
diff --git a/tests/TestsAppDelegate.m b/tests/TestsAppDelegate.m
index 522f9f37..0c3e02e7 100644
--- a/tests/TestsAppDelegate.m
+++ b/tests/TestsAppDelegate.m
@@ -89,17 +89,14 @@ main(int argc, char *argv[])
[[OFApplication sharedApplication] delegate];
OFString *string = [OFString stringWithFormat:
@"\nRuntime error: Unhandled exception:\n%@\n", e];
- OFString *backtrace = [[e backtrace]
- componentsJoinedByString: @"\n "];
+ OFString *backtrace = [OFString stringWithFormat:
+ @"\nBacktrace:\n %@\n\n",
+ [[e backtrace] componentsJoinedByString: @"\n "];
[delegate outputString: string
inColor: RED];
- if (backtrace != nil) {
- backtrace = [OFString stringWithFormat:
- @"\nBacktrace:\n %@\n\n", backtrace];
- [delegate outputString: backtrace
- inColor: RED];
- }
+ [delegate outputString: backtrace
+ inColor: RED];
[delegate outputString: @"Press home button to exit!\n"
inColor: NO_COLOR];
for (;;) {