Main Page   Class Hierarchy   Compound List   File List   Compound Members  

CAVERNnet_udp_c Class Reference

#include <CAVERNnet_udp_c.hxx>

Inheritance diagram for CAVERNnet_udp_c::

CAVERNnet_socketbase_c List of all members.

Public Methods

 CAVERNnet_udp_c ()
void enableInstrumentation ()
void disableInstrumentation ()
void setTimeOut (int t)
int getTimeOut ()
 Get timeout period.

int init (unsigned short port=0)
int setSendAddress (char *host, unsigned short port)
void copyReceiveAddressToSendAddress ()
CAVERNnet_udp_c* clone ()
int send (char *message, int length, int blockingType=CAVERNnet_udp_c::NULL_VALUE)
int receive (char *message, int length, int blockingType=CAVERNnet_udp_c::NULL_VALUE)
int peek (char *message, int length)
void makeNonBlocking ()
 Make a connection non blocking (This method is being phased out of the distribution - you can set the blocking type in send() or receive() directly).

void printInfo ()
 Print information on the connection (IP address, port number etc).

void close ()
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 ()
unsigned long getReceiveIP ()
 Get an incoming packet's originating address.

void getReceiveIP (char *ip)
 Get an incoming packet's originating address.

unsigned short getReceivePort ()
 Get an incoming packet's originating port.

unsigned long getSendIP ()
 Get outgoing packet's destination address.

void getSendIP (char *ip)
 Get outgoing packet's destination address.

unsigned short getSendPort ()
 Get outgoing packet's destination port.

unsigned long getSelfIP ()
 Get your own IP.

void getSelfIP (char *ip)
 Get your own IP.

unsigned short getSelfPort ()
 Get your own port.


Static Public Attributes

const int OK
 Status ok.

const int FAILED
 Status failed.

const int BLOCKING
 Make the connection blocking but timeout eventually.

const int NON_BLOCKING
 Make the connection non blocking.

const int NULL_VALUE
 Default value used for the send() and receive().

const int NO_TIME_OUT
 Used to set time out period to never time out.

const int DEFAULT_TIME_OUT
 Default time out is no time out.

const int SOCKET_NOT_OPEN
 Socket is not open.

const int TIMED_OUT
 The read/write timed out.

const int NON_BLOCKING_NOT_READY_TO_WRITE
 You attempted to write with non blocking and socket was not ready.

const int NON_BLOCKING_HAS_NO_DATA
 You attempted to read with non blocking and there was no data.


Private Attributes

int enableInstr
int sockfd
int timeOutStatus
int timeOutPeriod
struct sockaddr_in selfAddress
sendAddress 
receiveAddress
CAVERNnet_perfMonitor_c pmonitor
int typeOfBlocking

Detailed Description

UDP Class. This class bypasses CAVERN's standard method for establishing connections and provides the user with direct control of UDP connections. The idea is that you first create a udp object and then call the init() method. (see init() method for more details). Then you can either Send data to a destination or receive any incoming data.

To send data to a destination you need to set the destination with the SetSendAddress method and then call the Send method.

To receive data, simply call the Receive method.

By default the connections are BLOCKING, which means, if you call Receive and there is no data available to read your program will block until something comes along. To make your receives or sends non blocking, use the NON_BLOCKING flag as a parameter to the receive() or send().In the previous versions the makeNonBlocking() method was used. The makeNonBlocking() is being phased out.

Version:
Version 5/26/97
Author:
(C) 1996 Jason Leigh


Member Function Documentation

CAVERNnet_udp_c * CAVERNnet_udp_c::clone ( )
 

Make a clone of the current udp object. This is useful when you get multiple udp messages coming in from different sources and you want to save their return addresses so that you can reply to them. Typically you do a clone and then call CopyReceiveAddresToSendAddress.

See also:
CopyReceiveAddresToSendAddress

void CAVERNnet_udp_c::close ( ) [inline]
 

Close the udp handle. Must not do this as a destructor or you will disconnect a connection that might be still held by another client object. Only do this explicitly when you want to close a connection.

void CAVERNnet_udp_c::copyReceiveAddressToSendAddress ( )
 

Copy the receive address to send address. You can do this if you want to send a message back to the receiver.

void CAVERNnet_udp_c::disableInstrumentation ( )
 

Disable the logging of latency and inter-message delay. Note: in order for this to work, all clients and servers that use UDP connections must also disable their instrumentation or else the bit stream will become confused. By default instrumentation is disabled except for Bandwidth measurements.

void CAVERNnet_udp_c::enableInstrumentation ( )
 

Enable the logging of latency and inter-message delay. Note: in order for this to work, all clients and servers that use UDP connections must also enable their instrumentation or else the bit stream will become confused. Enabling logging prepends timestamp data that is used to compute latency. By default instrumentation is disabled except for Bandwidth measurements.

void CAVERNnet_udp_c::exitSendStats ( )
 

Properly delete the perfDaemonClient after sendStats is done

int CAVERNnet_udp_c::init ( unsigned short port = 0 )
 

Open a socket.

Parameters:
port   Specifies port number.
Returns:
FAILED if failed. OK if succeeded. With the port parameter omitted a dynamic port will be established. Dynamic ports are typically used if you intend to be a client program sending packets to a server. If you are a server then you need to specify some specific port number. Port numbers must be > 6000.

int CAVERNnet_udp_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 ona different port.

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

int CAVERNnet_udp_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_udp_c::peek ( char * message,
int length )
 

Peek at incoming packet. - without extracting it from the queue.

Returns:
number of bytes available to be extracted.

int CAVERNnet_udp_c::receive ( char * message,
int length,
int blockingType = CAVERNnet_udp_c::NULL_VALUE )
 

Receive data.

Returns:
The number of bytes found in the packet. If a -1 is found then there might be a read error. Check the global variable errno. If you are using NON blocking and errno is EWOULDBLOCK then that's ok, it simply means you attempted a read but no data was available. If its not EWOULDBLOCK then you have a real error. To find out what the error means call: perror() - this is a UNIX call.If you are using blocking with a timeout period (set by using the setTimeOut()),you will get an error if the timeout occurs.
Parameters:
length   If length is set to smaller than actual incoming packet size, then the remaining bytes of packet is discarded. If length is set to larger than actual packet size, then only the number of bytes available in the packet is retrieved.
blockingType   Default value of this argument is CAVERNnet_udp_c::NULL_VALUE. It can be set to CAVERNnet_udp_c::BLOCKING or CAVERNnet_udp_c::NON_BLOCKING. If a value is not passed the blocking type is changed to the value stored by the private memeber 'typeOfBlocking'.

int CAVERNnet_udp_c::send ( char * message,
int length,
int blockingType = CAVERNnet_udp_c::NULL_VALUE )
 

Send data.

Returns:
The number of characters sent. If a -1 is found then an error has occured. Check the global variable errno. If you are using NON blocking and errno is EWOULDBLCOK then that's ok, it simply means that you attempted a write but no the socket was not ready. If it is not EWOULDBLOCK then a real error has occured. If you are using blocking with a timeout period (set by using the setTimeOut()),you will get an error if the timeout occurs.
Parameters:
length   If length is set to smaller than the actual outgoing packet size, then the remaining bytes are not sent. If the length is set to larger than actual packet size, the whole packet * gets sent.
blockingType   Default value of this argument is CAVERNnet_udp_c::NULL_VALUE. It can be set to CAVERNnet_udp_c::BLOCKING or CAVERNnet_udp_c::NON_BLOCKING. If a value is not passed the blocking type is changed to the value stored by the private memeber 'typeOfBlocking'.

int CAVERNnet_udp_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)

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

int CAVERNnet_udp_c::setSendAddress ( char * host,
unsigned short port )
 

Set address to send to. After a socket is open, you can create a connection to some other listener if you know their address and port

Returns:
0 if failed, 1 if success.

void CAVERNnet_udp_c::setTimeOut ( int t ) [inline]
 

Set timeout period when performing read() or write() operations.

Parameters:
t   Time out period in seconds. Set to CAVERNnet_udp_c::NO_TIME_OUT to set no time out period.

void CAVERNnet_udp_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