@@ -16,13 +16,12 @@ #define __NO_EXT_QNX #include "config.h" -#include - #include +#include #import "OFStreamSocket.h" #import "OFInitializationFailedException.h" #import "OFNotConnectedException.h" @@ -37,11 +36,11 @@ + (void)initialize { if (self != [OFStreamSocket class]) return; - if (!of_init_sockets()) + if (!of_socket_init()) @throw [OFInitializationFailedException exceptionWithClass: self]; } + (instancetype)socket @@ -60,30 +59,30 @@ ssize_t ret; if (_socket == INVALID_SOCKET) @throw [OFNotConnectedException exceptionWithSocket: self]; - if (_atEndOfStream) { - OFReadFailedException *e; - - e = [OFReadFailedException exceptionWithObject: self - requestedLength: length]; - e->_errNo = ENOTCONN; - @throw e; - } + if (_atEndOfStream) + @throw [OFReadFailedException exceptionWithObject: self + requestedLength: length + errNo: ENOTCONN]; #ifndef _WIN32 if ((ret = recv(_socket, buffer, length, 0)) < 0) - @throw [OFReadFailedException exceptionWithObject: self - requestedLength: length]; + @throw [OFReadFailedException + exceptionWithObject: self + requestedLength: length + errNo: of_socket_errno()]; #else if (length > UINT_MAX) @throw [OFOutOfRangeException exception]; if ((ret = recv(_socket, buffer, (unsigned int)length, 0)) < 0) - @throw [OFReadFailedException exceptionWithObject: self - requestedLength: length]; + @throw [OFReadFailedException + exceptionWithObject: self + requestedLength: length + errNo: of_socket_errno()]; #endif if (ret == 0) _atEndOfStream = true; @@ -94,30 +93,30 @@ length: (size_t)length { if (_socket == INVALID_SOCKET) @throw [OFNotConnectedException exceptionWithSocket: self]; - if (_atEndOfStream) { - OFWriteFailedException *e; - - e = [OFWriteFailedException exceptionWithObject: self - requestedLength: length]; - e->_errNo = ENOTCONN; - @throw e; - } + if (_atEndOfStream) + @throw [OFWriteFailedException exceptionWithObject: self + requestedLength: length + errNo: ENOTCONN]; #ifndef _WIN32 if (send(_socket, buffer, length, 0) < length) - @throw [OFWriteFailedException exceptionWithObject: self - requestedLength: length]; + @throw [OFWriteFailedException + exceptionWithObject: self + requestedLength: length + errNo: of_socket_errno()]; #else if (length > UINT_MAX) @throw [OFOutOfRangeException exception]; if (send(_socket, buffer, (unsigned int)length, 0) < length) - @throw [OFWriteFailedException exceptionWithObject: self - requestedLength: length]; + @throw [OFWriteFailedException + exceptionWithObject: self + requestedLength: length + errNo: of_socket_errno()]; #endif } #ifdef _WIN32 - (void)setBlocking: (bool)enable @@ -124,11 +123,13 @@ { u_long v = enable; _blocking = enable; if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR) - @throw [OFSetOptionFailedException exceptionWithStream: self]; + @throw [OFSetOptionFailedException + exceptionWithStream: self + errNo: of_socket_errno()]; } #endif - (int)fileDescriptorForReading {