/* */ #ifndef D_SOCKET_RECV_BUFFER_H #define D_SOCKET_RECV_BUFFER_H #include "common.h" #include "SharedHandle.h" namespace aria2 { class SocketCore; class SocketRecvBuffer { public: SocketRecvBuffer (const SharedHandle& socket, size_t capacity = 16*1024); ~SocketRecvBuffer(); // Reads data from socket as much as capacity allows. Returns the // number of bytes read. ssize_t recv(); // Shifts buffer by offset bytes. offset must satisfy offset <= // getBufferLength(). void shiftBuffer(size_t offset); // Truncates the contents of buffer to 0. void clearBuffer() { bufLen_ = 0; } const SharedHandle& getSocket() const { return socket_; } const unsigned char* getBuffer() const { return buf_; } size_t getBufferLength() const { return bufLen_; } bool bufferEmpty() const { return bufLen_ == 0; } private: SharedHandle socket_; size_t capacity_; unsigned char* buf_; size_t bufLen_; }; } // namespace aria2 #endif // D_SOCKET_RECV_BUFFER_H