Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -595,10 +595,13 @@ AC_DEFINE(OF_HAVE_LINK, 1, [Whether we have link()]) ]) AC_CHECK_FUNC(symlink, [ AC_DEFINE(OF_HAVE_SYMLINK, 1, [Whether we have symlink()]) ]) +AC_CHECK_FUNC(pipe, [ + AC_DEFINE(OF_HAVE_PIPE, 1, [Whether we have pipe()]) +]) AC_ARG_ENABLE(sockets, AS_HELP_STRING([--disable-sockets], [disable socket support])) AS_IF([test x"$enable_sockets" != x"no"], [ AC_DEFINE(OF_HAVE_SOCKETS, 1, [Whether we have sockets]) @@ -606,10 +609,16 @@ AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket") AC_CHECK_LIB(network, socket, LIBS="$LIBS -lnetwork") AC_CHECK_LIB(ws2_32, main, LIBS="$LIBS -lws2_32") + AC_CHECK_HEADER(sys/socket.h, [ + AC_DEFINE(OF_HAVE_SYS_SOCKET_H, 1, + [Whether we have sys/socket.h]) + ]) + AC_CHECK_HEADERS([netinet/in.h arpa/inet.h netdb.h]) + AC_CHECK_FUNC(kqueue, [ AC_DEFINE(HAVE_KQUEUE, 1, [Whether we have kqueue]) AC_SUBST(OFSTREAMOBSERVER_KQUEUE_M, "OFStreamObserver_kqueue.m") ]) AC_CHECK_HEADER(poll.h, [ @@ -618,10 +627,11 @@ ]) AC_CHECK_HEADER(sys/select.h, [ AC_DEFINE(HAVE_SYS_SELECT_H, 1, [Whether we have sys/select.h]) AC_SUBST(OFSTREAMOBSERVER_SELECT_M, "OFStreamObserver_select.m") ]) + case "$host_os" in mingw*) AC_SUBST(OFSTREAMOBSERVER_SELECT_M, "OFStreamObserver_select.m") ;; @@ -699,16 +709,19 @@ ]) AS_IF([test x"$have_threadsafe_getaddrinfo" = x"yes"], [ AC_DEFINE(HAVE_THREADSAFE_GETADDRINFO, 1, [Whether getaddrinfo is thread-safe]) + ], [ + AC_CHECK_FUNCS([h_errno hstrerror]) ]) AC_MSG_RESULT($have_threadsafe_getaddrinfo) ]) ], [ AC_MSG_RESULT(no) + AC_CHECK_FUNCS([h_errno hstrerror]) ]) ]) AS_IF([test x"$enable_sockets" != x"no" -a x"$enable_threads" != x"no"], [ AC_SUBST(OFHTTPCLIENTTESTS_M, "OFHTTPClientTests.m") @@ -717,11 +730,11 @@ case "$host" in *-*-mingw*) have_processes="yes" ;; *) - AC_CHECK_FUNCS([fork pipe dup2 execvp kill], [ + AC_CHECK_FUNCS([fork dup2 execvp kill], [ if test x"$ac_cv_func_fork" = x"yes" \ -a x"$ac_cv_func_pipe" = x"yes" \ -a x"$ac_cv_func_dup2" = x"yes" \ -a x"$ac_cv_func_execvp" = x"yes" \ -a x"$ac_cv_func_kill" = x"yes"; then Index: src/OFStreamObserver.h ================================================================== --- src/OFStreamObserver.h +++ src/OFStreamObserver.h @@ -17,10 +17,14 @@ #import "OFObject.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif + +#ifdef OF_HAVE_SYS_SOCKET_H +# include +#endif #ifdef _WIN32 # include #endif @@ -84,11 +88,11 @@ size_t _maxFD; OFMutableArray *_queue; OFDataArray *_queueInfo, *_queueFDs; id _delegate; int _cancelFD[2]; -#ifdef _WIN32 +#ifndef OF_HAVE_PIPE struct sockaddr_in _cancelAddr; #endif #ifdef OF_HAVE_THREADS OFMutex *_mutex; #endif Index: src/OFStreamObserver.m ================================================================== --- src/OFStreamObserver.m +++ src/OFStreamObserver.m @@ -27,12 +27,12 @@ #import "OFStreamObserver.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFStream.h" #import "OFDataArray.h" -#ifdef _WIN32 -# import "OFTCPSocket.h" +#ifndef OF_HAVE_PIPE +# import "OFStreamSocket.h" #endif #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFDate.h" @@ -96,11 +96,11 @@ - init { self = [super init]; @try { -#ifdef _WIN32 +#ifndef OF_HAVE_PIPE struct sockaddr_in cancelAddr2; socklen_t cancelAddrLen; #endif _readStreams = [[OFMutableArray alloc] init]; @@ -108,17 +108,17 @@ _queue = [[OFMutableArray alloc] init]; _queueInfo = [[OFDataArray alloc] initWithItemSize: sizeof(int)]; _queueFDs = [[OFDataArray alloc] initWithItemSize: sizeof(int)]; -#ifndef _WIN32 +#ifdef OF_HAVE_PIPE if (pipe(_cancelFD)) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; #else - /* Make sure WSAStartup has been called */ - [OFTCPSocket class]; + /* Make sure network has been initialized */ + [OFStreamSocket class]; _cancelFD[0] = socket(AF_INET, SOCK_DGRAM, 0); _cancelFD[1] = socket(AF_INET, SOCK_DGRAM, 0); if (_cancelFD[0] == INVALID_SOCKET || @@ -136,11 +136,10 @@ (struct sockaddr*)&cancelAddr2, sizeof(cancelAddr2))) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; cancelAddrLen = sizeof(_cancelAddr); - if (getsockname(_cancelFD[0], (struct sockaddr*)&_cancelAddr, &cancelAddrLen)) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; #endif @@ -385,11 +384,11 @@ return [self observeForTimeInterval: [date timeIntervalSinceNow]]; } - (void)cancel { -#ifndef _WIN32 +#ifdef OF_HAVE_PIPE OF_ENSURE(write(_cancelFD[1], "", 1) > 0); #else OF_ENSURE(sendto(_cancelFD[1], "", 1, 0, (struct sockaddr*)&_cancelAddr, sizeof(_cancelAddr)) > 0); #endif Index: src/OFStreamObserver_poll.m ================================================================== --- src/OFStreamObserver_poll.m +++ src/OFStreamObserver_poll.m @@ -17,11 +17,14 @@ #include "config.h" #define __NO_EXT_QNX #include -#include + +#ifdef HAVE_POLL_H +# include +#endif #import "OFStreamObserver_poll.h" #import "OFDataArray.h" #import "OFOutOfRangeException.h" Index: src/OFStreamSocket.m ================================================================== --- src/OFStreamSocket.m +++ src/OFStreamSocket.m @@ -22,21 +22,17 @@ #include #include -#ifndef _WIN32 -# include +#include +#ifdef OF_HAVE_SYS_SOCKET_H # include #endif #import "OFStreamSocket.h" -#ifdef _WIN32 -# include -#endif - #import "OFInitializationFailedException.h" #import "OFNotConnectedException.h" #import "OFReadFailedException.h" #import "OFSetOptionFailedException.h" #import "OFWriteFailedException.h" Index: src/OFTCPSocket.h ================================================================== --- src/OFTCPSocket.h +++ src/OFTCPSocket.h @@ -19,14 +19,12 @@ #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif -#ifndef _WIN32 -# include +#ifdef OF_HAVE_SYS_SOCKET_H # include -# include #endif #import "OFStreamSocket.h" #ifdef _WIN32 Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -25,13 +25,17 @@ #include #include -#ifndef _WIN32 +#ifdef HAVE_NETINET_IN_H # include +#endif +#ifdef HAVE_ARPA_INET_H # include +#endif +#ifdef HAVE_NETDB_H # include #endif #import "OFTCPSocket.h" #import "OFTCPSocket+SOCKS5.h" @@ -66,10 +70,14 @@ # endif # ifndef AI_NUMERICHOST # define AI_NUMERICHOST 0 # endif #endif + +#ifndef SOMAXCONN +# define SOMAXCONN 32 +#endif #if defined(OF_HAVE_THREADS) && !defined(HAVE_THREADSAFE_GETADDRINFO) # import "OFMutex.h" # import "OFDataArray.h" Index: src/exceptions/common.h ================================================================== --- src/exceptions/common.h +++ src/exceptions/common.h @@ -13,31 +13,32 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include +#include #import "macros.h" + +#ifdef HAVE_NETDB_H +# include +#endif #ifndef _WIN32 -# if defined(OF_HAVE_SOCKETS) && !defined(HAVE_THREADSAFE_GETADDRINFO) -# include -# endif -# include # define GET_ERRNO errno # ifdef OF_HAVE_SOCKETS -# ifndef HAVE_THREADSAFE_GETADDRINFO +# if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(HAVE_H_ERRNO) # define GET_AT_ERRNO h_errno # else # define GET_AT_ERRNO errno # endif # define GET_SOCK_ERRNO errno # endif # define ERRFMT "Error string was: %s" # define ERRPARAM strerror(_errNo) # ifdef OF_HAVE_SOCKETS -# ifndef HAVE_THREADSAFE_GETADDRINFO +# if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(HAVE_HSTRERROR) # define AT_ERRPARAM hstrerror(_errNo) # else # define AT_ERRPARAM strerror(_errNo) # endif # endif Index: src/objfw-defs.h.in ================================================================== --- src/objfw-defs.h.in +++ src/objfw-defs.h.in @@ -9,16 +9,18 @@ #undef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR #undef OF_HAVE_GCC_ATOMIC_OPS #undef OF_HAVE_LINK #undef OF_HAVE_OSATOMIC #undef OF_HAVE_OSATOMIC_64 -#undef OF_HAVE_PTHREADS +#undef OF_HAVE_PIPE #undef OF_HAVE_PLUGINS #undef OF_HAVE_PROCESSES +#undef OF_HAVE_PTHREADS #undef OF_HAVE_PTHREAD_SPINLOCKS #undef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES #undef OF_HAVE_SCHED_YIELD #undef OF_HAVE_SOCKETS #undef OF_HAVE_SYMLINK +#undef OF_HAVE_SYS_SOCKET_H #undef OF_HAVE_THREADS #undef OF_OBJFW_RUNTIME #undef SIZE_MAX