event/BufferedSocket: move output buffer to FullyBufferedSocket

BufferedSocket has just an input buffer, and FullyBufferedSocket adds
the output buffer.
This commit is contained in:
Max Kellermann
2013-01-30 10:36:47 +01:00
parent 4ad7456428
commit a291415326
8 changed files with 210 additions and 119 deletions

View File

@@ -22,21 +22,19 @@
#include "check.h"
#include "SocketMonitor.hxx"
#include "util/PeakBuffer.hxx"
#include "gcc.h"
struct fifo_buffer;
class EventLoop;
class BufferedSocket : private SocketMonitor {
/**
* A #SocketMonitor specialization that adds an input buffer.
*/
class BufferedSocket : protected SocketMonitor {
fifo_buffer *input;
PeakBuffer output;
public:
BufferedSocket(int _fd, EventLoop &_loop,
size_t normal_size, size_t peak_size=0)
:SocketMonitor(_fd, _loop), input(nullptr),
output(normal_size, peak_size) {
BufferedSocket(int _fd, EventLoop &_loop)
:SocketMonitor(_fd, _loop), input(nullptr) {
ScheduleRead();
}
@@ -44,18 +42,11 @@ public:
using SocketMonitor::IsDefined;
using SocketMonitor::Close;
using SocketMonitor::Write;
private:
ssize_t DirectWrite(const void *data, size_t length);
ssize_t DirectRead(void *data, size_t length);
/**
* Send data from the output buffer to the socket.
*
* @return false if the socket has been closed
*/
bool WriteFromBuffer();
/**
* Receive data from the socket to the input buffer.
*
@@ -64,11 +55,6 @@ private:
bool ReadToBuffer();
protected:
/**
* @return false if the socket has been closed
*/
bool Write(const void *data, size_t length);
/**
* @return false if the socket has been closed
*/
@@ -112,7 +98,6 @@ protected:
virtual void OnSocketError(GError *error) = 0;
virtual void OnSocketClosed() = 0;
private:
virtual bool OnSocketReady(unsigned flags) override;
};