/********************************************************************
*       (c) Copyright 2003, Hogeschool voor de Kunsten Utrecht
*                       Hilversum, the Netherlands
*********************************************************************
*
* File name     : socket.h
* System name   : signature
* 
* Version       : $Revision: 1.3 $
*
*
* Description   : Definition of Socket class
*
*
* Author        : Marc_G
* E-mail        : marcg@dinkum.nl
*
*
********************************************************************/

/************
   $Log: socket.h,v $
   Revision 1.3  2003/08/28 13:22:10  marcg
   adaptations for gcc-3

   Revision 1.2  2003/02/07 16:51:35  marcg
   added wouldblock()

   Revision 1.1.1.1  2003/01/30 21:46:09  marcg
   Imported using TkCVS

*************/


#ifndef _SOCKET_H_
#define _SOCKET_H_

using namespace std;

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <arpa/inet.h>

#include <string>

const int MAXCONNECTIONS = 5;


class Socket
{
public:
  Socket();
  virtual ~Socket();

  // Server init
  int create();
  int bind(const int port);
  int listen() const;
  int accept(Socket&) const;

  // Client init
  int connect(const string host,const int port);

  bool wouldblock(void);
  int read(char *buf,int size);
  int write(char *buf,int size);
  int write(string outputstring);

  void set_non_blocking(const bool);

  bool is_valid() const {return m_sock != -1;}

private:
  int m_sock;
  sockaddr_in m_addr;
};

#endif // _SOCKET_H_

