/* */ #ifndef D_SOCKET_RECV_BUFFER_H #define D_SOCKET_RECV_BUFFER_H #include "common.h" #include #include #include "a2functional.h" namespace aria2 { class SocketCore; class SocketRecvBuffer { public: SocketRecvBuffer(std::shared_ptr socket); ~SocketRecvBuffer(); // Reads data from socket as much as capacity allows. Returns the // number of bytes read. ssize_t recv(); // Truncates the contents of buffer to 0. void truncateBuffer(); // Drains first n bytes of data from buffer. It is an programmer's // responsibility to ensure that n is smaller or equal to the // buffered data. void drain(size_t n); const std::shared_ptr& getSocket() const { return socket_; } const unsigned char* getBuffer() const { return pos_; } size_t getBufferLength() const { return last_ - pos_; } bool bufferEmpty() const { return pos_ == last_; } private: std::array buf_; std::shared_ptr socket_; unsigned char* pos_; unsigned char* last_; }; } // namespace aria2 #endif // D_SOCKET_RECV_BUFFER_H