Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -225,10 +225,13 @@ return _atEndOfStream; } - (int)fileDescriptorForReading { + if (_socket == nil) + return -1; + return [_socket fileDescriptorForReading]; } - (bool)hasDataInReadBuffer { Index: src/OFHTTPServer.m ================================================================== --- src/OFHTTPServer.m +++ src/OFHTTPServer.m @@ -279,11 +279,11 @@ } - (int)fileDescriptorForWriting { if (_socket == nil) - return (int)INVALID_SOCKET; + return -1; return [_socket fileDescriptorForWriting]; } @end Index: src/OFKernelEventObserver.h ================================================================== --- src/OFKernelEventObserver.h +++ src/OFKernelEventObserver.h @@ -113,16 +113,14 @@ __unsafe_unretained id *_FDToObject; size_t _maxFD; OFMutableArray *_queue; OFDataArray *_queueInfo, *_queueFDs; id _delegate; -#ifndef _WIN32 +#ifdef OF_HAVE_PIPE int _cancelFD[2]; #else - SOCKET _cancelFD[2]; -#endif -#ifndef OF_HAVE_PIPE + of_socket_t _cancelFD[2]; struct sockaddr_in _cancelAddr; #endif #ifdef OF_HAVE_THREADS OFMutex *_mutex; #endif Index: src/OFStreamSocket.h ================================================================== --- src/OFStreamSocket.h +++ src/OFStreamSocket.h @@ -23,20 +23,16 @@ * * @brief A class which provides functions to create and use stream sockets. */ @interface OFStreamSocket: OFStream { -#ifndef _WIN32 - int _socket; -#else - SOCKET _socket; -#endif - bool _atEndOfStream; + of_socket_t _socket; + bool _atEndOfStream; } /*! * @brief Returns a new, autoreleased OFTCPSocket. * * @return A new, autoreleased OFTCPSocket */ + (instancetype)socket; @end Index: src/OFStreamSocket.m ================================================================== --- src/OFStreamSocket.m +++ src/OFStreamSocket.m @@ -134,10 +134,13 @@ - (int)fileDescriptorForReading { #ifndef _WIN32 return _socket; #else + if (_socket == INVALID_SOCKET) + return -1; + if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif @@ -146,10 +149,13 @@ - (int)fileDescriptorForWriting { #ifndef _WIN32 return _socket; #else + if (_socket == INVALID_SOCKET) + return -1; + if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif Index: src/OFUDPSocket.h ================================================================== --- src/OFUDPSocket.h +++ src/OFUDPSocket.h @@ -85,15 +85,11 @@ * was called to create one "instance" for every thread! */ @interface OFUDPSocket: OFObject { -#ifndef _WIN32 - int _socket; -#else - SOCKET _socket; -#endif + of_socket_t _socket; } /*! * @brief Returns a new, autoreleased OFUDPSocket. * Index: src/OFUDPSocket.m ================================================================== --- src/OFUDPSocket.m +++ src/OFUDPSocket.m @@ -556,10 +556,13 @@ - (int)fileDescriptorForReading { #ifndef _WIN32 return _socket; #else + if (_socket == INVALID_SOCKET) + return -1; + if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif @@ -568,10 +571,13 @@ - (int)fileDescriptorForWriting { #ifndef _WIN32 return _socket; #else + if (_socket == INVALID_SOCKET) + return -1; + if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif Index: src/socket.h ================================================================== --- src/socket.h +++ src/socket.h @@ -63,18 +63,24 @@ in_port_t ss_data1; struct in_addr ss_data2; int8_t ss_data3[8]; }; #endif + +#ifndef _WIN32 +typedef int of_socket_t; +#else +typedef SOCKET of_socket_t; +#endif #ifdef __cplusplus extern "C" { #endif extern bool of_socket_init(void); extern int of_socket_errno(void); # ifndef __wii__ -extern int of_getsockname(int socket, struct sockaddr *restrict address, +extern int of_getsockname(of_socket_t socket, struct sockaddr *restrict address, socklen_t *restrict address_len); # endif #ifdef __cplusplus } #endif Index: src/socket.m ================================================================== --- src/socket.m +++ src/socket.m @@ -164,11 +164,11 @@ #endif } #ifndef __wii__ int -of_getsockname(int socket, struct sockaddr *restrict address, +of_getsockname(of_socket_t socket, struct sockaddr *restrict address, socklen_t *restrict address_len) { int ret; # ifdef OF_HAVE_THREADS