82 lines
1.9 KiB
C++
82 lines
1.9 KiB
C++
//
|
|
// TCP Server
|
|
//
|
|
|
|
/* prevent multiple inclusions */
|
|
#ifndef __TcpServer__
|
|
#define __TcpServer__
|
|
|
|
/* includes *****************************************************************/
|
|
|
|
#include "TcpSocket.h"
|
|
#include "Daemon.h"
|
|
#include "Server.h"
|
|
|
|
/* defines ******************************************************************/
|
|
|
|
/* macros *******************************************************************/
|
|
|
|
/* structs & typedefs *******************************************************/
|
|
|
|
/* c class definitions ******************************************************/
|
|
|
|
class TcpServer : public Server, public TcpSocket {
|
|
// public data
|
|
public:
|
|
|
|
// protected data
|
|
protected:
|
|
// logfile
|
|
|
|
// private data
|
|
private:
|
|
// socket
|
|
int m_clients;
|
|
fd_set m_cfds; /* client sockets */
|
|
|
|
// static data
|
|
|
|
// public methods
|
|
public:
|
|
// constructors
|
|
TcpServer();
|
|
TcpServer( const char *host, const char *service );
|
|
|
|
// destructor
|
|
virtual ~TcpServer();
|
|
|
|
// public methods
|
|
int ServiceUri( const char *uri );
|
|
int Service( const char *host, const char *service=NULL );
|
|
int Listen( void );
|
|
int Restart( void );
|
|
int NumClients(void) {return m_clients;};
|
|
|
|
// virtual functions
|
|
virtual int ServerTimeout(void) {return 0;};
|
|
virtual int ServerSocket(void) {return 0;}; // other socket (not client)
|
|
|
|
virtual int ClientUp( int sock ) { return 1; };
|
|
virtual void ClientDown( int sock ) {;};
|
|
virtual int ClientSock( int sock ) {return 0;};
|
|
virtual int ClientIn( int client, const char *buf, int n );
|
|
virtual int ClientOut( int client, char *buf, int max );
|
|
virtual void ClientCast( const char *buf, int len );
|
|
|
|
// exceptions
|
|
class TcpServerException
|
|
{
|
|
char *toString(void) { return strerror(errno); };
|
|
};
|
|
|
|
// static methods
|
|
|
|
// private methods
|
|
void Init(void);
|
|
|
|
private:
|
|
void ClientAdd(int sock);
|
|
};
|
|
|
|
#endif
|