Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -438,11 +438,11 @@ { self = [super initWithClass: class__]; req_size = size; - if ([class__ isSubclassOfClass: [OFTCPSocket class]]) + if ([class__ isSubclassOfClass: [OFSocket class]]) err = GET_SOCK_ERR; else err = GET_ERR; return self; Index: src/OFSocket.m ================================================================== --- src/OFSocket.m +++ src/OFSocket.m @@ -11,10 +11,11 @@ #include "config.h" #include #include +#include #ifndef _WIN32 # include # include #endif @@ -53,15 +54,19 @@ - (size_t)_readNBytes: (size_t)size intoBuffer: (char*)buf { ssize_t ret; - if (sock == INVALID_SOCKET || eos) + if (sock == INVALID_SOCKET) @throw [OFNotConnectedException newWithClass: isa]; - if ((ret = recv(sock, buf, size, 0)) < 0) - @throw [OFReadFailedException newWithClass: isa]; + if (eos) + errno = ENOTCONN; + + if (eos || (ret = recv(sock, buf, size, 0)) < 0) + @throw [OFReadFailedException newWithClass: isa + size: size]; if (ret == 0) eos = YES; return ret; @@ -73,11 +78,14 @@ ssize_t ret; if (sock == INVALID_SOCKET) @throw [OFNotConnectedException newWithClass: isa]; - if ((ret = send(sock, buf, size, 0)) == -1) + if (eos) + errno = ENOTCONN; + + if (eos || (ret = send(sock, buf, size, 0)) == -1) @throw [OFWriteFailedException newWithClass: isa size: size]; /* This is safe, as we already checked for -1 */ return ret;