#include <common.h>
Public Member Functions | |
| Packet (int buffer_length) | |
| int | fillPayload (int size, char *inputstream) |
| char * | getPayload () |
| void | setPayloadSize (int size) |
| int | getBufferSize () |
| int | getPayloadSize () |
| int | getHeaderSize () |
| PacketHdr * | accessHeader () |
| void | extractHeader (char *streambuf) |
| int | makePacket (char *streambuf) |
Static Public Attributes | |
| static const int | DEFAULT_PAYLOAD_SIZE = 512 |
Protected Attributes | |
| int | size_ |
| Packet length in Bytes. | |
| int | length_ |
| Maximum allocated Size of Payload buffer. it is no less than the size_. | |
| char * | payload_ |
| Payload Pointer. | |
| PacketHdr * | header_ |
| Header Pointer;. | |
Packet is an entity which contains a set of ordered information bits. This packet object only carries a pointer to payload information, not any socket address information.
Definition at line 99 of file common.h.
|
|
Alternate Packet Constructor: Specify a large buffer.... This is useful to define a packet receiving buffer. Definition at line 75 of file common.cpp. References header_, length_, payload_, and size_. 00076 {
00077 size_ = 0;
00078 length_ = buffer_length;
00079 payload_ = new char[buffer_length];
00080 header_ = new PacketHdr();
00081 }
|
|
|
Get the packet header Definition at line 129 of file common.h. References header_. 00129 { return header_;}
|
|
|
Extract packet header from the incoming stream Definition at line 133 of file common.cpp. References PacketHdr::accessInfo(), header_, and PacketHdr::setHeaderSize(). Referenced by ReceivingPort::receivePacket(). 00134 {
00135 char* p= streambuf;
00136 int a = *(p++);
00137 header_->setHeaderSize(a);
00138 memcpy( header_->accessInfo(), p ,a);
00139 }
|
|
||||||||||||
|
A function to fill payload. user can specify the content of payload for applications like audio/video playback... Definition at line 107 of file common.cpp. References payload_, and setPayloadSize(). Referenced by ReceivingPort::receivePacket(). 00108 {
00109 setPayloadSize(size);
00110 if (memcpy((char *)payload_, (char *)inputstream, size) == NULL) {
00111 throw "Fill payload Failed";
00112 }
00113 return 0;
00114 }
|
|
|
get the size of packet buffer where payload is stored. Definition at line 117 of file common.h. References length_. 00117 {return length_;}
|
|
|
get the size of the packet header Definition at line 125 of file common.h. References PacketHdr::getSize(), and header_. Referenced by ReceivingPort::receivePacket().
|
|
|
get a pointer to the payload
Definition at line 112 of file common.h. References payload_. 00112 { return payload_;}
|
|
|
get the size of the packet Definition at line 121 of file common.h. References size_. 00121 { return size_;}
|
|
|
Assemble header and payload and headersize in a single stream Definition at line 120 of file common.cpp. References PacketHdr::accessInfo(), PacketHdr::getSize(), header_, payload_, and size_. Referenced by SendingPort::sendPacket(). 00121 {
00122 streambuf[0]= ( header_->getSize() ) & 0xff;
00123 streambuf[1]= 0x00;
00124 memcpy(streambuf+1, header_->accessInfo(), header_->getSize());
00125 memcpy(streambuf+1+header_->getSize(), payload_, size_);
00126
00127 return 1+size_+ header_->getSize();
00128 }
|
|
|
set packet size. As packet already has a default buffer, there are two ways to determine the payload
Definition at line 93 of file common.cpp. References length_, payload_, and size_. Referenced by fillPayload(). 00094 {
00095 size_ = size;
00096 if (size > length_) {
00097 if (payload_ != NULL) delete [] payload_;
00098 length_ = (int)(1.5 * size);
00099 payload_ = new char[length_];
00100 }
00101 }
|
|
|
Default payload size is 512 Bytes |
1.4.2