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

#include <usockserv.h>

Public Member Functions

bool blockSend (const char *buffer, int length, int msTimeout)
 
char * getClientName ()
 
virtual bool getWelcomeMessage (unsigned char *buf, int *len)
 
virtual void gotNewMessage (unsigned char *message, int length)
 
bool handleConnection (int iConn, struct sockaddr_in iConnInfo)
 
bool isActive ()
 
virtual bool justConnected ()
 
int runConnection ()
 
bool stopConnection ()
 
 USockServConnection ()
 
virtual ~USockServConnection ()
 

Public Attributes

int client
 
int msgSend
 
pid_t pid
 
int recvLoops
 
USockServserv
 

Protected Member Functions

virtual void info (const char *info, USig significance, int interface)
 

Protected Attributes

int conn
 
bool connected
 
struct sockaddr_in connInfo
 
bool stop
 
pthread_t thClient
 

Detailed Description

example server from 31370 Exersize 6: TCP/IP

Author
(Jens) Christian Andersen,326/030,3548,

Constructor & Destructor Documentation

USockServConnection::USockServConnection ( )

Constructor

References conn, connected, msgSend, recvLoops, and stop.

USockServConnection::~USockServConnection ( )
virtual

Destructor - stops connection

References connected, and stopConnection().

Member Function Documentation

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

Send this bufferfull of data within this timeout period. Returns true if send. Returns false if not possible within timeout opperiod.

References conn, connected, and msgSend.

Referenced by isActive(), and USockServ::setPort().

char * USockServConnection::getClientName ( )

Get name of connecting client

References connected, and connInfo.

Referenced by runConnection().

bool USockServConnection::getWelcomeMessage ( unsigned char *  buf,
int *  len 
)
virtual

Called at start of client connection and sends a welcome message if so desired. Should return false if no message is to be send.

Referenced by isActive(), and runConnection().

void USockServConnection::gotNewMessage ( unsigned char *  message,
int  length 
)
virtual

A new message (or part of a message) has arraived. The message is assumed handled by this virtual function.

References client.

Referenced by isActive(), and runConnection().

bool USockServConnection::handleConnection ( int  iConn,
struct sockaddr_in  iConnInfo 
)
void USockServConnection::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.

Referenced by isActive(), USockServ::isRunning(), and runConnection().

bool USockServConnection::isActive ( )
inline
bool USockServConnection::justConnected ( )
virtual

tests wether a newly accepted connection can be accepted, and initiates any queues etc. that needs to be set up for the connection. This is also the place to send any welcome messages. The virtual function is called before receive thread is activated. Returns true if connection is acceptable.

Referenced by handleConnection(), USockServ::handleConnection(), and USockServ::isRunning().

int USockServConnection::runConnection ( )

This routine is running in a thread, and handles the connection protocol to this client. Returns when thread stopps.

References buf, client, conn, connected, einfo, getClientName(), getWelcomeMessage(), USockServ::gotConnectionProblems(), gotNewMessage(), info(), pid, recvLoops, serv, stop, and Wait().

Referenced by isActive(), and runServerConn().

bool USockServConnection::stopConnection ( )

Stop the connection if active

References conn, connected, pid, stop, and thClient.

Referenced by isActive(), and ~USockServConnection().

Member Data Documentation

int USockServConnection::client

index number of client connection (0 to MAX_CLIENTS_SERVED-1)

Referenced by gotNewMessage(), USockServ::isActive(), runConnection(), and USockServ::setPort().

int USockServConnection::conn
protected
bool USockServConnection::connected
protected
struct sockaddr_in USockServConnection::connInfo
protected

Structure with adress information etc.

Referenced by getClientName(), and handleConnection().

int USockServConnection::msgSend

statistics

Referenced by blockSend(), and USockServConnection().

pid_t USockServConnection::pid

id of the read process

Referenced by runConnection(), and stopConnection().

int USockServConnection::recvLoops

receive loops (poll loops)

Referenced by runConnection(), and USockServConnection().

USockServ* USockServConnection::serv

parent structure

Referenced by runConnection().

bool USockServConnection::stop
protected
pthread_t USockServConnection::thClient
protected

Read thread handle

Referenced by handleConnection(), and stopConnection().


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