HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_NetMessage Class Reference

#include <UT_NetMessage.h>

Public Types

enum  TransmitState {
  STATE_INVALID, STATE_READ, STATE_SENDACK, STATE_READFIN,
  STATE_WRITE, STATE_WAITACK, STATE_READPIPE, STATE_READPIPE_BLOSC,
  STATE_READPIPE_DONE, STATE_WRITEPIPE, STATE_WRITEPIPE_DONE
}
 

Public Member Functions

 UT_NetMessage ()
 
 ~UT_NetMessage ()
 Frees the allocated data buffer. More...
 
bool pumpData ()
 
bool tryConnection (bool *failed=0)
 
UT_NetSocketgetSocket () const
 The socket we are attached to. More...
 
int getSocketFD () const
 File descriptor of socket. More...
 
void addToFDSet (fd_set *set, int &maxfd) const
 
TransmitState state () const
 
bool isErrored () const
 
void flagErrored ()
 
const char * data () const
 
char * data ()
 
exint length () const
 
void resetLength (TransmitState state, exint newlen)
 Resizes, useful for pipe messages. More...
 
int64 extractInt64 (exint offset)
 
int32 extractInt32 (exint offset)
 
fpreal32 extractFloat32 (exint offset)
 
fpreal64 extractFloat64 (exint offset)
 
int16 extractInt16 (exint offset)
 
int8 extractInt8 (exint offset)
 
void overwriteInt64 (exint offset, int64 val)
 
void overwriteInt32 (exint offset, int32 val)
 
void overwriteFloat32 (exint offset, fpreal32 val)
 
void overwriteFloat64 (exint offset, fpreal64 val)
 
void overwriteInt16 (exint offset, int16 val)
 
void overwriteInt8 (exint offset, int8 val)
 
void setReadSocket (UT_NetSocket *socket)
 
void setWriteSocket (UT_NetSocket *socket)
 
void setWriteSocket (const char *addr, int port)
 
void setWriteData (const char *data, exint len)
 
void setWriteData (const char *data)
 
void setWriteDataWithHeader (exint headersize, const char *data, exint len)
 
void setWriteDataWithHeader (exint headersize, const char *data)
 
void setWriteDataLength (exint bufsize)
 
void setState (TransmitState state)
 
bool compress (exint header)
 
bool decompress (exint header)
 

Static Public Member Functions

static int64 totalBytesSent ()
 
static int64 totalBytesReceived ()
 
static void clearByteCounters ()
 
static fpreal64 totalNetworkTime ()
 
static void addToTotalNetworkTime (fpreal64 netnewtime)
 Adds the given number of seconds to total network timecounter. More...
 

Detailed Description

UT_NetMessage bears similarity to a UT_NetPacket in that it tries to abstract the necessitiy of retrying TCP/IP streams until the message is completely received. However, it is built around the idea of having a datapump, pumpData, to handle this, allowing one to interleave many messages in one thread using select()

Write Protocol: STATE_WRITE: send 32bit length in network byte order if length greater than 1<<31, send 32 bit -1 followed by 64 bit length in network-byte order. send myLength from myData STATE_WAITACK: receive 'j' shutdown the connection

Read Protocol: STATE_READ: receive 32bit length in network byte order if length is -1, receive 64bit length in network byte order. set myLength and allocate myData receive myLength into myData STATE_SENDACK: send 'j' STATE_READFIN: receive '' (ie, wait till safe to close)

Examples:
standalone/msgpipe.C.

Definition at line 60 of file UT_NetMessage.h.

Member Enumeration Documentation

What state we are in. Thanks to the vagaries of TCP/IP we need an application level ACK to verify the data made it across the wire before we do our shutdown.

Enumerator
STATE_INVALID 
STATE_READ 
STATE_SENDACK 

Read message.

STATE_READFIN 

Send ack.

STATE_WRITE 

Connection closed after ack sent.

STATE_WAITACK 

Send message.

STATE_READPIPE 

Wait for connection ack.

STATE_READPIPE_BLOSC 

Blind read of a pipe for our size.

STATE_READPIPE_DONE 

Blind read blosc pipe.

STATE_WRITEPIPE 
STATE_WRITEPIPE_DONE 

Blind write of a pipe for our size.

Definition at line 72 of file UT_NetMessage.h.

Constructor & Destructor Documentation

UT_NetMessage::UT_NetMessage ( )
UT_NetMessage::~UT_NetMessage ( )

Frees the allocated data buffer.

Member Function Documentation

void UT_NetMessage::addToFDSet ( fd_set *  set,
int maxfd 
) const

Adds our file descriptor to the select set and update maxfd.

static void UT_NetMessage::addToTotalNetworkTime ( fpreal64  netnewtime)
static

Adds the given number of seconds to total network timecounter.

static void UT_NetMessage::clearByteCounters ( )
static
bool UT_NetMessage::compress ( exint  header)

Compresses our data into swap buffer, then swap the pointers so we will send the compressed buffer. The header measures the number of bytes that will be copied over directly.

const char* UT_NetMessage::data ( void  ) const
inline

Definition at line 114 of file UT_NetMessage.h.

char* UT_NetMessage::data ( void  )
inline

Definition at line 115 of file UT_NetMessage.h.

bool UT_NetMessage::decompress ( exint  header)

Decompress our block and swap so we point at the decompressed buffer. If it fails, it was a corrupt buffer of some sort. The header is copied directly.

fpreal32 UT_NetMessage::extractFloat32 ( exint  offset)
fpreal64 UT_NetMessage::extractFloat64 ( exint  offset)
int16 UT_NetMessage::extractInt16 ( exint  offset)
int32 UT_NetMessage::extractInt32 ( exint  offset)
int64 UT_NetMessage::extractInt64 ( exint  offset)

Extracts data from the message, applying proper byteswaps. Offset is in bytes. Does not need to be aligned.

int8 UT_NetMessage::extractInt8 ( exint  offset)
void UT_NetMessage::flagErrored ( )
inline

Definition at line 112 of file UT_NetMessage.h.

UT_NetSocket* UT_NetMessage::getSocket ( ) const
inline

The socket we are attached to.

Definition at line 102 of file UT_NetMessage.h.

int UT_NetMessage::getSocketFD ( ) const
inline

File descriptor of socket.

Definition at line 104 of file UT_NetMessage.h.

bool UT_NetMessage::isErrored ( ) const
inline

Definition at line 111 of file UT_NetMessage.h.

exint UT_NetMessage::length ( void  ) const
inline

Definition at line 116 of file UT_NetMessage.h.

void UT_NetMessage::overwriteFloat32 ( exint  offset,
fpreal32  val 
)
void UT_NetMessage::overwriteFloat64 ( exint  offset,
fpreal64  val 
)
void UT_NetMessage::overwriteInt16 ( exint  offset,
int16  val 
)
void UT_NetMessage::overwriteInt32 ( exint  offset,
int32  val 
)
void UT_NetMessage::overwriteInt64 ( exint  offset,
int64  val 
)

Inserts data into the message, applying proper byte swaps. Offset is in bytes. Does not need to be aligned.

void UT_NetMessage::overwriteInt8 ( exint  offset,
int8  val 
)
bool UT_NetMessage::pumpData ( )

Sends or receives data from the socket until the message is complete. When it is complete or errored, returns true. Returns false if you should put it back in the select loop.

void UT_NetMessage::resetLength ( TransmitState  state,
exint  newlen 
)

Resizes, useful for pipe messages.

Examples:
standalone/msgpipe.C.
void UT_NetMessage::setReadSocket ( UT_NetSocket socket)

Determine source/sink of this message. Because we shutdown the socket on completion of the protocol, we always gain ownership of the socket and will handle deleting it ourselves.

void UT_NetMessage::setState ( TransmitState  state)
inline

Definition at line 180 of file UT_NetMessage.h.

void UT_NetMessage::setWriteData ( const char *  data,
exint  len 
)
inline

The headersize, in bytes, is prepended as nulls to the message. The headersize is included in the myLength, the receiver doesn't know about the distinction between header and data!

Definition at line 150 of file UT_NetMessage.h.

void UT_NetMessage::setWriteData ( const char *  data)
inline

Definition at line 152 of file UT_NetMessage.h.

void UT_NetMessage::setWriteDataLength ( exint  bufsize)
inline

Allocates a blank write buffer of the given size. It is assumed the caller will fill it out by writing to data()

Examples:
standalone/msgpipe.C.

Definition at line 160 of file UT_NetMessage.h.

void UT_NetMessage::setWriteDataWithHeader ( exint  headersize,
const char *  data,
exint  len 
)
void UT_NetMessage::setWriteDataWithHeader ( exint  headersize,
const char *  data 
)
inline

Definition at line 155 of file UT_NetMessage.h.

void UT_NetMessage::setWriteSocket ( UT_NetSocket socket)
void UT_NetMessage::setWriteSocket ( const char *  addr,
int  port 
)
TransmitState UT_NetMessage::state ( ) const
inline

Definition at line 110 of file UT_NetMessage.h.

static int64 UT_NetMessage::totalBytesReceived ( )
static
static int64 UT_NetMessage::totalBytesSent ( )
static
static fpreal64 UT_NetMessage::totalNetworkTime ( )
static

Tracks total network time. This does not include time spent in background threads, only the time spent to sync up to such threads. This includes transfer time and sync time. (It is hard to determine what time spent waiting on a pipe is the other system still computing, and what is just waiting on the network to transfer data...) There is no way to clear this because some load balancing systems may want it to properly accumulate between frames

bool UT_NetMessage::tryConnection ( bool *  failed = 0)

Trys to connect the socket, if already connected a no-op Returns false if still not connected, true if connected or error. failed is set to true if the connectionf ailed due to a UT_CONNECT_FAILED as opposed to being delayed by a UT_WOULD_BLOCK


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