/* */ #ifndef _D_SOCKET_BUFFER_H_ #define _D_SOCKET_BUFFER_H_ #include "common.h" #include #include #include "SharedHandle.h" namespace aria2 { class SocketCore; class SocketBuffer { private: SharedHandle _socket; std::deque _bufq; // Offset of data in _bufq[0]. SocketBuffer tries to send _bufq[0], // but it cannot always send whole data. In this case, offset points // to the data to be sent in the next send() call. size_t _offset; public: SocketBuffer(const SharedHandle& socket); ~SocketBuffer(); // Feeds data into queue. This function doesn't send data. void feedSendBuffer(const std::string& data); // Feeds data into queue and sends data in queue. This function is // equivalent to call feedSendBuffer() and send() sequentially. // Returns the number of bytes sent. ssize_t feedAndSend(const std::string& data); // Sends data in queue. Returns the number of bytes sent. ssize_t send(); // Returns true if queue is empty. bool sendBufferIsEmpty() const; }; } // namespace aria2 #endif // _D_SOCKET_BUFFER_H_