Index: PLATFORMS.md ================================================================== --- PLATFORMS.md +++ PLATFORMS.md @@ -99,11 +99,11 @@ * OS Versions: 9.2.0-20E, 10.5.0-30E / Homebrew Channel 1.1.0 * Architectures: ARM (EABI) * Compilers: GCC 5.3.0 (devkitARM release 45) * Runtimes: ObjFW - * Limitations: No threads, no sockets + * Limitations: No threads Nintendo DS ----------- Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -102,11 +102,10 @@ LDFLAGS="$LDFLAGS -specs=3dsx.specs -march=armv6k -mtune=mpcore" LDFLAGS="$LDFLAGS -mfloat-abi=hard -mtp=soft -mword-relocations" LIBS="$LIBS -L$DEVKITPRO/libctru/lib -lctru" enable_shared="no" enable_threads="no" # TODO - enable_sockets="no" # TODO check_pedantic="no" AC_DEFINE(OF_NINTENDO_3DS, 1, [Whether we are compiling for the Nintendo 3DS]) AC_SUBST(MAP_LDFLAGS, ['-Wl,-Map,$@.map']) @@ -841,10 +840,51 @@ AC_CHECK_HEADER(netinet/tcp.h, [ AC_DEFINE(OF_HAVE_NETINET_TCP_H, 1, [Whether we have netinet/tcp.h]) ]) AC_CHECK_HEADERS([arpa/inet.h netdb.h]) + + AC_CHECK_MEMBER([struct sockaddr_in6.sin6_addr], [ + AC_EGREP_CPP(yes, [ + #ifdef OF_HAVE_SYS_SOCKET_H + # include + #endif + + #ifdef _WIN32 + # ifdef __MINGW32__ + # include <_mingw.h> + # ifdef __MINGW64_VERSION_MAJOR + # include + # endif + # endif + # include + # include + #endif + + #ifdef AF_INET6 + yes + #endif + ], [ + AC_DEFINE(OF_HAVE_IPV6, 1, [Whether we have IPv6]) + ]) + ], [ + ], [ + #ifdef OF_HAVE_NETINET_IN_H + # include + #endif + + #ifdef _WIN32 + # ifdef __MINGW32__ + # include <_mingw.h> + # ifdef __MINGW64_VERSION_MAJOR + # include + # endif + # endif + # include + # include + #endif + ]) AC_CHECK_FUNCS([paccept accept4]) AC_CHECK_FUNC(kqueue, [ AC_DEFINE(HAVE_KQUEUE, 1, [Whether we have kqueue]) Index: src/OFKernelEventObserver.m ================================================================== --- src/OFKernelEventObserver.m +++ src/OFKernelEventObserver.m @@ -15,10 +15,12 @@ */ #define __NO_EXT_QNX #include "config.h" + +#include #import "OFKernelEventObserver.h" #import "OFKernelEventObserver+Private.h" #import "OFArray.h" #import "OFDataArray.h" @@ -99,11 +101,11 @@ - init { self = [super init]; @try { -#if !defined(OF_HAVE_PIPE) && !defined(OF_WII) +#if !defined(OF_HAVE_PIPE) && !defined(OF_WII) && !defined(OF_NINTENDO_3DS) socklen_t cancelAddrLen; #endif _readObjects = [[OFMutableArray alloc] init]; _writeObjects = [[OFMutableArray alloc] init]; @@ -120,28 +122,44 @@ exceptionWithClass: [self class]]; _cancelAddr.sin_family = AF_INET; _cancelAddr.sin_port = 0; _cancelAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); - # ifdef OF_WII _cancelAddr.sin_len = 8; - /* The Wii does not accept port 0 as "choose any free port" */ - _cancelAddr.sin_port = of_socket_port_find(SOCK_DGRAM); # endif +# if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) if (bind(_cancelFD[0], (struct sockaddr*)&_cancelAddr, - sizeof(_cancelAddr))) + sizeof(_cancelAddr)) != 0) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; -# ifndef OF_WII cancelAddrLen = sizeof(_cancelAddr); if (of_getsockname(_cancelFD[0], (struct sockaddr*)&_cancelAddr, &cancelAddrLen) != 0) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; +# else + for (;;) { + uint16_t rnd = 0; + int ret; + + while (rnd < 1024) + rnd = (uint16_t)rand(); + + _cancelAddr.sin_port = OF_BSWAP16_IF_LE(rnd); + ret = bind(_cancelFD[0], (struct sockaddr*)&_cancelAddr, + sizeof(_cancelAddr)); + + if (ret == 0) + break; + + if (of_socket_errno() != EADDRINUSE) + @throw [OFInitializationFailedException + exceptionWithClass: [self class]]; + } # endif #endif #ifdef OF_HAVE_THREADS _mutex = [[OFMutex alloc] init]; @@ -162,14 +180,10 @@ { close(_cancelFD[0]); if (_cancelFD[1] != _cancelFD[0]) close(_cancelFD[1]); -#ifdef OF_WII - of_socket_port_free(_cancelAddr.sin_port, SOCK_DGRAM); -#endif - [_readObjects release]; [_writeObjects release]; #ifdef OF_HAVE_THREADS [_mutex release]; Index: src/OFTCPSocket.h ================================================================== --- src/OFTCPSocket.h +++ src/OFTCPSocket.h @@ -65,11 +65,10 @@ socklen_t _addressLength; OFString *_SOCKS5Host; uint16_t _SOCKS5Port; #ifdef OF_WII uint16_t _port; - bool _keepAliveEnabled, _TCPNoDelayEnabled; #endif } /*! * The host to use as a SOCKS5 proxy. @@ -219,37 +218,49 @@ * * @return Whether the socket is a listening socket */ - (bool)isListening; +#if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) /*! * @brief Enable or disable keep alive for the connection. + * + * @warning This is not available on the Wii or Nintendo 3DS! * * @param enabled Whether to enable or disable keep alives for the connection */ - (void)setKeepAliveEnabled: (bool)enabled; /*! * @brief Returns whether keep alive is enabled for the connection. * + * @warning This is not available on the Wii or Nintendo 3DS! + * * @return Whether keep alives are enabled for the connection */ - (bool)isKeepAliveEnabled; +#endif +#ifndef OF_WII /*! * @brief Enable or disable TCP_NODELAY for the connection. + * + * @warning This is not available on the Wii! * * @param enabled Whether to enable or disable TCP_NODELAY for the connection */ - (void)setTCPNoDelayEnabled: (bool)enabled; /*! * @brief Returns whether TCP_NODELAY is enabled for the connection. + * + * @warning This is not available on the Wii! * * @return Whether TCP_NODELAY is enabled for the connection */ - (bool)isTCPNoDelayEnabled; +#endif @end #ifdef __cplusplus extern "C" { #endif Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -242,22 +242,10 @@ [_SOCKS5Host release]; [super dealloc]; } -- (void)close -{ - [super close]; - -#ifdef OF_WII - if (_port > 0) { - of_socket_port_free(_port, SOCK_STREAM); - _port = 0; - } -#endif -} - - (void)connectToHost: (OFString*)host port: (uint16_t)port { OFString *destinationHost = host; uint16_t destinationPort = port; @@ -368,15 +356,15 @@ - (uint16_t)bindToHost: (OFString*)host port: (uint16_t)port { of_resolver_result_t **results; const int one = 1; -#ifndef OF_WII +#if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) union { struct sockaddr_storage storage; struct sockaddr_in in; -# ifdef AF_INET6 +# ifdef HAVE_IPV6 struct sockaddr_in6 in6; # endif } addr; socklen_t addrLen; #endif @@ -386,29 +374,11 @@ if (_SOCKS5Host != nil) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; -#ifdef OF_WII - if (port == 0) - port = of_socket_port_find(SOCK_STREAM); - else if (!of_socket_port_register(port, SOCK_STREAM)) - @throw [OFBindFailedException exceptionWithHost: host - port: port - socket: self - errNo: EADDRINUSE]; -#endif - - @try { - results = of_resolve_host(host, port, SOCK_STREAM); - } @catch (id e) { -#ifdef OF_WII - of_socket_port_free(port, SOCK_STREAM); -#endif - @throw e; - } - + results = of_resolve_host(host, port, SOCK_STREAM); @try { #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif @@ -427,39 +397,84 @@ #endif setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR, (const char*)&one, (socklen_t)sizeof(one)); - if (bind(_socket, results[0]->address, - results[0]->addressLength) == -1) { - int errNo = of_socket_errno(); - - close(_socket); - _socket = INVALID_SOCKET; - - @throw [OFBindFailedException exceptionWithHost: host - port: port - socket: self - errNo: errNo]; - } - } @catch (id e) { -#ifdef OF_WII - of_socket_port_free(port, SOCK_STREAM); -#endif - @throw e; +#if defined(OF_WII) || defined(OF_NINTENDO_3DS) + if (port != 0) { +#endif + if (bind(_socket, results[0]->address, + results[0]->addressLength) != 0) { + int errNo = of_socket_errno(); + + close(_socket); + _socket = INVALID_SOCKET; + + @throw [OFBindFailedException + exceptionWithHost: host + port: port + socket: self + errNo: errNo]; + } +#if defined(OF_WII) || defined(OF_NINTENDO_3DS) + } else { + for (;;) { + uint16_t rnd = 0; + int ret; + + while (rnd < 1024) + rnd = (uint16_t)rand(); + + switch (results[0]->family) { + case AF_INET: + ((struct sockaddr_in*) + results[0]->address)->sin_port = + OF_BSWAP16_IF_LE(rnd); + break; +# ifdef HAVE_IPV6 + case AF_INET6: + ((struct sockaddr_in6*) + results[0]->address)->sin6_port = + OF_BSWAP16_IF_LE(rnd); + break; +# endif + default: + @throw [OFInvalidArgumentException + exception]; + } + + ret = bind(_socket, results[0]->address, + results[0]->addressLength); + + if (ret == 0) { + port = rnd; + break; + } + + if (of_socket_errno() != EADDRINUSE) { + int errNo = of_socket_errno(); + + close(_socket); + _socket = INVALID_SOCKET; + + @throw [OFBindFailedException + exceptionWithHost: host + port: port + socket: self + errNo: errNo]; + } + } + } +#endif } @finally { of_resolver_free(results); } - if (port > 0) { -#ifdef OF_WII - _port = port; -#endif + if (port > 0) return port; - } -#ifndef OF_WII +#if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) addrLen = (socklen_t)sizeof(addr.storage); if (of_getsockname(_socket, (struct sockaddr*)&addr.storage, &addrLen) != 0) { int errNo = of_socket_errno(); @@ -472,11 +487,11 @@ errNo: errNo]; } if (addr.storage.ss_family == AF_INET) return OF_BSWAP16_IF_LE(addr.in.sin_port); -# ifdef AF_INET6 +# ifdef HAVE_IPV6 if (addr.storage.ss_family == AF_INET6) return OF_BSWAP16_IF_LE(addr.in6.sin6_port); # endif #endif @@ -594,28 +609,24 @@ - (bool)isListening { return _listening; } +#if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) - (void)setKeepAliveEnabled: (bool)enabled { int v = enabled; if (setsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&v, (socklen_t)sizeof(v)) != 0) @throw [OFSetOptionFailedException exceptionWithStream: self errNo: of_socket_errno()]; - -#ifdef OF_WII - _keepAliveEnabled = enabled; -#endif } - (bool)isKeepAliveEnabled { -#ifndef OF_WII int v; socklen_t len = sizeof(v); if (getsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&v, &len) != 0 || len != sizeof(v)) @@ -622,33 +633,27 @@ @throw [OFGetOptionFailedException exceptionWithStream: self errNo: of_socket_errno()]; return v; -#else - return _keepAliveEnabled; +} #endif -} +#ifndef OF_WII - (void)setTCPNoDelayEnabled: (bool)enabled { int v = enabled; if (setsockopt(_socket, IPPROTO_TCP, TCP_NODELAY, (char*)&v, (socklen_t)sizeof(v)) != 0) @throw [OFSetOptionFailedException exceptionWithStream: self errNo: of_socket_errno()]; - -#ifdef OF_WII - _TCPNoDelayEnabled = enabled; -#endif } - (bool)isTCPNoDelayEnabled { -#ifndef OF_WII int v; socklen_t len = sizeof(v); if (getsockopt(_socket, IPPROTO_TCP, TCP_NODELAY, (char*)&v, &len) != 0 || len != sizeof(v)) @@ -655,10 +660,8 @@ @throw [OFGetOptionFailedException exceptionWithStream: self errNo: of_socket_errno()]; return v; -#else - return _TCPNoDelayEnabled; -#endif } +#endif @end Index: src/OFUDPSocket.m ================================================================== --- src/OFUDPSocket.m +++ src/OFUDPSocket.m @@ -174,20 +174,20 @@ bool of_udp_socket_address_equal(of_udp_socket_address_t *address1, of_udp_socket_address_t *address2) { struct sockaddr_in *sin_1, *sin_2; -#ifdef AF_INET6 +#ifdef HAVE_IPV6 struct sockaddr_in6 *sin6_1, *sin6_2; #endif if (address1->address.ss_family != address2->address.ss_family) return false; switch (address1->address.ss_family) { case AF_INET: -#ifndef OF_WII +#if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) if (address1->length < sizeof(struct sockaddr_in) || address2->length < sizeof(struct sockaddr_in)) @throw [OFInvalidArgumentException exception]; #else if (address1->length < 8 || address2->length < 8) @@ -201,11 +201,11 @@ return false; if (sin_1->sin_addr.s_addr != sin_2->sin_addr.s_addr) return false; break; -#ifdef AF_INET6 +#ifdef HAVE_IPV6 case AF_INET6: if (address1->length < sizeof(struct sockaddr_in6) || address2->length < sizeof(struct sockaddr_in6)) @throw [OFInvalidArgumentException exception]; @@ -231,20 +231,20 @@ uint32_t of_udp_socket_address_hash(of_udp_socket_address_t *address) { uint32_t hash = of_hash_seed; struct sockaddr_in *sin; -#ifdef AF_INET6 +#ifdef HAVE_IPV6 struct sockaddr_in6 *sin6; uint32_t subhash; #endif hash += address->address.ss_family; switch (address->address.ss_family) { case AF_INET: -#ifndef OF_WII +#if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) if (address->length < sizeof(struct sockaddr_in)) @throw [OFInvalidArgumentException exception]; #else if (address->length < 8) @throw [OFInvalidArgumentException exception]; @@ -254,11 +254,11 @@ hash += (sin->sin_port << 1); hash ^= sin->sin_addr.s_addr; break; -#ifdef AF_INET6 +#ifdef HAVE_IPV6 case AF_INET6: if (address->length < sizeof(struct sockaddr_in6)) @throw [OFInvalidArgumentException exception]; sin6 = (struct sockaddr_in6*)&address->address; @@ -383,40 +383,22 @@ - (uint16_t)bindToHost: (OFString*)host port: (uint16_t)port { of_resolver_result_t **results; -#ifndef OF_WII +#if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) union { struct sockaddr_storage storage; struct sockaddr_in in; -# ifdef AF_INET6 +# ifdef HAVE_IPV6 struct sockaddr_in6 in6; # endif } addr; socklen_t addrLen; #endif -#ifdef OF_WII - if (port == 0) - port = of_socket_port_find(SOCK_DGRAM); - else if (!of_socket_port_register(port, SOCK_DGRAM)) - @throw [OFBindFailedException exceptionWithHost: host - port: port - socket: self - errNo: EADDRINUSE]; -#endif - - @try { - results = of_resolve_host(host, port, SOCK_DGRAM); - } @catch (id e) { -#ifdef OF_WII - of_socket_port_free(port, SOCK_DGRAM); -#endif - @throw e; - } - + results = of_resolve_host(host, port, SOCK_DGRAM); @try { #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif @@ -432,39 +414,84 @@ #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif - if (bind(_socket, results[0]->address, - results[0]->addressLength) == -1) { - int errNo = of_socket_errno(); - - close(_socket); - _socket = INVALID_SOCKET; - - @throw [OFBindFailedException exceptionWithHost: host - port: port - socket: self - errNo: errNo]; - } - } @catch (id e) { -#ifdef OF_WII - of_socket_port_free(port, SOCK_DGRAM); -#endif - @throw e; +#if defined(OF_WII) || defined(OF_NINTENDO_3DS) + if (port != 0) { +#endif + if (bind(_socket, results[0]->address, + results[0]->addressLength) != 0) { + int errNo = of_socket_errno(); + + close(_socket); + _socket = INVALID_SOCKET; + + @throw [OFBindFailedException + exceptionWithHost: host + port: port + socket: self + errNo: errNo]; + } +#if defined(OF_WII) || defined(OF_NINTENDO_3DS) + } else { + for (;;) { + uint16_t rnd = 0; + int ret; + + while (rnd < 1024) + rnd = (uint16_t)rand(); + + switch (results[0]->family) { + case AF_INET: + ((struct sockaddr_in*) + results[0]->address)->sin_port = + OF_BSWAP16_IF_LE(rnd); + break; +# ifdef HAVE_IPV6 + case AF_INET6: + ((struct sockaddr_in6*) + results[0]->address)->sin6_port = + OF_BSWAP16_IF_LE(rnd); + break; +# endif + default: + @throw [OFInvalidArgumentException + exception]; + } + + ret = bind(_socket, results[0]->address, + results[0]->addressLength); + + if (ret == 0) { + port = rnd; + break; + } + + if (of_socket_errno() != EADDRINUSE) { + int errNo = of_socket_errno(); + + close(_socket); + _socket = INVALID_SOCKET; + + @throw [OFBindFailedException + exceptionWithHost: host + port: port + socket: self + errNo: errNo]; + } + } + } +#endif } @finally { of_resolver_free(results); } - if (port > 0) { -#ifdef OF_WII - _port = port; -#endif + if (port > 0) return port; - } -#ifndef OF_WII +#if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) addrLen = (socklen_t)sizeof(addr.storage); if (of_getsockname(_socket, (struct sockaddr*)&addr.storage, &addrLen) != 0) { int errNo = of_socket_errno(); @@ -477,11 +504,11 @@ errNo: errNo]; } if (addr.storage.ss_family == AF_INET) return OF_BSWAP16_IF_LE(addr.in.sin_port); -# ifdef AF_INET6 +# ifdef HAVE_IPV6 if (addr.storage.ss_family == AF_INET6) return OF_BSWAP16_IF_LE(addr.in6.sin6_port); # endif #endif @@ -622,14 +649,7 @@ if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; close(_socket); _socket = INVALID_SOCKET; - -#ifdef OF_WII - if (_port > 0) { - of_socket_port_free(_port, SOCK_DGRAM); - _port = 0; - } -#endif } @end Index: src/objfw-defs.h.in ================================================================== --- src/objfw-defs.h.in +++ src/objfw-defs.h.in @@ -8,10 +8,11 @@ #undef OF_HAVE_CHMOD #undef OF_HAVE_CHOWN #undef OF_HAVE_FILES #undef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR #undef OF_HAVE_GCC_ATOMIC_OPS +#undef OF_HAVE_IPV6 #undef OF_HAVE_LINK #undef OF_HAVE_MAX_ALIGN_T #undef OF_HAVE_NETINET_IN_H #undef OF_HAVE_OSATOMIC #undef OF_HAVE_OSATOMIC_64 Index: src/socket.h ================================================================== --- src/socket.h +++ src/socket.h @@ -85,15 +85,11 @@ extern bool of_socket_init(void); extern int of_socket_errno(void); # ifndef OF_WII extern int of_getsockname(of_socket_t socket, struct sockaddr *restrict address, socklen_t *restrict address_len); -# else -extern bool of_socket_port_register(uint16_t port, int type); -extern void of_socket_port_free(uint16_t port, int type); -extern uint16_t of_socket_port_find(int type); # endif #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END Index: src/socket.m ================================================================== --- src/socket.m +++ src/socket.m @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" + +#ifdef OF_NINTENDO_3DS +# include /* For memalign() */ +#endif #include #import "OFException.h" /* For some E* -> WSAE* defines */ #import "OFInvalidArgumentException.h" @@ -24,11 +28,18 @@ #import "OFUnlockFailedException.h" #import "socket.h" #ifdef OF_HAVE_THREADS # include "threading.h" +#endif + +#ifdef OF_NINTENDO_3DS +# include <3ds/types.h> +# include <3ds/services/soc.h> +#endif +#ifdef OF_HAVE_THREADS static of_once_t onceControl = OF_ONCE_INIT; static of_mutex_t mutex; #endif static bool initialized = false; @@ -48,10 +59,20 @@ if (WSAStartup(MAKEWORD(2, 0), &wsa)) return; #elif defined(OF_WII) if (net_init() < 0) return; +#elif defined(OF_NINTENDO_3DS) + void *ctx; + + if ((ctx = memalign(0x1000, 0x100000)) == NULL) + return; + + if (socInit(ctx, 0x100000) != 0) + return; + + atexit((void(*))socExit); #endif #ifdef OF_HAVE_THREADS if (!of_mutex_new(&mutex)) return; @@ -197,90 +218,6 @@ @throw [OFUnlockFailedException exception]; # endif return ret; } -#else -static size_t -type_to_index(int type) -{ - switch (type) { - case SOCK_STREAM: - return 0; - case SOCK_DGRAM: - return 1; - default: - @throw [OFInvalidArgumentException exception]; - } -} - -bool -of_socket_port_register(uint16_t port, int type) -{ - size_t index; - bool wasSet; - - if (port == 0) - @throw [OFInvalidArgumentException exception]; - -# ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&spinlock)) - @throw [OFLockFailedException exception]; -# endif - - index = type_to_index(type); - wasSet = of_bitset_isset(portRegistry[index], port); - - of_bitset_set(portRegistry[index], port); - -# ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&spinlock)) - @throw [OFUnlockFailedException exception]; -# endif - - return !wasSet; -} - -void -of_socket_port_free(uint16_t port, int type) -{ - if (port == 0) - @throw [OFInvalidArgumentException exception]; - -# ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&spinlock)) - @throw [OFLockFailedException exception]; -# endif - - of_bitset_clear(portRegistry[type_to_index(type)], port); - -# ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&spinlock)) - @throw [OFUnlockFailedException exception]; -# endif -} - -uint16_t -of_socket_port_find(int type) -{ - uint16_t port; - size_t index; - -# ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&spinlock)) - @throw [OFLockFailedException exception]; -# endif - - index = type_to_index(type); - - do { - port = rand(); - } while (port == 0 || of_bitset_isset(portRegistry[index], port)); - -# ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&spinlock)) - @throw [OFUnlockFailedException exception]; -# endif - - return port; -} #endif Index: src/socket_helpers.h ================================================================== --- src/socket_helpers.h +++ src/socket_helpers.h @@ -48,11 +48,15 @@ #ifndef INADDR_NONE # define INADDR_NONE ((in_addr_t)-1) #endif #ifndef SOMAXCONN -# define SOMAXCONN 32 +/* + * Use 16 as everything > 17 fails on Nintendo 3DS and 16 is a less arbitrary + * number than 17. + */ +# define SOMAXCONN 16 #endif #ifndef SOCK_CLOEXEC # define SOCK_CLOEXEC 0 #endif @@ -59,15 +63,10 @@ #ifdef OF_WINDOWS # define close(sock) closesocket(sock) #endif -#ifdef OF_PSP -/* PSP defines AF_INET6, even though sockaddr_in6 is missing */ -# undef AF_INET6 -#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 close(sock) net_close(sock) # define connect(sock, addr, addrlen) net_connect(sock, addr, addrlen) Index: utils/ofhttp/ProgressBar.m ================================================================== --- utils/ofhttp/ProgressBar.m +++ utils/ofhttp/ProgressBar.m @@ -92,11 +92,11 @@ - (void)_drawProgress { float bars, percent; unsigned short barWidth; -#ifdef HAVE_SYS_IOCTL_H +#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) struct winsize ws; if (ioctl(0, TIOCGWINSZ, &ws) == 0 && ws.ws_col > 37) barWidth = ws.ws_col - 37; else