AURobotServers  4
Public Member Functions | Public Attributes | Protected Member Functions | Private Attributes | List of all members
USockServ Class Reference

#include <usockserv.h>

Public Member Functions

bool blockSend (int client, const char *buffer, int length, int msTimeout)
 
virtual int getUsedClientHandles ()
 
virtual void gotConnectionProblems (int client, int errnum, const char *leadText)
 
bool isActive (int client)
 
bool isRunning ()
 
int runServerThread ()
 
int setPort (int iPort)
 
bool startServer ()
 
int stopServer ()
 
 USockServ ()
 
virtual ~USockServ ()
 

Public Attributes

USockServConnectionclientConn [MAX_CLIENTS_SERVED]
 
UTime startTime
 
bool verboseMessages
 

Protected Member Functions

virtual int getFreeClientHandle ()
 
virtual int handleConnection (int iConn, struct sockaddr_in iConnInfo)
 
virtual void info (const char *info, USig significance, int interface)
 
virtual bool justConnected (int client)
 

Private Attributes

int port
 
bool running
 
bool stop
 
pthread_t thServ
 

Detailed Description

Socket server bas class, that opens a port and accepts connection until no more client handles. Each client are given a welcome message - if such is defined. When client messages are received (in a receive thread) the butes are transferred in a call to gotNewMessage(), and are assumed consumed here. Transmissions to the client are performed by a call to sendBlock().

Constructor & Destructor Documentation

USockServ::USockServ ( )

Constructor

References MAX_CLIENTS_SERVED, and USockServConnection::stop.

USockServ::~USockServ ( )
virtual

Destructor

Member Function Documentation

bool USockServ::blockSend ( int  client,
const char *  buffer,
int  length,
int  msTimeout 
)

Send data to client. if connection to client is open the data is send. returns false if client do not exist or data could not be send within timeout period.

int USockServ::getFreeClientHandle ( )
protectedvirtual

Get free handle to a client connection. Returns -1 if no handle is available.

References USockServConnection::isActive(), and MAX_CLIENTS_SERVED.

int USockServ::getUsedClientHandles ( )
virtual

Get count of used handles.

References USockServConnection::isActive(), and MAX_CLIENTS_SERVED.

void USockServ::gotConnectionProblems ( int  client,
int  errnum,
const char *  leadText 
)
virtual

Connection error has occured, this is the details

References MAX_COM_INFO_SIZE.

Referenced by USockServConnection::runConnection().

int USockServ::handleConnection ( int  iConn,
struct sockaddr_in  iConnInfo 
)
protectedvirtual

Handle connection for client number clnt. clnt is index to client handle.

References USockServConnection::justConnected().

void USockServ::info ( const char *  info,
USig  significance,
int  interface 
)
protectedvirtual

Information that might be relevant for the user and might be printed on console or into logfile.

References eerror.

bool USockServ::isActive ( int  client)

Tests if there is an active connection for this client, returns true if client is active (connected).

References USockServConnection::client, and MAX_CLIENTS_SERVED.

bool USockServ::isRunning ( )
inline

Is server running. Returns false if server is not accepting connections.

References USockServConnection::handleConnection(), USockServConnection::info(), and USockServConnection::justConnected().

bool USockServ::justConnected ( int  client)
protectedvirtual

tests wether a newly accepted connection can be accepted, and initiates any queues etc. that needs to be set up for the connection. Returns true if connection is acceptable.

int USockServ::runServerThread ( )

start function for socket server thread

References buf, USockServConnection::handleConnection(), and USockServConnection::stop.

Referenced by runSockServer().

int USockServ::setPort ( int  iPort)
inline
bool USockServ::startServer ( )

Start server with set port number

References runSockServer(), and USockServConnection::stop.

int USockServ::stopServer ( )

Stop server

References USockServConnection::stop.

Member Data Documentation

USockServConnection* USockServ::clientConn[MAX_CLIENTS_SERVED]

Structure for the accepted connections

int USockServ::port
private

Port where to accept connections

bool USockServ::running
private

Running is true when accepting calls

UTime USockServ::startTime

Start time - used fior timing analysis

bool USockServ::stop
private

Flag to stop active connections and stop accepting connections.

pthread_t USockServ::thServ
private

Handle to accept thread

bool USockServ::verboseMessages

Print more to info connection / console


The documentation for this class was generated from the following files: