@@ -24,10 +24,11 @@ #import "OFStreamSocket.h" #import "OFInitializationFailedException.h" #import "OFNotConnectedException.h" +#import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSetOptionFailedException.h" #import "OFWriteFailedException.h" #import "socket_helpers.h" @@ -68,13 +69,22 @@ requestedLength: length]; e->_errNo = ENOTCONN; @throw e; } +#ifndef _WIN32 if ((ret = recv(_socket, buffer, length, 0)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length]; +#else + if (length > UINT_MAX) + @throw [OFOutOfRangeException exception]; + + if ((ret = recv(_socket, buffer, (unsigned int)length, 0)) < 0) + @throw [OFReadFailedException exceptionWithObject: self + requestedLength: length]; +#endif if (ret == 0) _atEndOfStream = true; return ret; @@ -93,13 +103,22 @@ requestedLength: length]; e->_errNo = ENOTCONN; @throw e; } +#ifndef _WIN32 if (send(_socket, buffer, length, 0) < length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length]; +#else + if (length > UINT_MAX) + @throw [OFOutOfRangeException exception]; + + if (send(_socket, buffer, (unsigned int)length, 0) < length) + @throw [OFWriteFailedException exceptionWithObject: self + requestedLength: length]; +#endif } #ifdef _WIN32 - (void)setBlocking: (bool)enable { @@ -111,16 +130,30 @@ } #endif - (int)fileDescriptorForReading { +#ifndef _WIN32 return _socket; +#else + if (_socket > INT_MAX) + @throw [OFOutOfRangeException exception]; + + return (int)_socket; +#endif } - (int)fileDescriptorForWriting { +#ifndef _WIN32 return _socket; +#else + if (_socket > INT_MAX) + @throw [OFOutOfRangeException exception]; + + return (int)_socket; +#endif } - (void)close { if (_socket == INVALID_SOCKET)