NetP Class Reference

Class NetP allows sending and receiving of PData structures over the pvm network. More...

List of all members.

Starting and Stopping



 NetP (string packettype)
 Create a send packet, specifying the channel on which to send.
 NetP ()
 Create a receive packet; you shold join channels with joinChannel after creation.
 ~NetP ()
void cleanUp ()
 Java and Python might not garbage-collect immediately, which means even after you stop using a NetP it might still be lying around, subscribed to channels and receiving packets in the background.
int joinChannel (string channel)
 Join a channel (receive packets only).
int leaveChannel (string channel)
 Leave a channel (receive packets only).

Sending and Receiving



int send ()
 Send the current contents of the packet.
string bReceive ()
 Perform a blocking receive (does not return until a packet is received).
string nReceive ()
 Perform a non-blocking receive (returns immediately).
string tReceive (double timeout_sec)
 Perform a timed receive.
string bReceiveNewest ()
 Same as bReceive(), but discards all but the most recent packet.
string nReceiveNewest ()
 Same as nReceive(), but discards all but the most recent packet.
string tReceiveNewest (double timeout_sec)
 Same as tReceive(), but discards all but the most recent packet.
int peek ()
 Check if a packet is waiting to be received.

Data and Metadata



PDatadata ()
 References the current data structure contained by the packet.
string getType ()
 Get the type (channel) of the packet.
double getTimeStamp ()
 Get the time stamp of the packet.
int getSize ()
 Get the total transmit size of this packet.
int getTid ()
 Get the tid of the packet's sender.
string getHostname ()
 Get the hostname of the packet's sender.
int getProcessID ()
 Get the process ID of the packet's sender.
string toString ()
 Produce a string representation.
static double currentTime ()
 Get the current time according to the NetP system.
ostream & operator<< (ostream &o, NetP &netp)
 Output to ostream.

Threads and Buffers



void setBufferSize (long bytes)
 Set the total buffer size for a receive packet, in bytes.
static void setMaxPeriod (double seconds)
 Set the maximum length of time, in seconds, the receive thread will wait before checking again to see if anything has been received.
static void setMinPeriod (double seconds)
 Set the minimum length of time, in seconds, the receive thread will wait before checking again to see if anything has been received.
static void setUnthreaded ()
 Prevent the creation of the receive thread.
static void LockPvmMutex ()
 Lock the PVM operations mutex.
static void UnlockPvmMutex ()
 Unlock the mutex.
static void Exit ()
 Exit the receive thread.

Direct Connect



static void DirectOffer (string channel)
 Start listening for a direct connect request on the given channel.
static int DirectConnect (string channel, unsigned short int port=51552)
 Issue a direct connect request on the given channel. Blocks until connection established.
static void DirectClose (string channel)
 Close a direct connection.
static void DirectClose (int socket)
 Close a direct connection by socket number.
static void DirectCloseAll ()
 Close all direct connections.
static int DirectWrite (int socket, const char *buf, int len=-1)
 Write (blocking) to the direct connection.
static int DirectWrite (int socket, string buf)
 Write (blocking) to the direct connection.
static int DirectWrite (string channel, string buf)
 Write (blocking) to the direct connection.
static int DirectRead (int socket, char *buf, int len)
 Read (non-blocking) up to len bytes from the direct connection.
static int DirectConnectToServer (string hostname, string direct_id, unsigned short int port=51552)
 Connect to a server.
static string DirectRead (int socket)
 Read (non-blocking) from the direct connection.
static string DirectRead (string channel)
 Read (non-blocking) from the direct connection.
static vector< string > ListOpenConnects ()
 List all open connections.
static vector< string > ListPendingConnects ()
 List all pending connections.
static int GetSocketNum (string channel)
 Convert a channel to a socket number.

Detailed Description

Class NetP allows sending and receiving of PData structures over the pvm network.


Constructor & Destructor Documentation

NetP::NetP ( string  packettype  ) 

Create a send packet, specifying the channel on which to send.

Parameters:
packettype,: the name of the channel to broadcast messages on

Member Function Documentation

void NetP::cleanUp (  ) 

Java and Python might not garbage-collect immediately, which means even after you stop using a NetP it might still be lying around, subscribed to channels and receiving packets in the background.

Call cleanUp() to leave all channels immediately and just leave the object itself for destruction.

int NetP::joinChannel ( string  channel  ) 

Join a channel (receive packets only).

Parameters:
channel,: the name of the channel to join
Returns:
a PVM error code if an error occured, 0 otherwise
int NetP::leaveChannel ( string  channel  ) 

Leave a channel (receive packets only).

Parameters:
channel,: the name of the channel to leave
Returns:
a PVM error code if an error occured, 0 otherwise
int NetP::send (  ) 

Send the current contents of the packet.

Returns:
0 on failure, 1 on success
string NetP::bReceive (  ) 

Perform a blocking receive (does not return until a packet is received).

Returns:
the type of packet received (name of its channel)
string NetP::nReceive (  ) 

Perform a non-blocking receive (returns immediately).

Returns:
the type of packet received (name of its channel), or empty string if no packet is waiting.
string NetP::tReceive ( double  timeout_sec  ) 

Perform a timed receive.

Waits for timeout_sec seconds before giving up.

Parameters:
timeout_sec the timeout in seconds
Returns:
the type of packet received (name of its channel), or empty string if no packet received before timeout.
string NetP::bReceiveNewest (  ) 

Same as bReceive(), but discards all but the most recent packet.

Returns:
the type of packet received (name of its channel)
string NetP::nReceiveNewest (  ) 

Same as nReceive(), but discards all but the most recent packet.

Returns:
the type of packet received (name of its channel), or empty string if no packet is waiting.
string NetP::tReceiveNewest ( double  timeout_sec  ) 

Same as tReceive(), but discards all but the most recent packet.

Parameters:
timeout_sec the timeout in seconds
Returns:
the type of packet received (name of its channel), or empty string if no packet received before timeout.
int NetP::peek (  ) 

Check if a packet is waiting to be received.

Returns immediately.

Returns:
1 if receive buffer is non-empty, 0 otherwise
PData& NetP::data (  ) 

References the current data structure contained by the packet.

Warning: all pointers into the returned structure are invalidated as soon as you run any of the receive functions.

Returns:
reference to the current data object
string NetP::getType (  ) 

Get the type (channel) of the packet.

Returns:
channel name
double NetP::getTimeStamp (  ) 

Get the time stamp of the packet.

For receive packets, this is the time it was sent. For send packets, this is the timestamp of the most recent send operation.

Returns:
timestamp value
static double NetP::currentTime (  )  [static]

Get the current time according to the NetP system.

Returns:
current system time
int NetP::getSize (  ) 

Get the total transmit size of this packet.

Returns:
size of packet in bytes
int NetP::getTid (  ) 

Get the tid of the packet's sender.

Returns:
the PVM tid of the sender
string NetP::getHostname (  ) 

Get the hostname of the packet's sender.

Returns:
internet hostname of sender
int NetP::getProcessID (  ) 

Get the process ID of the packet's sender.

Returns:
unix process id of sender
string NetP::toString (  ) 

Produce a string representation.

Returns:
a verbose, descriptive dump of this packet
void NetP::setBufferSize ( long  bytes  ) 

Set the total buffer size for a receive packet, in bytes.

Packets are discarded oldest-first when the buffer fills up.

Parameters:
bytes,: size of buffer to reserve, -1 for no limit. default value: 50 megabytes.
static void NetP::setMaxPeriod ( double  seconds  )  [static]

Set the maximum length of time, in seconds, the receive thread will wait before checking again to see if anything has been received.

If the receive thread has not seen any packets in a while, it will drop to this receive period. Generally, the thread will try to adjust so it acquires one packet per cycle, or until it hits the maximum or minimum limit. If you absolutely, totally, need to have every packet the instant it is sent, set this to zero.

Parameters:
seconds,: max wait time before check, 0.5 is default
static void NetP::setMinPeriod ( double  seconds  )  [static]

Set the minimum length of time, in seconds, the receive thread will wait before checking again to see if anything has been received.

No matter what (even if the minimum is set higher than maximum), we never elapse more than the set maximum time between checks.

Parameters:
seconds,: min wait time between checks, default 0.005 seconds.
static void NetP::setUnthreaded (  )  [static]

Prevent the creation of the receive thread.

setUnthreaded must be called before any NetP constructors are called, in order to not start another thread. Useful if you want total control over when pvm messages are received.

static void NetP::LockPvmMutex (  )  [static]

Lock the PVM operations mutex.

This mutex is provided just in case you run multithreaded but want to do your own pvm operations from time to time. you _must_ take this lock before performing _any_ pvm operations from your own code, and you must relinquish the lock when you are done.

static void NetP::Exit (  )  [static]

Exit the receive thread.

If your receive thread is not exiting cleanly (and your process locks up), run this before you close your main thread.

static int NetP::DirectWrite ( int  socket,
const char *  buf,
int  len = -1 
) [static]

Write (blocking) to the direct connection.

Returns:
Number of bytes actually sent.
static int NetP::DirectWrite ( int  socket,
string  buf 
) [static]

Write (blocking) to the direct connection.

Returns:
Number of bytes actually sent.
static int NetP::DirectWrite ( string  channel,
string  buf 
) [static]

Write (blocking) to the direct connection.

Returns:
Number of bytes actually sent.
static int NetP::DirectRead ( int  socket,
char *  buf,
int  len 
) [static]

Read (non-blocking) up to len bytes from the direct connection.

Returns:
Number of bytes received.
static int NetP::DirectConnectToServer ( string  hostname,
string  direct_id,
unsigned short int  port = 51552 
) [static]

Connect to a server.

Called internally unless you're setting up a connection manually without PVM.

Parameters:
hostname,: the name of the server to connect to
direct_id A label for this connection (when called internally,
port,: the port number to use it uses the channel name).
static string NetP::DirectRead ( int  socket  )  [static]

Read (non-blocking) from the direct connection.

Returns:
An appropriately-sized string.
static string NetP::DirectRead ( string  channel  )  [static]

Read (non-blocking) from the direct connection.

Returns:
An appropriately-sized string.
static int NetP::GetSocketNum ( string  channel  )  [static]

Convert a channel to a socket number.

Use this to test if the connection exists or not.

Returns:
The socket number, or -1 if no socket is associated (or socket is no longer associated) with that channel.

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

Generated on Wed Mar 9 12:04:24 2011 for netp2 by  doxygen 1.6.1