Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Public Attributes | List of all members
packetbuf Struct Reference

network packet buffer More...

#include <buffer_types.hpp>

Inheritance diagram for packetbuf:
databuf< T >

Public Types

enum  { OVERREAD = 1<<0, OVERWROTE = 1<<1 }
 buffer missuse flags. More...
 

Public Member Functions

 packetbuf (ENetPacket *packet)
 call constructor from inherited class in this constructor More...
 
 packetbuf (int growth, int pflags=0)
 reserve memory in this constructor More...
 
 ~packetbuf ()
 call cleanup in destructor! More...
 
void reliable ()
 set ENET_PACKET_FLAG_RELIABLE - flag More...
 
void resize (int n)
 resize ENET packet, copy data and buffer length More...
 
void checkspace (int n)
 check if [n] bytes memory are available in this buffer if not reserve memory! More...
 
ucharbuf subbuf (int sz)
 create a sub buffer of [sz] bytes size More...
 
void put (const uchar &val)
 write to buffer functions More...
 
void put (const uchar *vals, int numvals)
 
ENetPacket * finalize ()
 remove any allocated space which is not used yet background: allocations are expensive, so we pr More...
 
void cleanup ()
 destroy ENET packet and reset memory More...
 
void reset ()
 
void reset (T *buf_, int maxlen_)
 
const T & get ()
 get one byte from the buffer and More...
 
int get (T *vals, int numvals)
 receive the given amount of elements from the buffer to given array. More...
 
T * pad (int numvals)
 
void put (const T &val)
 put one element at the end of the buffer. More...
 
void put (const T *vals, int numvals)
 put a given number of elements at the end of the buffer. More...
 
void offset (int n)
 skip the first n elemnts of the buffer. More...
 
T * getbuf () const
 
bool empty () const
 
int length () const
 receive amount of values in buffer. More...
 
int remaining () const
 receive remaining space in buffer. More...
 
bool overread () const
 did we try to read too much? More...
 
bool overwrote () const
 did we try to write too much into the buffer? More...
 
bool check (int n)
 
void forceoverread ()
 force buffer to skip all free memory space More...
 

Public Attributes

ENetPacket * packet
 
int growth
 
T * buf
 the pointer to the data. More...
 
int len
 
int maxlen
 
uchar flags
 

Detailed Description

network packet buffer

Member Enumeration Documentation

template<class T>
anonymous enum
inherited

buffer missuse flags.

Enumerator
OVERREAD 
OVERWROTE 

Constructor & Destructor Documentation

packetbuf::packetbuf ( ENetPacket *  packet)
inline

call constructor from inherited class in this constructor

packetbuf::packetbuf ( int  growth,
int  pflags = 0 
)
inline

reserve memory in this constructor

References databuf< T >::buf, databuf< T >::maxlen, and packet.

packetbuf::~packetbuf ( )
inline

call cleanup in destructor!

References cleanup().

Member Function Documentation

template<class T>
bool databuf< T >::check ( int  n)
inlineinherited

References databuf< T >::remaining().

Referenced by gle::attrib().

void packetbuf::checkspace ( int  n)
inline

check if [n] bytes memory are available in this buffer if not reserve memory!

References growth, databuf< T >::len, inexor::rpc::max(), databuf< T >::maxlen, packet, and resize().

Referenced by put(), and subbuf().

void packetbuf::cleanup ( )
inline

destroy ENET packet and reset memory

References databuf< T >::buf, growth, databuf< T >::len, databuf< T >::maxlen, and packet.

Referenced by ~packetbuf().

template<class T>
bool databuf< T >::empty ( ) const
inlineinherited
ENetPacket* packetbuf::finalize ( )
inline
template<class T>
void databuf< T >::forceoverread ( )
inlineinherited

force buffer to skip all free memory space

References databuf< T >::flags, databuf< T >::len, databuf< T >::maxlen, and databuf< T >::OVERREAD.

template<class T>
const T& databuf< T >::get ( )
inlineinherited
template<class T>
int databuf< T >::get ( T *  vals,
int  numvals 
)
inlineinherited

receive the given amount of elements from the buffer to given array.

References databuf< T >::buf, databuf< T >::flags, databuf< T >::len, databuf< T >::maxlen, inexor::rpc::min(), and databuf< T >::OVERREAD.

template<class T>
T* databuf< T >::getbuf ( ) const
inlineinherited

References databuf< T >::buf.

Referenced by gle::end().

template<class T>
int databuf< T >::length ( ) const
inlineinherited
template<class T>
void databuf< T >::offset ( int  n)
inlineinherited
template<class T>
bool databuf< T >::overread ( ) const
inlineinherited
template<class T>
bool databuf< T >::overwrote ( ) const
inlineinherited

did we try to write too much into the buffer?

References databuf< T >::flags, and databuf< T >::OVERWROTE.

template<class T>
T* databuf< T >::pad ( int  numvals)
inlineinherited
template<class T>
void databuf< T >::put ( const T &  val)
inlineinherited
template<class T>
void databuf< T >::put ( const T *  vals,
int  numvals 
)
inlineinherited

put a given number of elements at the end of the buffer.

References databuf< T >::buf, databuf< T >::flags, databuf< T >::len, databuf< T >::maxlen, inexor::rpc::min(), and databuf< T >::OVERWROTE.

void packetbuf::put ( const uchar val)
inline
void packetbuf::put ( const uchar vals,
int  numvals 
)
inline
void packetbuf::reliable ( )
inline

set ENET_PACKET_FLAG_RELIABLE - flag

References packet.

Referenced by game::sendmessages().

template<class T>
int databuf< T >::remaining ( ) const
inlineinherited
template<class T>
void databuf< T >::reset ( )
inlineinherited
template<class T>
void databuf< T >::reset ( T *  buf_,
int  maxlen_ 
)
inlineinherited
void packetbuf::resize ( int  n)
inline

resize ENET packet, copy data and buffer length

References databuf< T >::buf, databuf< T >::maxlen, and packet.

Referenced by checkspace(), and finalize().

ucharbuf packetbuf::subbuf ( int  sz)
inline

create a sub buffer of [sz] bytes size

References checkspace(), and databuf< T >::subbuf().

Referenced by make_file_packet(), server::parsepacket(), and game::receivefile().

Member Data Documentation

template<class T>
T* databuf< T >::buf
inherited
template<class T>
uchar databuf< T >::flags
inherited
int packetbuf::growth

Referenced by checkspace(), and cleanup().

template<class T>
int databuf< T >::len
inherited
template<class T>
int databuf< T >::maxlen
inherited
ENetPacket* packetbuf::packet

The documentation for this struct was generated from the following file: