@@ -21,48 +21,38 @@ #import "OFKernelEventObserver.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" -#import "OFStream.h" -#import "OFStream+Private.h" -#ifndef OF_HAVE_PIPE -# import "OFStreamSocket.h" +#ifdef HAVE_EPOLL +# import "OFEpollKernelEventObserver.h" #endif - #ifdef HAVE_KQUEUE # import "OFKqueueKernelEventObserver.h" #endif -#ifdef HAVE_EPOLL -# import "OFEpollKernelEventObserver.h" -#endif #ifdef HAVE_POLL # import "OFPollKernelEventObserver.h" #endif #ifdef HAVE_SELECT # import "OFSelectKernelEventObserver.h" #endif +#import "OFSocket.h" +#import "OFSocket+Private.h" +#import "OFStream.h" +#import "OFStream+Private.h" +#ifndef OF_HAVE_PIPE +# import "OFStreamSocket.h" +#endif #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" -#import "socket.h" -#import "socket_helpers.h" - #ifdef OF_AMIGAOS # include #endif -enum { - QUEUE_ADD = 0, - QUEUE_REMOVE = 1, - QUEUE_READ = 0, - QUEUE_WRITE = 2 -}; -#define QUEUE_ACTION (QUEUE_ADD | QUEUE_REMOVE) - @implementation OFKernelEventObserver @synthesize delegate = _delegate; #ifdef OF_AMIGAOS @synthesize execSignalMask = _execSignalMask; #endif @@ -70,11 +60,11 @@ + (void)initialize { if (self != [OFKernelEventObserver class]) return; - if (!of_socket_init()) + if (!OFSocketInit()) @throw [OFInitializationFailedException exceptionWithClass: self]; } + (instancetype)observer @@ -118,11 +108,11 @@ @throw [OFInitializationFailedException exceptionWithClass: self.class]; #elif !defined(OF_AMIGAOS) _cancelFD[0] = _cancelFD[1] = socket(AF_INET, SOCK_DGRAM, 0); - if (_cancelFD[0] == INVALID_SOCKET) + if (_cancelFD[0] == OFInvalidSocketHandle) @throw [OFInitializationFailedException exceptionWithClass: self.class]; _cancelAddr.sin_family = AF_INET; _cancelAddr.sin_port = 0; @@ -136,11 +126,11 @@ sizeof(_cancelAddr)) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; cancelAddrLen = sizeof(_cancelAddr); - if (of_getsockname(_cancelFD[0], + if (OFGetSockName(_cancelFD[0], (struct sockaddr *)&_cancelAddr, &cancelAddrLen) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; # else for (;;) { @@ -148,19 +138,19 @@ int ret; while (rnd < 1024) rnd = (uint16_t)rand(); - _cancelAddr.sin_port = OF_BSWAP16_IF_LE(rnd); + _cancelAddr.sin_port = OFToBigEndian16(rnd); ret = bind(_cancelFD[0], (struct sockaddr *)&_cancelAddr, sizeof(_cancelAddr)); if (ret == 0) break; - if (of_socket_errno() != EADDRINUSE) + if (OFSocketErrNo() != EADDRINUSE) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } # endif #endif @@ -243,11 +233,11 @@ - (void)observe { [self observeForTimeInterval: -1]; } -- (void)observeForTimeInterval: (of_time_interval_t)timeInterval +- (void)observeForTimeInterval: (OFTimeInterval)timeInterval { OF_UNRECOGNIZED_SELECTOR } - (void)observeUntilDate: (OFDate *)date @@ -265,15 +255,15 @@ _waitingTask = NULL; } Permit(); #elif defined(OF_HAVE_PIPE) - OF_ENSURE(write(_cancelFD[1], "", 1) > 0); + OFEnsure(write(_cancelFD[1], "", 1) > 0); #elif defined(OF_WII) - OF_ENSURE(sendto(_cancelFD[1], "", 1, 0, + OFEnsure(sendto(_cancelFD[1], "", 1, 0, (struct sockaddr *)&_cancelAddr, 8) > 0); #else - OF_ENSURE(sendto(_cancelFD[1], (void *)"", 1, 0, + OFEnsure(sendto(_cancelFD[1], (void *)"", 1, 0, (struct sockaddr *)&_cancelAddr, sizeof(_cancelAddr)) > 0); #endif } @end