HDK
|
#include <UT_NetMessage.h>
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... | |
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)
Definition at line 63 of file UT_NetMessage.h.
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.
Definition at line 77 of file UT_NetMessage.h.
UT_NetMessage::UT_NetMessage | ( | ) |
UT_NetMessage::~UT_NetMessage | ( | ) |
Frees the allocated data buffer.
Adds our file descriptor to the select set and update maxfd.
Adds the given number of seconds to total network timecounter.
|
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.
|
inline |
Definition at line 119 of file UT_NetMessage.h.
|
inline |
Definition at line 120 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.
Extracts data from the message, applying proper byteswaps. Offset is in bytes. Does not need to be aligned.
|
inline |
Definition at line 117 of file UT_NetMessage.h.
|
inline |
The socket we are attached to.
Definition at line 107 of file UT_NetMessage.h.
|
inline |
File descriptor of socket.
Definition at line 109 of file UT_NetMessage.h.
Grows a write buffer to this size, must be done before transmitting. Existing data is left intact.
|
inline |
Definition at line 116 of file UT_NetMessage.h.
Definition at line 121 of file UT_NetMessage.h.
Inserts data into the message, applying proper byte swaps. Offset is in bytes. Does not need to be aligned.
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.
void UT_NetMessage::setReadSocket | ( | UT_NetSocketPtr | 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.
|
inline |
Definition at line 189 of file UT_NetMessage.h.
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 155 of file UT_NetMessage.h.
|
inline |
Definition at line 157 of file UT_NetMessage.h.
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 165 of file UT_NetMessage.h.
Definition at line 160 of file UT_NetMessage.h.
void UT_NetMessage::setWriteSocket | ( | UT_NetSocketPtr | socket | ) |
|
inline |
Definition at line 115 of file UT_NetMessage.h.
|
static |
|
static |
|
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