forest-net
an overlay networks for large-scale virtual worlds
|
Maintains a set of packets with selected header fields and a separate set of buffers. More...
#include <PacketStore.h>
Public Member Functions | |
PacketStore (int=100000, int=50000) | |
Constructor allocates space and initializes free lists. More... | |
Packet & | getPacket (pktx) const |
Get reference to packet header. More... | |
pktx | alloc () |
Allocate a new packet and buffer. More... | |
void | free (pktx) |
Release the storage used by a packet. More... | |
pktx | clone (pktx) |
Make a "clone" of an existing packet. More... | |
pktx | fullCopy (pktx) |
Allocate a new packet with the same content as p. More... | |
Private Attributes | |
int | N |
number of packets we have room for | |
int | M |
number of buffers we have room for | |
int | n |
number of packets in use | |
int | m |
number of buffers in use | |
mutex | mtx |
lock on packet store | |
Packet * | pkt |
hkt[i] = packet with index i | |
int * | pb |
pb[i] = index of packet i's buffer | |
buffer_t * | buff |
array of packet buffers | |
int * | ref |
array of ref counts for buffers | |
List * | freePkts |
list of free packets | |
List * | freeBufs |
list of free buffers | |
Maintains a set of packets with selected header fields and a separate set of buffers.
Each packet is associated with some buffer, but a buffer may be associated with several packets (to support multicast).
Packets are identified by an integer index.
Definition at line 35 of file PacketStore.h.
forest::PacketStore::PacketStore | ( | int | N1 = 100000 , |
int | M1 = 50000 |
||
) |
Constructor allocates space and initializes free lists.
N1 | is number of packets to allocate space for |
M1 | is the number of buffers to allocate space for |
Definition at line 18 of file PacketStore.cpp.
pktx forest::PacketStore::alloc | ( | ) |
Allocate a new packet and buffer.
Definition at line 39 of file PacketStore.cpp.
pktx forest::PacketStore::clone | ( | pktx | px) |
Make a "clone" of an existing packet.
The clone shares the same buffer as the original. Its header is initialized to match the original.
px | is the packet number of the packet to be cloned |
Definition at line 75 of file PacketStore.cpp.
void forest::PacketStore::free | ( | pktx | px) |
Release the storage used by a packet.
Also releases the associated buffer, if no clones are using it.
px | is the packet number of the packet to be released |
Definition at line 58 of file PacketStore.cpp.
pktx forest::PacketStore::fullCopy | ( | pktx | px) |
Allocate a new packet with the same content as p.
A new buffer is allocated for this packet.
Definition at line 92 of file PacketStore.cpp.
|
inline |
Get reference to packet header.
px | is a packet index |
Definition at line 74 of file PacketStore.h.