#ifndef TCPQUEUE_H
#define TCPQUEUE_H
#include "common.h"
class Connection;
class TcpQueue {
public:
enum { ALLOCATED_SIZE = TCP_BUFFER_SIZE + 1 };
public:
Connection &connection;
private:
unsigned char buffer[ALLOCATED_SIZE];
int begin;
int end;
public:
explicit TcpQueue(Connection &connection);
~TcpQueue();
inline int busySize() const
{ return end < begin ? end + ALLOCATED_SIZE - begin : end - begin; }
inline int freeSize() const
{ return TCP_BUFFER_SIZE - busySize(); }
bool push(const void *data, int size);
bool pop(void *data, int size);
int readFromTcp();
int writeToTcp();
};
#endif