Main Page   Class Hierarchy   Compound List   File List   Compound Members  

CAVERNnet_tcpReflector_c Class Reference

#include <CAVERNnet_tcpReflector_c.hxx>

List of all members.

Public Methods

 CAVERNnet_tcpReflector_c ()
 ~CAVERNnet_tcpReflector_c ()
int init (int incomingPort=TCP_REFLECTOR_DEFAULT_PORT, int maxClients=64, char *forwardAddr=NULL, unsigned short forwardPort=0)
int process ()
int checkForNewClients ()
int setForcedDestination (char *ipAddr, unsigned short port)
void sendToAll (char *buffer, int dataSize)
void intercept (int(*callback)(CAVERNnet_tcpReflectorClient_c *client, char **buffer, int *bufferSize, void *userData), void *userData)
void interceptNewConnection (void(*callback)(CAVERNnet_tcpReflectorClient_c *newClient, void *userData), void *userData)
void showStats (char *streamInfo, char *comment)
int logStats (char *streamInfo, char *comment, FILE *filePtr)
int sendStats (char *streamInfo, char *comment)
int initSendStats (char *monitorClientIP, int port=PERF_DAEMON_DEFAULT_PORT)
void exitSendStats ()

Static Public Attributes

const int OK
 Status ok.

const int FAILED
 Status failed.

const int MEM_ALLOC_ERR
 Memory allocation error.

const int NEW_CONNECTION_ESTABLISHED
 New client has been connected.

const int TOO_MANY_CLIENTS
 Reflector cannot handle any more connections.

const int NO_NEW_CONNECTION
 No new connection.

const int NON_BLOCKING_HAS_NO_DATA
 A non-blocking read had no data available to read.

const int SKIP_DISTRIBUTION
 Skip the data distribution process. Used in user callback. See intercept().

const int DEFAULT_PORT

Private Methods

int distributeDataExceptTo (int clientToIgnore, char *buf, int incomingSize)
void removeClient (int clientNum)
void closeDownSockets ()
int addNewClient (CAVERNnet_tcpReflectorClient_c *newClient)

Private Attributes

CAVERNnet_tcpReflectorClient_c** clients
CAVERNnet_tcpServer_cserver
unsigned short incomingPort
char* perfDaemonIP
int perfDaemonPort
int perfDaemonStatus
int (* interceptCallback )(CAVERNnet_tcpReflectorClient_c *newClient, char **buffer, int *bufsize, void *userData)
void* interceptUserData
void (* interceptNewConnectionCallback )(CAVERNnet_tcpReflectorClient_c *newClient, void *userData)
void* interceptNewConnectionUserData
int maxNumClients


Detailed Description

TCP Reflector class. This class treats TCP streams as discrete packets/messages that can be reflected to multiple connected clients. Clients must be created using CAVERNnet_tcpReflectorClient_c in order to interpret the TCP stream correctly. Hence do NOT attempt to use CAVERNnet_tcpClient_c to connect to a TCP reflector or it will corrupt the TCP reflector stream. This reflector has 2 main functions: checkForNewClients() and process(). checkForNewClients, as the name suggests, checks to see if any new clients wish to connect to the reflector. Process() does the actual work of data reflection.

checkForNewClients is called everytime process() is called. If you want the check to be done more frequently you need to do it yourself. Similarly if you want the process() call done more frequently it is up to you to do it. I recommend threading those two off and setting up a mutex so that you do not do process() and checkForNewClients() at the same time.


Member Function Documentation

int CAVERNnet_tcpReflector_c::checkForNewClients ( )
 

Call this as often as you wish to check for new clients. Note. If you do this in a separate thread then you must set up a mutex so that you do not call the proces() call and this call at the same time. The process() call itself has imbedded in it 1 check for each time you call it.

Returns:
One of CAVERNnet_tcpReflector_c::NEW_CONNECTION_ESTABLISHED, NO_NEW_CONNECTION, TOO_MANY_CLIENTS.

void CAVERNnet_tcpReflector_c::exitSendStats ( )
 

Properly delete the perfDaemonClient after sendStats is done

int CAVERNnet_tcpReflector_c::init ( int incomingPort = TCP_REFLECTOR_DEFAULT_PORT,
int maxClients = 64,
char * forwardAddr = NULL,
unsigned short forwardPort = 0 )
 

Initialize the reflector.

Parameters:
incomingPort   is listening port for incoming connections. Default is 7000.
maxClients   is the max number of clients the reflector will manage.
forwardAddr   is the IP address of a machine running another tcpreflector to whom data must be forwared to.
forwardPort   is the port number of tcpreflector to whom data must be forwared to.
Returns:
Either CAVERNnet_tcpReflector_c::OK,FAILED,MEM_ALLOC_ERR.

int CAVERNnet_tcpReflector_c::initSendStats ( char * monitorClientIP,
int port = PERF_DAEMON_DEFAULT_PORT )
 

Initialize sendStats - provide the IP of the perfDaemon and an optional port number to connect to. This should be done initially before using the sendStats API.

Parameters:
monitorClientIP   IP address of the perfDameon to connect to
port   Port number at which the perfDaemon is running -this is optional. The default port number for perfDaemon is 9500 -so a different port number has to be specified if the perfDaemon is running on a different port.

Returns:
Either CAVERNnet_perfMonitor_c::OK or CAVERNnet_perfMonitor_c::FAILED

void CAVERNnet_tcpReflector_c::intercept ( int(* callback)(CAVERNnet_tcpReflectorClient_c *client, char **buffer, int *bufferSize,void *userData),
void * userData )
 

Intercept incoming messages and call a user-defined callback function. If you want you can also alter the buffer completely so that the reflector will reflect an entirely different message. You can do this by changing the contents of the buffer or by replacing the buffer entirely by allocating memory for a new buffer and stuffing it with your own data. If you choose to allocate a totally new buffer you must remember to deallocate memory for the original buffer before substituting it with yours.

If after your callback function exits you do not wish the reflector to forward the contents of the buffer, return with CAVERN_tcpReflector_c::SKIP_DISTRIBUTION. Otherwise just return CAVERN_tcpReflector_c::OK.

Note also that the callback function will also be given a pointer to a CAVERNnet_tcpReflectorClient_c object that can then be used to send data directly to the client that originally sent the message.

void CAVERNnet_tcpReflector_c::interceptNewConnection ( void(* callback)(CAVERNnet_tcpReflectorClient_c *newClient, void *userData),
void * userData )
 

Intercept any new connections that are formed. This allows you to send private data to the newly formed connection before it assumes its data reflection duties. Callback function will be given a pointer to the CAVERNnet_tcpReflectorClient_c object that can then be used to send data directly to the client.

int CAVERNnet_tcpReflector_c::logStats ( char * streamInfo,
char * comment,
FILE * filePtr )
 

This logs performance statistics in a file. The user opens a file and passes the file pointer with this function and results of monitoring are written into the logfile.

Parameters:
streamInfo   A label describing the stream that is being monitored.
comment   A comment on the event that marks the time at which the stream is being monitored
filePtr   File pointer to the file in which the results of monitoring are to be stored

Returns:
Either CAVERNnet_perfMonitor_c::OK or CAVERNnet_perfMonitor_c::FAILED

int CAVERNnet_tcpReflector_c::process ( )
 

Call this within a while loop to let the reflector continuously do its processing.

Returns:
Either CAVERNnet_tcpReflector_c::OK,MEM_ALLOC_ERR

int CAVERNnet_tcpReflector_c::sendStats ( char * streamInfo,
char * comment )
 

Sends the performance statistics to a remote perfdaemon -for further analysis of the monitored data - the initSendStats API should be called first, before calling a sendStats (In order to connect to the perfdaemon initially)

(Note: A typical example of sendStats is given in the (CAVERN_DISTRIB_DIR/demos/tcpreflector/ directory)

Parameters:
streamInfo   A label describing the stream that is being monitored.
comment   A comment on the event that marks the time at which the stream is being monitored

Returns:
Either CAVERNnet_perfMonitor_c::OK or CAVERNnet_perfMonitor_c::FAILED

void CAVERNnet_tcpReflector_c::sendToAll ( char * buffer,
int dataSize )
 

Send data to all clients connected to the reflector.

int CAVERNnet_tcpReflector_c::setForcedDestination ( char * ipAddr,
unsigned short port )
 

Set a single ip address and port number to which all packets will be sent.

Returns:
One of CAVERNnet_tcpReflector_c::NEW_CONNECTION_ESTABLISHED, NO_NEW_CONNECTION, TOO_MANY_CLIENTS.

void CAVERNnet_tcpReflector_c::showStats ( char * streamInfo,
char * comment )
 

Displays the resultant statistics instantaneously in the netlogger format - this should be typically done after a read/write is done a network.

Also, it should be noted that a showStats call should be made at the end of atleast one send and receive for two-way information (the same applies for logStats and sendStats)

Parameters:
streamInfo   A label describing the stream that is being monitored.
comment   A comment on the event that marks the time at which the stream is being monitored


The documentation for this class was generated from the following file:
Generated at Mon Jul 2 14:24:45 2001 for CAVERNsoft by doxygen1.2.8-20010617 written by Dimitri van Heesch, © 1997-2001