/*
 * extendes sockets
 */

#ifndef _VDRMON_SOCK
#define _VDRMON_SOCK

#include <sys/types.h>
#include <sys/socket.h>
#include <string>

using namespace std;

class cVdrmonSocket
{
protected:
  int sock;
protected:
  cVdrmonSocket();
public:
  virtual ~cVdrmonSocket();
  void Close();
  int GetSocket();
  bool MakeDontBlock();
};

class cVdrmonClientSocket : public cVdrmonSocket
{
private:
  string readbuf;
  string writebuf;
  bool disconnected;
  int client;
public:
  cVdrmonClientSocket();
  virtual ~cVdrmonClientSocket();
  bool Attach(int fd);
  bool IsLineComplete();
  bool GetLine(string& line);
  bool PutLine(string line);
  bool Read();
  bool Disconnected();
  void Disconnect();
  bool Flush();
  int GetClientId();
  bool WritePending();
};

class cVdrmonServerSocket : public cVdrmonSocket
{
public:
  cVdrmonServerSocket();
  virtual ~cVdrmonServerSocket();
  bool Create(int port);
  cVdrmonClientSocket * Accept();
};

#endif
