Index: src/OFSocket.h ================================================================== --- src/OFSocket.h +++ src/OFSocket.h @@ -41,10 +41,11 @@ #else SOCKET sock; #endif struct sockaddr *saddr; socklen_t saddr_len; + BOOL eos; } /** * \return A new autoreleased OFTCPSocket */ Index: src/OFSocket.m ================================================================== --- src/OFSocket.m +++ src/OFSocket.m @@ -50,32 +50,27 @@ return self; } - (BOOL)atEndOfStream { - /* FIXME: Implement this! */ - - return NO; + return eos; } - (size_t)readNBytes: (size_t)size intoBuffer: (char*)buf { ssize_t ret; - if (sock == INVALID_SOCKET) + if (sock == INVALID_SOCKET || eos) @throw [OFNotConnectedException newWithClass: isa]; - switch ((ret = recv(sock, buf, size, 0))) { - case 0: - @throw [OFNotConnectedException newWithClass: isa]; - case -1: - @throw [OFReadFailedException newWithClass: isa - andSize: size]; - } - - /* This is safe, as we already checked < 1 */ + if ((ret = recv(sock, buf, size, 0)) < 0) + @throw [OFReadFailedException newWithClass: isa]; + + if (ret == 0) + eos = YES; + return ret; } - (size_t)writeNBytes: (size_t)size fromBuffer: (const char*)buf