@@ -38,16 +38,18 @@ * The OFTCPSocket class provides functions to create and use sockets. */ @interface OFTCPSocket: OFObject { #ifndef _WIN32 - int sock; + int sock; #else - SOCKET sock; + SOCKET sock; #endif - struct sockaddr *saddr; - socklen_t saddr_len; + struct sockaddr *saddr; + socklen_t saddr_len; + char *cache; + size_t cache_len; } /** * \return A new autoreleased OFTCPSocket */ @@ -97,10 +99,34 @@ * \return An OFTCPSocket for the accepted connection, which is NOT * autoreleased! */ - (OFTCPSocket*)accept; +/** + * Read until a newline or \0 occurs. + * + * If you want to use readNBytes afterwards again, you have to clear the cache + * before and optionally get the cache before clearing it! + * + * \return The line that was read. Use freeMem: to free it! + */ +- (char*)readLine; + +/** + * Sets a specified pointer to the cache and returns the length of the cache. + * + * \param ptr A pointer to a pointer. It will be set to the cache. + * If it is NULL, only the number of bytes in the cache is returned. + * \return The number of bytes in the cache. + */ +- (size_t)getCache: (char**)ptr; + +/** + * Clears the cache. + */ +- clearCache; + /** * Enables/disables non-blocking I/O. */ - setBlocking: (BOOL)enable;