Index: .gitignore ================================================================== --- .gitignore +++ .gitignore @@ -8,10 +8,11 @@ *.so *~ .deps aclocal.m4 autom4te.cache +boot.dol build buildsys.mk config.h config.h.in config.log Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -635,10 +635,14 @@ mingw*) AC_SUBST(OFSTREAMOBSERVER_SELECT_M, "OFStreamObserver_select.m") ;; 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 #ifndef _WIN32 Index: src/OFStreamObserver.h ================================================================== --- src/OFStreamObserver.h +++ src/OFStreamObserver.h @@ -25,10 +25,16 @@ #endif #ifdef _WIN32 # include #endif + +#ifdef __wii__ +# define BOOL OGC_BOOL +# include +# undef BOOL +#endif @class OFStream; @class OFMutableArray; @class OFMutableDictionary; @class OFDataArray; Index: src/OFStreamObserver.m ================================================================== --- src/OFStreamObserver.m +++ src/OFStreamObserver.m @@ -38,11 +38,11 @@ #import "OFDate.h" #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) # import "OFStreamObserver_select.h" #endif @@ -54,10 +54,21 @@ #import "OFInitializationFailedException.h" #import "OFOutOfRangeException.h" #import "autorelease.h" #import "macros.h" + +#ifdef __wii__ +# define BOOL OGC_BOOL +# include +# 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, QUEUE_READ = 0, @@ -77,11 +88,11 @@ if (self == [OFStreamObserver class]) return [OFStreamObserver_kqueue alloc]; return [super alloc]; } -#elif defined(HAVE_POLL_H) +#elif defined(HAVE_POLL_H) || defined(__wii__) + alloc { if (self == [OFStreamObserver class]) return [OFStreamObserver_poll alloc]; Index: src/OFStreamObserver_poll.m ================================================================== --- src/OFStreamObserver_poll.m +++ src/OFStreamObserver_poll.m @@ -29,10 +29,20 @@ #import "OFOutOfRangeException.h" #import "autorelease.h" #import "macros.h" + +#ifdef __wii__ +# define BOOL OGC_BOOL +# include +# 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 { self = [super init]; Index: src/OFStreamSocket.m ================================================================== --- src/OFStreamSocket.m +++ src/OFStreamSocket.m @@ -34,10 +34,18 @@ #import "OFInitializationFailedException.h" #import "OFNotConnectedException.h" #import "OFReadFailedException.h" #import "OFSetOptionFailedException.h" #import "OFWriteFailedException.h" + +#ifdef __wii__ +# define BOOL OGC_BOOL +# include +# 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 @@ -44,23 +52,29 @@ #ifdef _WIN32 # define close(sock) closesocket(sock) #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 { return [[[self alloc] init] autorelease]; } Index: src/OFTCPSocket.h ================================================================== --- src/OFTCPSocket.h +++ src/OFTCPSocket.h @@ -30,10 +30,16 @@ #import "OFStreamSocket.h" #ifdef _WIN32 # include #endif + +#ifdef __wii__ +# define BOOL OGC_BOOL +# include +# undef BOOL +#endif /*! @file */ @class OFTCPSocket; @class OFString; Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -83,10 +83,23 @@ #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; @@ -489,11 +502,13 @@ { 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 @@ -618,12 +633,14 @@ 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 Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -91,11 +91,14 @@ psp-fixup-imports ${PROG_NOINST} mksfo "ObjFW Tests" PARAM.SFO 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 LIBS := -L../src -lobjfw ${TESTS_LIBS} ${LIBS} LDFLAGS += ${MAP_LDFLAGS} LD = ${OBJC} Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -87,21 +87,18 @@ } @catch (id e) { TestsAppDelegate *delegate = [[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 (;;) { WPAD_ScanPads();