Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -782,11 +782,11 @@ ]) ]) 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__) __asm__ __volatile__ ( "fstmfdd sp!, {d0-d7}" Index: src/OFRunLoop+Private.h ================================================================== --- src/OFRunLoop+Private.h +++ src/OFRunLoop+Private.h @@ -82,14 +82,16 @@ block: (nullable of_stream_async_write_string_block_t) block # endif delegate: (nullable id )delegate; +# if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) + (void)of_addAsyncConnectForTCPSocket: (OFTCPSocket *)socket mode: (of_run_loop_mode_t)mode delegate: (id ) delegate; +# endif + (void)of_addAsyncAcceptForTCPSocket: (OFTCPSocket *)socket mode: (of_run_loop_mode_t)mode # ifdef OF_HAVE_BLOCKS block: (nullable of_tcp_socket_async_accept_block_t) Index: src/OFRunLoop.m ================================================================== --- src/OFRunLoop.m +++ src/OFRunLoop.m @@ -134,12 +134,14 @@ of_string_encoding_t _encoding; size_t _writtenLength; } @end +# if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) @interface OFRunLoop_ConnectQueueItem: OFRunLoop_QueueItem @end +# endif @interface OFRunLoop_AcceptQueueItem: OFRunLoop_QueueItem { @public # ifdef OF_HAVE_BLOCKS @@ -600,10 +602,11 @@ [super dealloc]; } @end +# if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) @implementation OFRunLoop_ConnectQueueItem - (bool)handleObject: (id)object { id exception = nil; int errNo; @@ -621,10 +624,11 @@ exception: exception]; return false; } @end +# endif @implementation OFRunLoop_AcceptQueueItem - (bool)handleObject: (id)object { OFTCPSocket *acceptedSocket; @@ -941,10 +945,11 @@ queueItem->_encoding = encoding; QUEUE_ITEM } +# if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) + (void)of_addAsyncConnectForTCPSocket: (OFTCPSocket *)stream mode: (of_run_loop_mode_t)mode delegate: (id ) delegate { @@ -952,10 +957,11 @@ queueItem->_delegate = [delegate retain]; QUEUE_ITEM } +# endif + (void)of_addAsyncAcceptForTCPSocket: (OFTCPSocket *)stream mode: (of_run_loop_mode_t)mode # ifdef OF_HAVE_BLOCKS block: (of_tcp_socket_async_accept_block_t)block Index: src/OFTCPSocket+Private.h ================================================================== --- src/OFTCPSocket+Private.h +++ src/OFTCPSocket+Private.h @@ -18,11 +18,13 @@ #import "OFTCPSocket.h" 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; - (bool)of_connectSocketToAddress: (const of_socket_address_t *)address errNo: (int *)errNo; Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -264,20 +264,36 @@ [self tryNextAddressWithRunLoopMode: runLoopMode]; 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]) { _exception = [[OFConnectionFailedException alloc] initWithHost: _host @@ -288,12 +304,18 @@ return; } [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]; } - (void)resolver: (OFDNSResolver *)resolver @@ -661,10 +683,11 @@ { closesocket(_socket); _socket = INVALID_SOCKET; } +#ifndef OF_WII - (int)of_socketError { int errNo; socklen_t len = sizeof(errNo); @@ -672,10 +695,11 @@ &len) != 0) return of_socket_errno(); return errNo; } +#endif - (void)connectToHost: (OFString *)host port: (uint16_t)port { void *pool = objc_autoreleasePoolPush(); Index: src/OFUDPSocket.m ================================================================== --- src/OFUDPSocket.m +++ src/OFUDPSocket.m @@ -152,11 +152,11 @@ if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #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) { int errNo = of_socket_errno(); Index: src/socket.h ================================================================== --- src/socket.h +++ src/socket.h @@ -130,11 +130,11 @@ #ifdef __cplusplus 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 /*! Index: src/socket.m ================================================================== --- src/socket.m +++ src/socket.m @@ -239,14 +239,14 @@ OFArray OF_GENERIC(OFString *) *components; uint32_t addr; memset(&ret, '\0', sizeof(ret)); ret.family = OF_SOCKET_ADDRESS_FAMILY_IPV4; -#ifndef OF_WII - ret.length = sizeof(ret.sockaddr.in); +#if defined(OF_WII) || defined(OF_NINTENDO_3DS) + ret.length = 8; #else - ret.length = 8; + ret.length = sizeof(ret.sockaddr.in); #endif addrIn->sin_family = AF_INET; addrIn->sin_port = OF_BSWAP16_IF_LE(port); #ifdef OF_WII @@ -403,16 +403,16 @@ if (address1->family != address2->family) return false; 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 addrIn1 = &address1->sockaddr.in; addrIn2 = &address2->sockaddr.in; @@ -454,15 +454,15 @@ OF_HASH_INIT(hash); OF_HASH_ADD(hash, address->family); 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 OF_HASH_ADD(hash, address->sockaddr.in.sin_port >> 8); OF_HASH_ADD(hash, address->sockaddr.in.sin_port); Index: src/socket_helpers.h ================================================================== --- src/socket_helpers.h +++ src/socket_helpers.h @@ -66,12 +66,10 @@ # 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 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)