Class NetP allows sending and receiving of PData structures over the pvm network. More...
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 | |
| |
PData & | data () |
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. |
Class NetP allows sending and receiving of PData structures over the pvm network.
NetP::NetP | ( | string | packettype | ) |
Create a send packet, specifying the channel on which to send.
packettype,: | the name of the channel to broadcast messages on |
void NetP::cleanUp | ( | ) |
int NetP::joinChannel | ( | string | channel | ) |
Join a channel (receive packets only).
channel,: | the name of the channel to join |
int NetP::leaveChannel | ( | string | channel | ) |
Leave a channel (receive packets only).
channel,: | the name of the channel to leave |
int NetP::send | ( | ) |
Send the current contents of the packet.
string NetP::bReceive | ( | ) |
Perform a blocking receive (does not return until a packet is received).
string NetP::nReceive | ( | ) |
Perform a non-blocking receive (returns immediately).
string NetP::tReceive | ( | double | timeout_sec | ) |
Perform a timed receive.
Waits for timeout_sec seconds before giving up.
timeout_sec | the timeout in seconds |
string NetP::bReceiveNewest | ( | ) |
Same as bReceive(), but discards all but the most recent packet.
string NetP::nReceiveNewest | ( | ) |
Same as nReceive(), but discards all but the most recent packet.
string NetP::tReceiveNewest | ( | double | timeout_sec | ) |
Same as tReceive(), but discards all but the most recent packet.
timeout_sec | the timeout in seconds |
int NetP::peek | ( | ) |
Check if a packet is waiting to be received.
Returns immediately.
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.
string NetP::getType | ( | ) |
Get the type (channel) of the packet.
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.
static double NetP::currentTime | ( | ) | [static] |
Get the current time according to the NetP system.
int NetP::getSize | ( | ) |
Get the total transmit size of this packet.
int NetP::getTid | ( | ) |
Get the tid of the packet's sender.
string NetP::getHostname | ( | ) |
Get the hostname of the packet's sender.
int NetP::getProcessID | ( | ) |
Get the process ID of the packet's sender.
string NetP::toString | ( | ) |
Produce a string representation.
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.
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.
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.
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.
static int NetP::DirectWrite | ( | int | socket, | |
string | buf | |||
) | [static] |
Write (blocking) to the direct connection.
static int NetP::DirectWrite | ( | string | channel, | |
string | buf | |||
) | [static] |
Write (blocking) to the direct connection.
static int NetP::DirectRead | ( | int | socket, | |
char * | buf, | |||
int | len | |||
) | [static] |
Read (non-blocking) up to len bytes from the direct connection.
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.
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.
static string NetP::DirectRead | ( | string | channel | ) | [static] |
Read (non-blocking) from the direct connection.
static int NetP::GetSocketNum | ( | string | channel | ) | [static] |
Convert a channel to a socket number.
Use this to test if the connection exists or not.