libvisiontransfer
5.2.0
|
A protocol for transmitting large blocks of data over a network. More...
#include <visiontransfer/datablockprotocol.h>
Public Types | |
enum | ProtocolType { PROTOCOL_TCP, PROTOCOL_UDP } |
Public Member Functions | |
DataBlockProtocol (ProtocolType protType, int maxUdpPacketSize) | |
Creates a new instance. More... | |
int | getProtocolOverhead () const |
Returns the size of the overhead data that is required for transferring a single network message. More... | |
int | getMaxReceptionSize () const |
Returns the maximum paload size that can be recedived. More... | |
void | startTransfer () |
Starts the transfer of a new data block. More... | |
void | resetTransfer () |
Stops the current transfer. More... | |
void | setTransferData (unsigned char *data, int size, int validBytes=0x7FFFFFFF) |
Sets a new chunk of data that should be transferred. More... | |
void | setTransferValidBytes (int validBytes) |
Updates the number of valid bytes in a partial transmission. More... | |
const unsigned char * | getTransferMessage (int &length) |
Gets the next network message for the current transfer. More... | |
bool | transferComplete () |
Returns true if the current transfer has been completed. More... | |
void | setReceiveDataSize (int size) |
Sets the total size of the data that shall be received. More... | |
unsigned char * | getNextReceiveBuffer (int maxLength) |
Gets a buffer for receiving the next network message. More... | |
void | resetReception () |
Resets the message reception. More... | |
bool | processReceivedMessage (int length) |
Handles a received network message. More... | |
unsigned char * | getReceivedData (int &length) |
Returns the data that has been received for the current data block. More... | |
void | finishReception () |
Finishes reception of the current data block. More... | |
Static Public Attributes | |
static const int | MAX_TCP_BYTES_TRANSFER = 0xFFFF |
static const int | MAX_UDP_RECEPTION = 0x4000 |
static const int | MAX_OUTSTANDING_BYTES = 2*MAX_TCP_BYTES_TRANSFER |
A protocol for transmitting large blocks of data over a network.
The protocol slices the large data block into several smaller chunks that can be transmitted over a network. In UDP mode, each chunk contains a sequence number.
This class is intended to be used by ImageProtocol and should normally not be used directly.
Definition at line 34 of file datablockprotocol.h.
DataBlockProtocol::DataBlockProtocol | ( | ProtocolType | protType, |
int | maxUdpPacketSize | ||
) |
Creates a new instance.
protType | The target network protocol. |
maxUdpPacketSize | Maximum allowed size of a UDP packet when sending data. |
Definition at line 30 of file datablockprotocol.cpp.
void DataBlockProtocol::finishReception | ( | ) |
Finishes reception of the current data block.
The first network message that is added after calling this method will start the reception of a new data block.
Definition at line 221 of file datablockprotocol.cpp.
int DataBlockProtocol::getMaxReceptionSize | ( | ) | const |
Returns the maximum paload size that can be recedived.
Definition at line 132 of file datablockprotocol.cpp.
unsigned char * DataBlockProtocol::getNextReceiveBuffer | ( | int | maxLength | ) |
Gets a buffer for receiving the next network message.
The returned buffer is a subsection of the internal receive buffer
Definition at line 140 of file datablockprotocol.cpp.
|
inline |
Returns the size of the overhead data that is required for transferring a single network message.
Definition at line 59 of file datablockprotocol.h.
unsigned char * DataBlockProtocol::getReceivedData | ( | int & | length | ) |
Returns the data that has been received for the current data block.
length | Will be set to the number of bytes that have been received. |
The received data is valid until receiving the first byte of a new data block.
Definition at line 230 of file datablockprotocol.cpp.
const unsigned char * DataBlockProtocol::getTransferMessage | ( | int & | length | ) |
Gets the next network message for the current transfer.
length | The length of the network message. |
If the transfer has already been completed or if there are currently no more valid bytes to be transmitted, a null pointer is returned.
Definition at line 77 of file datablockprotocol.cpp.
bool DataBlockProtocol::processReceivedMessage | ( | int | length | ) |
Handles a received network message.
Please see ImageProtocol::processReceivedMessage() for further details.
Definition at line 155 of file datablockprotocol.cpp.
void DataBlockProtocol::resetReception | ( | ) |
Resets the message reception.
Definition at line 225 of file datablockprotocol.cpp.
void DataBlockProtocol::resetTransfer | ( | ) |
Stops the current transfer.
Definition at line 52 of file datablockprotocol.cpp.
void DataBlockProtocol::setReceiveDataSize | ( | int | size | ) |
Sets the total size of the data that shall be received.
size | New data size. |
This method has to be called before receiving the first data item. It can be called within an active transfer. This is typically done to set the expected data size after the header has been received.
Definition at line 117 of file datablockprotocol.cpp.
void DataBlockProtocol::setTransferData | ( | unsigned char * | data, |
int | size, | ||
int | validBytes = 0x7FFFFFFF |
||
) |
Sets a new chunk of data that should be transferred.
data | Pointer to the data that should be transferred. |
size | Total size of the data transfer. |
validBytes | The number of bytes that are currently valid in data . |
Part of data
will be overwritten. There must be at least 2 additional bytes before the start of data
.
If validBytes
is set to a value smaller than the total transfer size, only a partial transfer is performed. Subsequent calls to setTransferValidBytes() are then necessary.
Definition at line 57 of file datablockprotocol.cpp.
void DataBlockProtocol::setTransferValidBytes | ( | int | validBytes | ) |
Updates the number of valid bytes in a partial transmission.
validBytes | The number of already valid bytes in the previously set data pointer. |
This method has to be called whenever new data is available in a partial transfer.
Definition at line 65 of file datablockprotocol.cpp.
void DataBlockProtocol::startTransfer | ( | ) |
Starts the transfer of a new data block.
Call this method before setTransferData().
Definition at line 46 of file datablockprotocol.cpp.
bool DataBlockProtocol::transferComplete | ( | ) |
Returns true if the current transfer has been completed.
Definition at line 113 of file datablockprotocol.cpp.