Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -571,119 +571,131 @@ AC_DEFINE(OF_HAVE_ATOMIC_OPS, 1, [Whether we have atomic operations]) AC_SUBST(ATOMIC_H, "atomic.h") ]) AC_MSG_RESULT($atomic_ops) -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_FUNC(gmtime_r, [ AC_DEFINE(HAVE_GMTIME_R, 1, [Whether we have gmtime_r]) ]) AC_CHECK_FUNC(localtime_r, [ AC_DEFINE(HAVE_LOCALTIME_R, 1, [Whether we have localtime_r]) ]) -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, [ - AC_DEFINE(HAVE_POLL_H, 1, [Whether we have poll.h]) - AC_SUBST(OFSTREAMOBSERVER_POLL_M, "OFStreamObserver_poll.m") -]) -AC_CHECK_HEADERS(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") - ;; -esac - -AC_MSG_CHECKING(for getaddrinfo) -AC_TRY_COMPILE([ - #include - #ifndef _WIN32 - # include - # include - # include - #else - typedef unsigned char BOOL; - # include - #endif -], [ - struct addrinfo ai; - getaddrinfo(NULL, NULL, NULL, NULL); -], [ - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_GETADDRINFO, 1, [Whether we have getaddrinfo]) - - AS_IF([test x"$enable_threads" != x"no"], [ - AC_MSG_CHECKING(whether getaddrinfo is thread-safe) - - case "$host_os" in - darwin[[12345]].*) - have_threadsafe_getaddrinfo="no" - ;; - darwin*) - have_threadsafe_getaddrinfo="yes" - ;; - freebsd[[1234]].* | freebsd5.[[1234]]*) - have_threadsafe_getaddrinfo="no" - ;; - freebsd*) - have_threadsafe_getaddrinfo="yes" - ;; - netbsd[[123]].*) - have_threadsafe_getaddrinfo="no" - ;; - netbsd*) - have_threadsafe_getaddrinfo="yes" - ;; - solaris*) - have_threadsafe_getaddrinfo="yes" - ;; - *) - have_threadsafe_getaddrinfo="unknown" - ;; - esac - - AS_IF([test x"$have_threadsafe_getaddrinfo" = x"unknown"], [ - AC_EGREP_CPP(yes, [ - #ifndef _WIN32 - # include - # include - # include - #else - # define _WIN32_WINNT 0x0501 - # include - # include - #endif - - #ifdef h_errno - yes - #end - ], [ - have_threadsafe_getaddrinfo="yes" - ], [ - have_threadsafe_getaddrinfo="no" - ]) - ]) - - AS_IF([test x"$have_threadsafe_getaddrinfo" = x"yes"], [ - AC_DEFINE(HAVE_THREADSAFE_GETADDRINFO, 1, - [Whether getaddrinfo is thread-safe]) - ]) - - AC_MSG_RESULT($have_threadsafe_getaddrinfo) - ]) -], [ - AC_MSG_RESULT(no) +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]) + AC_SUBST(USE_SRCS_SOCKETS, '${SRCS_SOCKETS}') + + 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_FUNC(kqueue, [ + AC_DEFINE(HAVE_KQUEUE, 1, [Whether we have kqueue]) + AC_SUBST(OFSTREAMOBSERVER_KQUEUE_M, "OFStreamObserver_kqueue.m") + ]) + AC_CHECK_HEADER(poll.h, [ + AC_DEFINE(HAVE_POLL_H, 1, [Whether we have poll.h]) + AC_SUBST(OFSTREAMOBSERVER_POLL_M, "OFStreamObserver_poll.m") + ]) + AC_CHECK_HEADERS(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") + ;; + esac + + AC_MSG_CHECKING(for getaddrinfo) + AC_TRY_COMPILE([ + #include + #ifndef _WIN32 + # include + # include + # include + #else + typedef unsigned char BOOL; + # include + #endif + ], [ + struct addrinfo ai; + getaddrinfo(NULL, NULL, NULL, NULL); + ], [ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_GETADDRINFO, 1, [Whether we have getaddrinfo]) + + AS_IF([test x"$enable_threads" != x"no"], [ + AC_MSG_CHECKING(whether getaddrinfo is thread-safe) + + case "$host_os" in + darwin[[12345]].*) + have_threadsafe_getaddrinfo="no" + ;; + darwin*) + have_threadsafe_getaddrinfo="yes" + ;; + freebsd[[1234]].* | freebsd5.[[1234]]*) + have_threadsafe_getaddrinfo="no" + ;; + freebsd*) + have_threadsafe_getaddrinfo="yes" + ;; + netbsd[[123]].*) + have_threadsafe_getaddrinfo="no" + ;; + netbsd*) + have_threadsafe_getaddrinfo="yes" + ;; + solaris*) + have_threadsafe_getaddrinfo="yes" + ;; + *) + have_threadsafe_getaddrinfo="unknown" + ;; + esac + + AS_IF([test x"$have_threadsafe_getaddrinfo" = \ + x"unknown"], [ + AC_EGREP_CPP(yes, [ + #ifndef _WIN32 + # include + # include + # include + #else + # define _WIN32_WINNT 0x0501 + # include + # include + #endif + + #ifdef h_errno + yes + #end + ], [ + have_threadsafe_getaddrinfo="yes" + ], [ + have_threadsafe_getaddrinfo="no" + ]) + ]) + + AS_IF([test x"$have_threadsafe_getaddrinfo" = x"yes"], [ + AC_DEFINE(HAVE_THREADSAFE_GETADDRINFO, 1, + [Whether getaddrinfo is thread-safe]) + ]) + + AC_MSG_RESULT($have_threadsafe_getaddrinfo) + ]) + ], [ + AC_MSG_RESULT(no) + ]) +]) + +AS_IF([test x"$enable_sockets" != x"no" -a x"$enable_threads" != x"no"], [ + AC_SUBST(OFHTTPCLIENTTESTS_M, "OFHTTPClientTests.m") ]) AS_IF([test x"$objc_runtime" = x"Apple runtime"], [ AC_CHECK_HEADER(Foundation/NSObject.h, [ AC_SUBST(FOUNDATION_COMPAT_M, "foundation-compat.m") Index: extra.mk.in ================================================================== --- extra.mk.in +++ extra.mk.in @@ -21,10 +21,11 @@ FORWARDING_S = @FORWARDING_S@ FOUNDATION_COMPAT_M = @FOUNDATION_COMPAT_M@ INSTANCE_M = @INSTANCE_M@ LOOKUP_S = @LOOKUP_S@ OFBLOCKTESTS_M = @OFBLOCKTESTS_M@ +OFHTTPCLIENTTESTS_M = @OFHTTPCLIENTTESTS_M@ OFSTREAMOBSERVER_KQUEUE_M = @OFSTREAMOBSERVER_KQUEUE_M@ OFSTREAMOBSERVER_POLL_M = @OFSTREAMOBSERVER_POLL_M@ OFSTREAMOBSERVER_SELECT_M = @OFSTREAMOBSERVER_SELECT_M@ PROPERTIESTESTS_M = @PROPERTIESTESTS_M@ REEXPORT_LIBOBJC = @REEXPORT_LIBOBJC@ @@ -36,6 +37,7 @@ TESTPLUGIN = @TESTPLUGIN@ TESTS = @TESTS@ TEST_LAUNCHER = @TEST_LAUNCHER@ USE_INCLUDES_THREADS = @USE_INCLUDES_THREADS@ USE_SRCS_PLUGINS = @USE_SRCS_PLUGINS@ +USE_SRCS_SOCKETS = @USE_SRCS_SOCKETS@ USE_SRCS_THREADS = @USE_SRCS_THREADS@ Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -19,14 +19,10 @@ OFDataArray+Hashing.m \ OFDate.m \ OFDictionary.m \ OFEnumerator.m \ OFFile.m \ - OFHTTPClient.m \ - OFHTTPRequest.m \ - OFHTTPRequestReply.m \ - OFHTTPServer.m \ OFIntrospection.m \ OFList.m \ OFMapTable.m \ OFMD5Hash.m \ OFMutableArray.m \ @@ -42,21 +38,18 @@ OFSeekableStream.m \ OFSet.m \ OFSHA1Hash.m \ OFSortedList.m \ OFStream.m \ - OFStreamObserver.m \ - OFStreamSocket.m \ OFString.m \ OFString+Hashing.m \ OFString+JSONValue.m \ OFString+Serialization.m \ OFString+URLEncoding.m \ OFString+XMLEscaping.m \ OFString+XMLUnescaping.m \ OFSystemInfo.m \ - OFTCPSocket.m \ OFTimer.m \ OFURL.m \ OFXMLAttribute.m \ OFXMLCDATA.m \ OFXMLCharacters.m \ @@ -70,12 +63,20 @@ base64.m \ of_asprintf.m \ of_strptime.m \ unicode.m \ ${USE_SRCS_PLUGINS} \ + ${USE_SRCS_SOCKETS} \ ${USE_SRCS_THREADS} SRCS_PLUGINS = OFPlugin.m +SRCS_SOCKETS = OFHTTPClient.m \ + OFHTTPRequest.m \ + OFHTTPRequestReply.m \ + OFHTTPServer.m \ + OFStreamObserver.m \ + OFStreamSocket.m \ + OFTCPSocket.m SRCS_THREADS = OFCondition.m \ OFMutex.m \ OFRecursiveMutex.m \ OFThread.m \ OFThreadPool.m \ @@ -109,20 +110,20 @@ OFMutableArray_adjacent.m \ OFMutableDictionary_hashtable.m \ OFMutableSet_hashtable.m \ OFMutableString_UTF8.m \ OFSet_hashtable.m \ - ${OFSTREAMOBSERVER_KQUEUE_M} \ - ${OFSTREAMOBSERVER_POLL_M} \ - ${OFSTREAMOBSERVER_SELECT_M} \ OFString_UTF8.m \ - OFTCPSocket+SOCKS5.m \ ${ASPRINTF_M} \ ${FORWARDING_S} \ ${FOUNDATION_COMPAT_M} \ iso_8859_15.m \ windows_1252.m +SRCS_SOCKETS += ${OFSTREAMOBSERVER_KQUEUE_M} \ + ${OFSTREAMOBSERVER_POLL_M} \ + ${OFSTREAMOBSERVER_SELECT_M} \ + OFTCPSocket+SOCKS5.m OBJS_EXTRA = ${EXCEPTIONS_EXCEPTIONS_A} ${RUNTIME_RUNTIME_A} LIB_OBJS_EXTRA = ${EXCEPTIONS_EXCEPTIONS_LIB_A} ${RUNTIME_RUNTIME_LIB_A} include ../buildsys.mk Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -22,23 +22,28 @@ #import "OFDataArray.h" #import "OFString.h" #import "OFFile.h" #import "OFURL.h" -#import "OFHTTPClient.h" -#import "OFHTTPRequest.h" -#import "OFHTTPRequestReply.h" +#ifdef OF_HAVE_SOCKETS +# import "OFHTTPClient.h" +# import "OFHTTPRequest.h" +# import "OFHTTPRequestReply.h" +#endif #import "OFDictionary.h" #import "OFXMLElement.h" #import "OFSystemInfo.h" -#import "OFHTTPRequestFailedException.h" +#ifdef OF_HAVE_SOCKETS +# import "OFHTTPRequestFailedException.h" +#endif #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" +#import "OFUnsupportedProtocolException.h" #import "autorelease.h" #import "base64.h" #import "macros.h" @@ -161,22 +166,25 @@ } - initWithContentsOfURL: (OFURL*)URL { void *pool; +#ifdef OF_HAVE_SOCKETS OFHTTPClient *client; OFHTTPRequest *request; OFHTTPRequestReply *reply; OFDictionary *headers; OFString *contentLength; +#endif Class c; c = [self class]; [self release]; pool = objc_autoreleasePoolPush(); +#ifdef OF_HAVE_SOCKETS if ([[URL scheme] isEqual: @"file"]) { self = [[c alloc] initWithContentsOfFile: [URL path]]; objc_autoreleasePoolPop(pool); return self; } @@ -200,10 +208,13 @@ headers = [reply headers]; if ((contentLength = [headers objectForKey: @"Content-Length"]) != nil) if ([self count] != (size_t)[contentLength decimalValue]) @throw [OFTruncatedDataException exceptionWithClass: [self class]]; +#else + @throw [OFUnsupportedProtocolException exceptionWithClass: c]; +#endif objc_autoreleasePoolPop(pool); return self; } Index: src/OFHTTPClient.h ================================================================== --- src/OFHTTPClient.h +++ src/OFHTTPClient.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif @class OFHTTPClient; @class OFHTTPRequest; @class OFHTTPRequestReply; @class OFURL; Index: src/OFHTTPRequest.h ================================================================== --- src/OFHTTPRequest.h +++ src/OFHTTPRequest.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif @class OFURL; @class OFDictionary; @class OFDataArray; @class OFString; Index: src/OFHTTPRequestReply.h ================================================================== --- src/OFHTTPRequestReply.h +++ src/OFHTTPRequestReply.h @@ -14,10 +14,14 @@ * file. */ #import "OFStream.h" #import "OFHTTPRequest.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif @class OFDictionary; /*! * @brief A class for representing an HTTP request reply as a stream. Index: src/OFHTTPServer.h ================================================================== --- src/OFHTTPServer.h +++ src/OFHTTPServer.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif @class OFHTTPServer; @class OFHTTPRequest; @class OFHTTPRequestReply; @class OFTCPSocket; Index: src/OFRunLoop.h ================================================================== --- src/OFRunLoop.h +++ src/OFRunLoop.h @@ -14,11 +14,13 @@ * file. */ #import "OFObject.h" #import "OFStream.h" -#import "OFTCPSocket.h" +#ifdef OF_HAVE_SOCKETS +# import "OFTCPSocket.h" +#endif @class OFSortedList; #ifdef OF_HAVE_THREADS @class OFMutex; #endif @@ -33,12 +35,14 @@ { OFSortedList *_timersQueue; #ifdef OF_HAVE_THREADS OFMutex *_timersQueueLock; #endif +#ifdef OF_HAVE_SOCKETS OFStreamObserver *_streamObserver; OFMutableDictionary *_readQueues; +#endif volatile bool _running; } /*! * @brief Returns the main run loop. @@ -53,10 +57,11 @@ * @return The run loop for the current thread */ + (OFRunLoop*)currentRunLoop; + (void)OF_setMainRunLoop: (OFRunLoop*)runLoop; +#ifdef OF_HAVE_SOCKETS + (void)OF_addAsyncReadForStream: (OFStream*)stream buffer: (void*)buffer length: (size_t)length target: (id)target selector: (SEL)selector; @@ -70,11 +75,11 @@ target: (id)target selector: (SEL)selector; + (void)OF_addAsyncAcceptForTCPSocket: (OFTCPSocket*)socket target: (id)target selector: (SEL)selector; -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS + (void)OF_addAsyncReadForStream: (OFStream*)stream buffer: (void*)buffer length: (size_t)length block: (of_stream_async_read_block_t)block; + (void)OF_addAsyncReadForStream: (OFStream*)stream @@ -84,12 +89,13 @@ + (void)OF_addAsyncReadLineForStream: (OFStream*)stream encoding: (of_string_encoding_t)encoding block: (of_stream_async_read_line_block_t)block; + (void)OF_addAsyncAcceptForTCPSocket: (OFTCPSocket*)socket block: (of_tcpsocket_async_accept_block_t)block; -#endif +# endif + (void)OF_cancelAsyncRequestsForStream: (OFStream*)stream; +#endif /*! * @brief Adds an OFTimer to the run loop. * * @param timer The timer to add Index: src/OFRunLoop.m ================================================================== --- src/OFRunLoop.m +++ src/OFRunLoop.m @@ -18,11 +18,13 @@ #include #import "OFRunLoop.h" #import "OFDictionary.h" -#import "OFStreamObserver.h" +#ifdef OF_HAVE_SOCKETS +# import "OFStreamObserver.h" +#endif #ifdef OF_HAVE_THREADS # import "OFThread.h" # import "OFMutex.h" #endif #import "OFSortedList.h" @@ -32,10 +34,11 @@ #import "autorelease.h" #import "macros.h" static OFRunLoop *mainRunLoop = nil; +#ifdef OF_HAVE_SOCKETS @interface OFRunLoop_QueueItem: OFObject { @public id _target; SEL _selector; @@ -43,45 +46,45 @@ @end @interface OFRunLoop_ReadQueueItem: OFRunLoop_QueueItem { @public -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS of_stream_async_read_block_t _block; -#endif +# endif void *_buffer; size_t _length; } @end @interface OFRunLoop_ExactReadQueueItem: OFRunLoop_QueueItem { @public -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS of_stream_async_read_block_t _block; -#endif +# endif void *_buffer; size_t _exactLength, _readLength; } @end @interface OFRunLoop_ReadLineQueueItem: OFRunLoop_QueueItem { @public -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS of_stream_async_read_line_block_t _block; -#endif +# endif of_string_encoding_t _encoding; } @end @interface OFRunLoop_AcceptQueueItem: OFRunLoop_QueueItem { @public -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS of_tcpsocket_async_accept_block_t _block; -#endif +# endif } @end @implementation OFRunLoop_QueueItem - (void)dealloc @@ -91,52 +94,53 @@ [super dealloc]; } @end @implementation OFRunLoop_ReadQueueItem -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS +- (void)dealloc +{ + [_block release]; + + [super dealloc]; +} +# endif +@end + +@implementation OFRunLoop_ExactReadQueueItem +# ifdef OF_HAVE_BLOCKS - (void)dealloc { [_block release]; [super dealloc]; } -#endif +# endif @end -@implementation OFRunLoop_ExactReadQueueItem -#ifdef OF_HAVE_BLOCKS +@implementation OFRunLoop_ReadLineQueueItem +# ifdef OF_HAVE_BLOCKS - (void)dealloc { [_block release]; [super dealloc]; } -#endif +# endif @end -@implementation OFRunLoop_ReadLineQueueItem -#ifdef OF_HAVE_BLOCKS +@implementation OFRunLoop_AcceptQueueItem +# ifdef OF_HAVE_BLOCKS - (void)dealloc { [_block release]; [super dealloc]; } -#endif -@end - -@implementation OFRunLoop_AcceptQueueItem -#ifdef OF_HAVE_BLOCKS -- (void)dealloc -{ - [_block release]; - - [super dealloc]; -} -#endif -@end +# endif +@end +#endif @implementation OFRunLoop + (OFRunLoop*)mainRunLoop { return [[mainRunLoop retain] autorelease]; @@ -154,11 +158,12 @@ + (void)OF_setMainRunLoop: (OFRunLoop*)runLoop { mainRunLoop = [runLoop retain]; } -#define ADD(type, code) \ +#ifdef OF_HAVE_SOCKETS +# define ADD(type, code) \ void *pool = objc_autoreleasePoolPush(); \ OFRunLoop *runLoop = [self currentRunLoop]; \ OFList *queue = [runLoop->_readQueues objectForKey: stream]; \ type *queueItem; \ \ @@ -225,11 +230,11 @@ queueItem->_target = [target retain]; queueItem->_selector = selector; }) } -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS + (void)OF_addAsyncReadForStream: (OFStream*)stream buffer: (void*)buffer length: (size_t)length block: (of_stream_async_read_block_t)block { @@ -267,13 +272,12 @@ { ADD(OFRunLoop_AcceptQueueItem, { queueItem->_block = [block copy]; }) } -#endif - -#undef ADD +# endif +# undef ADD + (void)OF_cancelAsyncRequestsForStream: (OFStream*)stream { void *pool = objc_autoreleasePoolPush(); OFRunLoop *runLoop = [self currentRunLoop]; @@ -286,10 +290,11 @@ [runLoop->_readQueues removeObjectForKey: stream]; } objc_autoreleasePoolPop(pool); } +#endif - init { self = [super init]; @@ -297,14 +302,16 @@ _timersQueue = [[OFSortedList alloc] init]; #ifdef OF_HAVE_THREADS _timersQueueLock = [[OFMutex alloc] init]; #endif +#ifdef OF_HAVE_SOCKETS _streamObserver = [[OFStreamObserver alloc] init]; [_streamObserver setDelegate: self]; _readQueues = [[OFMutableDictionary alloc] init]; +#endif } @catch (id e) { [self release]; @throw e; } @@ -315,12 +322,14 @@ { [_timersQueue release]; #ifdef OF_HAVE_THREADS [_timersQueueLock release]; #endif +#ifdef OF_HAVE_SOCKETS [_streamObserver release]; [_readQueues release]; +#endif [super dealloc]; } - (void)addTimer: (OFTimer*)timer @@ -336,11 +345,17 @@ } #endif [timer OF_setInRunLoop: self]; +#ifdef OF_HAVE_SOCKETS [_streamObserver cancel]; +#endif + +#if defined(OF_HAVE_THREADS) && !defined(OF_HAVE_SOCKETS) + /* FIXME: No way to cancel waiting! What to do? */ +#endif } - (void)OF_removeTimer: (OFTimer*)timer { #ifdef OF_HAVE_THREADS @@ -361,10 +376,11 @@ [_timersQueueLock unlock]; } #endif } +#ifdef OF_HAVE_SOCKETS - (void)streamIsReadyForReading: (OFStream*)stream { OFList *queue = [_readQueues objectForKey: stream]; of_list_object_t *listObject; @@ -384,11 +400,11 @@ } @catch (OFException *e) { length = 0; exception = e; } -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS if (queueItem->_block != NULL) { if (!queueItem->_block(stream, queueItem->_buffer, length, exception)) { [queue removeListObject: listObject]; @@ -398,11 +414,11 @@ [_readQueues removeObjectForKey: stream]; } } } else { -#endif +# endif bool (*func)(id, SEL, OFStream*, void*, size_t, OFException*) = (bool(*)(id, SEL, OFStream*, void*, size_t, OFException*)) [queueItem->_target methodForSelector: queueItem->_selector]; @@ -416,13 +432,13 @@ removeStreamForReading: stream]; [_readQueues removeObjectForKey: stream]; } } -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS } -#endif +# endif } else if ([listObject->object isKindOfClass: [OFRunLoop_ExactReadQueueItem class]]) { OFRunLoop_ExactReadQueueItem *queueItem = listObject->object; size_t length; OFException *exception = nil; @@ -439,11 +455,11 @@ } queueItem->_readLength += length; if (queueItem->_readLength == queueItem->_exactLength || [stream isAtEndOfStream] || exception != nil) { -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS if (queueItem->_block != NULL) { if (queueItem->_block(stream, queueItem->_buffer, queueItem->_readLength, exception)) queueItem->_readLength = 0; @@ -457,11 +473,11 @@ [_readQueues removeObjectForKey: stream]; } } } else { -#endif +# endif bool (*func)(id, SEL, OFStream*, void*, size_t, OFException*) = (bool(*)(id, SEL, OFStream*, void*, size_t, OFException*)) [queueItem->_target methodForSelector: queueItem->_selector]; @@ -480,13 +496,13 @@ stream]; [_readQueues removeObjectForKey: stream]; } } -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS } -#endif +# endif } } else if ([listObject->object isKindOfClass: [OFRunLoop_ReadLineQueueItem class]]) { OFRunLoop_ReadLineQueueItem *queueItem = listObject->object; OFString *line; @@ -500,11 +516,11 @@ exception = e; } if (line != nil || [stream isAtEndOfStream] || exception != nil) { -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS if (queueItem->_block != NULL) { if (!queueItem->_block(stream, line, exception)) { [queue removeListObject: listObject]; @@ -515,11 +531,11 @@ [_readQueues removeObjectForKey: stream]; } } } else { -#endif +# endif bool (*func)(id, SEL, OFStream*, OFString*, OFException*) = (bool(*)(id, SEL, OFStream*, OFString*, OFException*)) [queueItem->_target methodForSelector: queueItem->_selector]; @@ -535,13 +551,13 @@ stream]; [_readQueues removeObjectForKey: stream]; } } -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS } -#endif +# endif } } else if ([listObject->object isKindOfClass: [OFRunLoop_AcceptQueueItem class]]) { OFRunLoop_AcceptQueueItem *queueItem = listObject->object; OFTCPSocket *newSocket; @@ -552,11 +568,11 @@ } @catch (OFException *e) { newSocket = nil; exception = e; } -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS if (queueItem->_block != NULL) { if (!queueItem->_block((OFTCPSocket*)stream, newSocket, exception)) { [queue removeListObject: listObject]; @@ -566,11 +582,11 @@ [_readQueues removeObjectForKey: stream]; } } } else { -#endif +# endif bool (*func)(id, SEL, OFTCPSocket*, OFTCPSocket*, OFException*) = (bool(*)(id, SEL, OFTCPSocket*, OFTCPSocket*, OFException*)) [queueItem->_target methodForSelector: @@ -585,16 +601,17 @@ removeStreamForReading: stream]; [_readQueues removeObjectForKey: stream]; } } -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS } -#endif +# endif } else OF_ENSURE(0); } +#endif - (void)run { _running = true; @@ -654,18 +671,26 @@ /* Watch for stream events until the next timer is due */ if (nextTimer != nil) { double timeout = [nextTimer timeIntervalSinceNow]; if (timeout > 0) +#ifdef OF_HAVE_SOCKETS [_streamObserver observeWithTimeout: timeout]; +#else + [OFThread sleepForTimeInterval: timeout]; +#endif } else { /* * No more timers: Just watch for streams until we get * an event. If a timer is added by another thread, it * cancels the observe. */ +#ifdef OF_HAVE_SOCKETS [_streamObserver observe]; +#else + [OFThread sleepForTimeInterval: 86400]; +#endif } objc_autoreleasePoolPop(pool); } } @@ -674,8 +699,14 @@ { _running = false; #ifdef OF_HAVE_THREADS of_memory_write_barrier(); #endif +#ifdef OF_HAVE_SOCKETS [_streamObserver cancel]; +#endif + +#if defined(OF_HAVE_THREADS) && !defined(OF_HAVE_SOCKETS) + /* FIXME: No way to cancel waiting! What to do? */ +#endif } @end Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -30,11 +30,11 @@ @class OFStream; @class OFDataArray; @class OFException; -#ifdef OF_HAVE_BLOCKS +#if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_BLOCKS) /*! * @brief A block which is called when data was read from the stream. * * @param stream The stream on which data was read * @param buffer A buffer with the data that has been read @@ -128,10 +128,11 @@ * The buffer *must* be *at least* this big! */ - (void)readIntoBuffer: (void*)buffer exactLength: (size_t)length; +#ifdef OF_HAVE_SOCKETS /*! * @brief Asyncronously reads *at most* size bytes from the stream into a * buffer. * * On network streams, this might read less than the specified number of bytes. @@ -184,11 +185,11 @@ - (void)asyncReadIntoBuffer: (void*)buffer exactLength: (size_t)length target: (id)target selector: (SEL)selector; -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS /*! * @brief Asyncronously reads *at most* ref size bytes from the stream into a * buffer. * * On network streams, this might read less than the specified number of bytes. @@ -230,10 +231,11 @@ * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void*)buffer exactLength: (size_t)length block: (of_stream_async_read_block_t)block; +# endif #endif /*! * @brief Reads a uint8_t from the stream. * @@ -578,10 +580,11 @@ * @return The line that was read, autoreleased, or nil if the end of the * stream has been reached. */ - (OFString*)readLineWithEncoding: (of_string_encoding_t)encoding; +#ifdef OF_HAVE_SOCKETS /*! * @brief Asyncronously reads until a newline, \\0, end of stream or an * exception occurs. * * @param target The target on which to call the selector when the data has @@ -612,11 +615,11 @@ */ - (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding target: (id)target selector: (SEL)selector; -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS /*! * @brief Asyncronously reads until a newline, \\0, end of stream or an * exception occurs. * * @param block The block to call when the data has been received. @@ -638,10 +641,11 @@ * to handle the next line, you need to return false from the * block. */ - (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding block: (of_stream_async_read_line_block_t)block; +# endif #endif /*! * @brief Tries to read a line from the stream (see readLine) and returns nil if * no complete line has been received yet. @@ -1039,14 +1043,16 @@ * * @return The file descriptor for the write end of the stream */ - (int)fileDescriptorForWriting; +#ifdef OF_HAVE_SOCKETS /*! * @brief Cancels all pending asyncronous requests on the stream. */ - (void)cancelAsyncRequests; +#endif /*! * @brief Closes the stream. */ - (void)close; Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -146,10 +146,11 @@ while (readLength < length) readLength += [self readIntoBuffer: (char*)buffer + readLength length: length - readLength]; } +#ifdef OF_HAVE_SOCKETS - (void)asyncReadIntoBuffer: (void*)buffer length: (size_t)length target: (id)target selector: (SEL)selector { @@ -170,11 +171,11 @@ exactLength: length target: target selector: selector]; } -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS - (void)asyncReadIntoBuffer: (void*)buffer length: (size_t)length block: (of_stream_async_read_block_t)block { [OFRunLoop OF_addAsyncReadForStream: self @@ -190,10 +191,11 @@ [OFRunLoop OF_addAsyncReadForStream: self buffer: buffer exactLength: length block: block]; } +# endif #endif - (uint8_t)readInt8 { uint8_t ret; @@ -731,10 +733,11 @@ return nil; return line; } +#ifdef OF_HAVE_SOCKETS - (void)asyncReadLineWithTarget: (id)target selector: (SEL)selector { [self asyncReadLineWithEncoding: OF_STRING_ENCODING_UTF_8 target: target @@ -749,11 +752,11 @@ encoding: encoding target: target selector: selector]; } -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS - (void)asyncReadLineWithBlock: (of_stream_async_read_line_block_t)block { [self asyncReadLineWithEncoding: OF_STRING_ENCODING_UTF_8 block: block]; } @@ -763,10 +766,11 @@ { [OFRunLoop OF_addAsyncReadLineForStream: self encoding: encoding block: block]; } +# endif #endif - (OFString*)tryReadLine { return [self tryReadLineWithEncoding: OF_STRING_ENCODING_UTF_8]; @@ -1551,14 +1555,16 @@ { [self doesNotRecognizeSelector: _cmd]; abort(); } +#ifdef OF_HAVE_SOCKETS - (void)cancelAsyncRequests { [OFRunLoop OF_cancelAsyncRequestsForStream: self]; } +#endif - (void)close { [self doesNotRecognizeSelector: _cmd]; abort(); Index: src/OFStreamObserver.h ================================================================== --- src/OFStreamObserver.h +++ src/OFStreamObserver.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif #ifdef _WIN32 # include #endif Index: src/OFStreamSocket.h ================================================================== --- src/OFStreamSocket.h +++ src/OFStreamSocket.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFStream.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif #ifdef _WIN32 # include #endif Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -26,26 +26,31 @@ #import "OFString_UTF8.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFFile.h" #import "OFURL.h" -#import "OFHTTPClient.h" -#import "OFHTTPRequest.h" -#import "OFHTTPRequestReply.h" +#ifdef OF_HAVE_SOCKETS +# import "OFHTTPClient.h" +# import "OFHTTPRequest.h" +# import "OFHTTPRequestReply.h" +#endif #import "OFDataArray.h" #import "OFXMLElement.h" -#import "OFHTTPRequestFailedException.h" +#ifdef OF_HAVE_SOCKETS +# import "OFHTTPRequestFailedException.h" +#endif #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOpenFileFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" +#import "OFUnsupportedProtocolException.h" #import "autorelease.h" #import "macros.h" #import "of_asprintf.h" #import "unicode.h" @@ -905,16 +910,18 @@ - initWithContentsOfURL: (OFURL*)URL encoding: (of_string_encoding_t)encoding { void *pool; +#ifdef OF_HAVE_SOCKETS OFHTTPClient *client; OFHTTPRequest *request; OFHTTPRequestReply *reply; OFDictionary *headers; OFString *contentType, *contentLength; OFDataArray *data; +#endif Class c; c = [self class]; [self release]; @@ -928,10 +935,11 @@ encoding: encoding]; objc_autoreleasePoolPop(pool); return self; } +#ifdef OF_HAVE_SOCKETS client = [OFHTTPClient client]; request = [OFHTTPRequest requestWithURL: URL]; reply = [client performRequest: request]; if ([reply statusCode] != 200) @@ -967,10 +975,13 @@ exceptionWithClass: [self class]]; self = [[c alloc] initWithCString: (char*)[data items] encoding: encoding length: [data count]]; +#else + @throw [OFUnsupportedProtocolException exceptionWithClass: c]; +#endif objc_autoreleasePoolPop(pool); return self; } Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -44,20 +44,23 @@ #import "OFDate.h" #import "OFURL.h" #import "OFStream.h" #import "OFFile.h" -#import "OFStreamSocket.h" -#import "OFTCPSocket.h" -#import "OFTLSSocket.h" -#import "OFProcess.h" -#import "OFStreamObserver.h" - -#import "OFHTTPRequest.h" -#import "OFHTTPRequestReply.h" -#import "OFHTTPClient.h" -#import "OFHTTPServer.h" +#ifdef OF_HAVE_SOCKETS +# import "OFStreamSocket.h" +# import "OFTCPSocket.h" +# import "OFTLSSocket.h" +# import "OFStreamObserver.h" + +# import "OFHTTPRequest.h" +# import "OFHTTPRequestReply.h" +# import "OFHTTPClient.h" +# import "OFHTTPServer.h" +#endif + +#import "OFProcess.h" #import "OFHash.h" #import "OFMD5Hash.h" #import "OFSHA1Hash.h" @@ -78,43 +81,53 @@ #import "OFTimer.h" #import "OFRunLoop.h" #import "OFAllocFailedException.h" #import "OFException.h" -#import "OFAcceptFailedException.h" -#import "OFAddressTranslationFailedException.h" -#import "OFAlreadyConnectedException.h" -#import "OFBindFailedException.h" +#ifdef OF_HAVE_SOCKETS +# import "OFAcceptFailedException.h" +# import "OFAddressTranslationFailedException.h" +# import "OFAlreadyConnectedException.h" +# import "OFBindFailedException.h" +#endif #import "OFChangeDirectoryFailedException.h" #import "OFChangeFileModeFailedException.h" #import "OFChangeFileOwnerFailedException.h" #ifdef OF_HAVE_THREADS # import "OFConditionBroadcastFailedException.h" # import "OFConditionSignalFailedException.h" # import "OFConditionStillWaitingException.h" # import "OFConditionWaitFailedException.h" #endif -#import "OFConnectionFailedException.h" +#ifdef OF_HAVE_SOCKETS +# import "OFConnectionFailedException.h" +#endif #import "OFCopyFileFailedException.h" #import "OFCreateDirectoryFailedException.h" #import "OFDeleteDirectoryFailedException.h" #import "OFDeleteFileFailedException.h" #import "OFEnumerationMutationException.h" #import "OFHashAlreadyCalculatedException.h" -#import "OFHTTPRequestFailedException.h" +#ifdef OF_HAVE_SOCKETS +# import "OFHTTPRequestFailedException.h" +#endif #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFInvalidJSONException.h" #import "OFInvalidServerReplyException.h" #import "OFLinkFailedException.h" -#import "OFListenFailedException.h" +#ifdef OF_HAVE_SOCKETS +# import "OFListenFailedException.h" +#endif #import "OFLockFailedException.h" #import "OFMalformedXMLException.h" #import "OFMemoryNotPartOfObjectException.h" -#import "OFNotConnectedException.h" +#ifdef OF_HAVE_SOCKETS +# import "OFNotConnectedException.h" +#endif #import "OFNotImplementedException.h" #import "OFOpenFileFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" Index: src/exceptions/Makefile ================================================================== --- src/exceptions/Makefile +++ src/exceptions/Makefile @@ -1,39 +1,31 @@ include ../../extra.mk STATIC_PIC_LIB_NOINST = ${EXCEPTIONS_LIB_A} STATIC_LIB_NOINST = ${EXCEPTIONS_A} -SRCS = OFAcceptFailedException.m \ - OFAddressTranslationFailedException.m \ - OFAllocFailedException.m \ - OFAlreadyConnectedException.m \ - OFBindFailedException.m \ +SRCS = OFAllocFailedException.m \ OFChangeDirectoryFailedException.m \ OFChangeFileModeFailedException.m \ OFChangeFileOwnerFailedException.m \ - OFConnectionFailedException.m \ OFCopyFileFailedException.m \ OFCreateDirectoryFailedException.m \ OFDeleteDirectoryFailedException.m \ OFDeleteFileFailedException.m \ OFEnumerationMutationException.m \ OFException.m \ - OFHTTPRequestFailedException.m \ OFHashAlreadyCalculatedException.m \ OFInitializationFailedException.m \ OFInvalidArgumentException.m \ OFInvalidEncodingException.m \ OFInvalidFormatException.m \ OFInvalidJSONException.m \ OFInvalidServerReplyException.m \ OFLinkFailedException.m \ - OFListenFailedException.m \ OFLockFailedException.m \ OFMalformedXMLException.m \ OFMemoryNotPartOfObjectException.m \ - OFNotConnectedException.m \ OFNotImplementedException.m \ OFOpenFileFailedException.m \ OFOutOfMemoryException.m \ OFOutOfRangeException.m \ OFReadFailedException.m \ @@ -47,11 +39,20 @@ OFUnboundNamespaceException.m \ OFUnlockFailedException.m \ OFUnsupportedProtocolException.m \ OFUnsupportedVersionException.m \ OFWriteFailedException.m \ + ${USE_SRCS_SOCKETS} \ ${USE_SRCS_THREADS} +SRCS_SOCKETS = OFAcceptFailedException.m \ + OFAddressTranslationFailedException.m \ + OFAlreadyConnectedException.m \ + OFBindFailedException.m \ + OFConnectionFailedException.m \ + OFHTTPRequestFailedException.m \ + OFListenFailedException.m \ + OFNotConnectedException.m SRCS_THREADS = OFConditionBroadcastFailedException.m \ OFConditionSignalFailedException.m \ OFConditionStillWaitingException.m \ OFConditionWaitFailedException.m \ OFThreadJoinFailedException.m \ Index: src/exceptions/OFAcceptFailedException.h ================================================================== --- src/exceptions/OFAcceptFailedException.h +++ src/exceptions/OFAcceptFailedException.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif @class OFTCPSocket; /*! * @brief An exception indicating that accepting a connection failed. Index: src/exceptions/OFAddressTranslationFailedException.h ================================================================== --- src/exceptions/OFAddressTranslationFailedException.h +++ src/exceptions/OFAddressTranslationFailedException.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif @class OFTCPSocket; /*! * @brief An exception indicating the translation of an address failed. Index: src/exceptions/OFAlreadyConnectedException.h ================================================================== --- src/exceptions/OFAlreadyConnectedException.h +++ src/exceptions/OFAlreadyConnectedException.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif @class OFTCPSocket; /*! * @brief An exception indicating an attempt to connect or bind an already Index: src/exceptions/OFBindFailedException.h ================================================================== --- src/exceptions/OFBindFailedException.h +++ src/exceptions/OFBindFailedException.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif @class OFTCPSocket; /*! * @brief An exception indicating that binding a socket failed. Index: src/exceptions/OFConnectionFailedException.h ================================================================== --- src/exceptions/OFConnectionFailedException.h +++ src/exceptions/OFConnectionFailedException.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif @class OFTCPSocket; /*! * @brief An exception indicating that a connection could not be established. Index: src/exceptions/OFHTTPRequestFailedException.h ================================================================== --- src/exceptions/OFHTTPRequestFailedException.h +++ src/exceptions/OFHTTPRequestFailedException.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif @class OFHTTPRequest; @class OFHTTPRequestReply; /*! Index: src/exceptions/OFListenFailedException.h ================================================================== --- src/exceptions/OFListenFailedException.h +++ src/exceptions/OFListenFailedException.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif @class OFTCPSocket; /*! * @brief An exception indicating that listening on the socket failed. Index: src/exceptions/OFNotConnectedException.h ================================================================== --- src/exceptions/OFNotConnectedException.h +++ src/exceptions/OFNotConnectedException.h @@ -13,10 +13,14 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif @class OFStreamSocket; /*! * @brief An exception indicating a socket is not connected or bound. Index: src/exceptions/OFReadOrWriteFailedException.m ================================================================== --- src/exceptions/OFReadOrWriteFailedException.m +++ src/exceptions/OFReadOrWriteFailedException.m @@ -18,11 +18,13 @@ #include #import "OFReadOrWriteFailedException.h" #import "OFString.h" -#import "OFStreamSocket.h" +#ifdef OF_HAVE_SOCKETS +# import "OFStreamSocket.h" +#endif #import "common.h" @implementation OFReadOrWriteFailedException + (instancetype)exceptionWithClass: (Class)class @@ -53,13 +55,15 @@ self = [super initWithClass: class]; _stream = [stream retain]; _requestedLength = requestedLength; +#ifdef OF_HAVE_SOCKETS if ([class isSubclassOfClass: [OFStreamSocket class]]) _errNo = GET_SOCK_ERRNO; else +#endif _errNo = GET_ERRNO; return self; } Index: src/exceptions/common.h ================================================================== --- src/exceptions/common.h +++ src/exceptions/common.h @@ -17,32 +17,40 @@ #include #import "macros.h" #ifndef _WIN32 -# if !defined(HAVE_THREADSAFE_GETADDRINFO) && !defined(_PSP) +# if defined(OF_HAVE_SOCKETS) && !defined(HAVE_THREADSAFE_GETADDRINFO) # include # endif # include # define GET_ERRNO errno -# ifndef HAVE_THREADSAFE_GETADDRINFO -# define GET_AT_ERRNO h_errno -# else -# define GET_AT_ERRNO errno -# endif +# ifdef OF_HAVE_SOCKETS +# ifndef HAVE_THREADSAFE_GETADDRINFO +# define GET_AT_ERRNO h_errno +# else +# define GET_AT_ERRNO errno +# endif # define GET_SOCK_ERRNO errno -# define ERRFMT "Error string was: %s" -# define ERRPARAM strerror(_errNo) -# if !defined(HAVE_THREADSAFE_GETADDRINFO) && !defined(_PSP) -# define AT_ERRPARAM hstrerror(_errNo) -# else -# define AT_ERRPARAM strerror(_errNo) +# endif +# define ERRFMT "Error string was: %s" +# define ERRPARAM strerror(_errNo) +# ifdef OF_HAVE_SOCKETS +# ifndef HAVE_THREADSAFE_GETADDRINFO +# define AT_ERRPARAM hstrerror(_errNo) +# else +# define AT_ERRPARAM strerror(_errNo) +# endif # endif #else # include -# define GET_ERRNO GetLastError() -# define GET_AT_ERRNO WSAGetLastError() -# define GET_SOCK_ERRNO WSAGetLastError() -# define ERRFMT "Error code was: %d" -# define ERRPARAM _errNo -# define AT_ERRPARAM _errNo +# define GET_ERRNO GetLastError() +# ifdef OF_HAVE_SOCKETS +# define GET_AT_ERRNO WSAGetLastError() +# define GET_SOCK_ERRNO WSAGetLastError() +# endif +# define ERRFMT "Error code was: %d" +# define ERRPARAM _errNo +# ifdef OF_HAVE_SOCKETS +# define AT_ERRPARAM _errNo +# endif #endif Index: src/objfw-defs.h.in ================================================================== --- src/objfw-defs.h.in +++ src/objfw-defs.h.in @@ -11,8 +11,9 @@ #undef OF_HAVE_PTHREADS #undef OF_HAVE_PLUGINS #undef OF_HAVE_PTHREAD_SPINLOCKS #undef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES #undef OF_HAVE_SCHED_YIELD +#undef OF_HAVE_SOCKETS #undef OF_HAVE_THREADS #undef OF_OBJFW_RUNTIME #undef SIZE_MAX Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -17,22 +17,23 @@ OFSerializationTests.m \ OFSet.m \ OFSHA1HashTests.m \ OFStreamTests.m \ OFStringTests.m \ - OFTCPSocketTests.m \ OFURLTests.m \ OFXMLElementBuilderTests.m \ OFXMLNodeTests.m \ OFXMLParserTests.m \ ${PROPERTIESTESTS_M} \ TestsAppDelegate.m \ ${USE_SRCS_PLUGINS} \ - ${USE_SRCS_THREADS} + ${USE_SRCS_SOCKETS} \ + ${USE_SRCS_THREADS} \ + ${OFHTTPCLIENTTESTS_M} SRCS_PLUGINS = OFPluginTests.m -SRCS_THREADS = OFThreadTests.m \ - OFHTTPClientTests.m +SRCS_SOCKETS = OFTCPSocketTests.m +SRCS_THREADS = OFThreadTests.m IOS_USER ?= mobile IOS_TMP ?= /tmp/objfw-test .PHONY: run run-tests run-on-ios Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -139,16 +139,18 @@ [self listTests]; [self setTests]; [self dateTests]; [self numberTests]; [self streamTests]; +#ifdef OF_HAVE_SOCKETS [self TCPSocketTests]; +#endif #ifdef OF_HAVE_THREADS [self threadTests]; #endif [self URLTests]; -#ifdef OF_HAVE_THREADS +#if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) [self HTTPClientTests]; #endif [self XMLParserTests]; [self XMLNodeTests]; [self XMLElementBuilderTests];