@@ -29,10 +29,11 @@ #import "OFBindFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFNotConnectedException.h" +#import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" #import "autorelease.h" #import "macros.h" @@ -451,14 +452,24 @@ if (_socket == INVALID_SOCKET) @throw [OFNotConnectedException exceptionWithSocket: self]; sender->length = (socklen_t)sizeof(sender->address); +#ifndef _WIN32 if ((ret = recvfrom(_socket, buffer, length, 0, (struct sockaddr*)&sender->address, &sender->length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length]; +#else + if (length > INT_MAX) + @throw [OFOutOfRangeException exception]; + + if ((ret = recvfrom(_socket, buffer, (int)length, 0, + (struct sockaddr*)&sender->address, &sender->length)) < 0) + @throw [OFReadFailedException exceptionWithObject: self + requestedLength: length]; +#endif return ret; } - (void)asyncReceiveIntoBuffer: (void*)buffer @@ -490,29 +501,53 @@ receiver: (of_udp_socket_address_t*)receiver { if (_socket == INVALID_SOCKET) @throw [OFNotConnectedException exceptionWithSocket: self]; +#ifndef _WIN32 if (sendto(_socket, buffer, length, 0, (struct sockaddr*)&receiver->address, receiver->length) < length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length]; +#else + if (length > INT_MAX) + @throw [OFOutOfRangeException exception]; + + if (sendto(_socket, buffer, (int)length, 0, + (struct sockaddr*)&receiver->address, receiver->length) < length) + @throw [OFWriteFailedException exceptionWithObject: self + requestedLength: length]; +#endif } - (void)cancelAsyncRequests { [OFRunLoop OF_cancelAsyncRequestsForObject: self]; } - (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)