forest-net
an overlay networks for large-scale virtual worlds
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
forest::PacketStore Class Reference

Maintains a set of packets with selected header fields and a separate set of buffers. More...

#include <PacketStore.h>

Collaboration diagram for forest::PacketStore:

Public Member Functions

 PacketStore (int=100000, int=50000)
 Constructor allocates space and initializes free lists. More...
 
PacketgetPacket (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
 
Packetpkt
 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
 

Detailed Description

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.

Constructor & Destructor Documentation

forest::PacketStore::PacketStore ( int  N1 = 100000,
int  M1 = 50000 
)

Constructor allocates space and initializes free lists.

Parameters
N1is number of packets to allocate space for
M1is the number of buffers to allocate space for

Definition at line 18 of file PacketStore.cpp.

Member Function Documentation

pktx forest::PacketStore::alloc ( )

Allocate a new packet and buffer.

Returns
the packet number or 0, if no more packets available

Definition at line 39 of file PacketStore.cpp.

Here is the caller graph for this function:

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.

Parameters
pxis the packet number of the packet to be cloned
Returns
the index of the new packet or 0 on failure

Definition at line 75 of file PacketStore.cpp.

Here is the caller graph for this function:

void forest::PacketStore::free ( pktx  px)

Release the storage used by a packet.

Also releases the associated buffer, if no clones are using it.

Parameters
pxis the packet number of the packet to be released

Definition at line 58 of file PacketStore.cpp.

Here is the caller graph for this function:

pktx forest::PacketStore::fullCopy ( pktx  px)

Allocate a new packet with the same content as p.

A new buffer is allocated for this packet.

Returns
the index of the new packet.

Definition at line 92 of file PacketStore.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Packet & forest::PacketStore::getPacket ( pktx  px) const
inline

Get reference to packet header.

Parameters
pxis a packet index
Returns
a reference to the packet for px

Definition at line 74 of file PacketStore.h.

Here is the caller graph for this function:


The documentation for this class was generated from the following files: