UT_NetMessage Class Reference

#include <UT_NetMessage.h>

List of all members.

Public Types

enum  TransmitState {
  STATE_INVALID, STATE_READ, STATE_SENDACK, STATE_READFIN,
  STATE_WRITE, STATE_WAITACK
}

Public Member Functions

 UT_NetMessage ()
 ~UT_NetMessage ()
 Frees the allocated data buffer.
bool pumpData ()
bool tryConnection (bool *failed=0)
UT_NetSocketgetSocket () const
 The socket we are attached to.
int getSocketFD () const
 File descriptor of socket.
void addToFDSet (fd_set *set, int &maxfd) const
TransmitState state () const
bool isErrored () const
void flagErrored ()
const char * data () const
char * data ()
int length () const
int64 extractInt64 (int offset)
int32 extractInt32 (int offset)
fpreal32 extractFloat32 (int offset)
fpreal64 extractFloat64 (int offset)
int16 extractInt16 (int offset)
int8 extractInt8 (int offset)
void overwriteInt64 (int offset, int64 val)
void overwriteInt32 (int offset, int32 val)
void overwriteFloat32 (int offset, fpreal32 val)
void overwriteFloat64 (int offset, fpreal64 val)
void overwriteInt16 (int offset, int16 val)
void overwriteInt8 (int 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, int len)
void setWriteData (const char *data)
void setWriteDataWithHeader (int headersize, const char *data, int len)
void setWriteDataWithHeader (int headersize, const char *data)
void setWriteDataLength (int bufsize)

Static Public Member Functions

static int64 totalBytesSent ()
static int64 totalBytesReceived ()
static void clearByteCounters ()


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 send myLength from myData STATE_WAITACK: receive 'j' shutdown the connection

Read Protocol: STATE_READ: receive 32bit 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)

Definition at line 65 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.

Wait for connection ack.

Definition at line 77 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::clearByteCounters (  )  [static]

char* UT_NetMessage::data ( void   )  [inline]

Definition at line 114 of file UT_NetMessage.h.

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

Definition at line 113 of file UT_NetMessage.h.

fpreal32 UT_NetMessage::extractFloat32 ( int  offset  ) 

fpreal64 UT_NetMessage::extractFloat64 ( int  offset  ) 

int16 UT_NetMessage::extractInt16 ( int  offset  ) 

int32 UT_NetMessage::extractInt32 ( int  offset  ) 

int64 UT_NetMessage::extractInt64 ( int  offset  ) 

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

int8 UT_NetMessage::extractInt8 ( int  offset  ) 

void UT_NetMessage::flagErrored (  )  [inline]

Definition at line 111 of file UT_NetMessage.h.

UT_NetSocket* UT_NetMessage::getSocket (  )  const [inline]

The socket we are attached to.

Definition at line 101 of file UT_NetMessage.h.

int UT_NetMessage::getSocketFD (  )  const [inline]

File descriptor of socket.

Definition at line 103 of file UT_NetMessage.h.

bool UT_NetMessage::isErrored (  )  const [inline]

Definition at line 110 of file UT_NetMessage.h.

int UT_NetMessage::length (  )  const [inline]

Definition at line 115 of file UT_NetMessage.h.

void UT_NetMessage::overwriteFloat32 ( int  offset,
fpreal32  val 
)

void UT_NetMessage::overwriteFloat64 ( int  offset,
fpreal64  val 
)

void UT_NetMessage::overwriteInt16 ( int  offset,
int16  val 
)

void UT_NetMessage::overwriteInt32 ( int  offset,
int32  val 
)

void UT_NetMessage::overwriteInt64 ( int  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 ( int  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::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::setWriteData ( const char *  data  )  [inline]

Definition at line 148 of file UT_NetMessage.h.

void UT_NetMessage::setWriteData ( const char *  data,
int  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 146 of file UT_NetMessage.h.

void UT_NetMessage::setWriteDataLength ( int  bufsize  )  [inline]

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

Definition at line 156 of file UT_NetMessage.h.

void UT_NetMessage::setWriteDataWithHeader ( int  headersize,
const char *  data 
) [inline]

Definition at line 151 of file UT_NetMessage.h.

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

void UT_NetMessage::setWriteSocket ( const char *  addr,
int  port 
)

void UT_NetMessage::setWriteSocket ( UT_NetSocket socket  ) 

TransmitState UT_NetMessage::state (  )  const [inline]

Definition at line 109 of file UT_NetMessage.h.

static int64 UT_NetMessage::totalBytesReceived (  )  [static]

static int64 UT_NetMessage::totalBytesSent (  )  [static]

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:

Generated on Fri May 25 00:10:51 2012 for HDK by  doxygen 1.5.9