nidas  v1.2-1520
Public Member Functions | Protected Attributes | List of all members
nidas::util::DatagramPacketT< DataT > Class Template Reference

A DatagramPacket with a specific structure of data. More...

#include <DatagramPacket.h>

Inheritance diagram for nidas::util::DatagramPacketT< DataT >:
Inheritance graph
[legend]

Public Member Functions

 DatagramPacketT (DataT *buf, int n)
 Create a datagram packet from a pointer to some data. More...
 
 DatagramPacketT (DataT *buf, int n, const Inet4Address &add, int port)
 Create a DatagramPacket for sending. More...
 
 DatagramPacketT (DataT *buf, int n, const SocketAddress &add)
 
 DatagramPacketT (const DatagramPacketT &x)
 Copy constructor. More...
 
DatagramPacketToperator= (const DatagramPacketT &rhs)
 Assignment operator. More...
 
virtual void * getDataVoidPtr ()
 Get the pointer to the data portion of the packet. More...
 
virtual const void * getConstDataVoidPtr () const
 
DataT * getData ()
 
void setData (DataT *val)
 Set the pointer to the data portion of the packet. More...
 
SocketAddressgetSocketAddress () const
 
void setSocketAddress (const SocketAddress &val)
 
struct sockaddr * getSockAddrPtr ()
 
struct sockaddr * getConstSockAddrPtr () const
 
int getSockAddrLen () const
 
virtual void setLength (int val)
 Set the value for the current number of bytes in data. More...
 
virtual int getLength () const
 Get the value for the current number of bytes in data. More...
 
void setMaxLength (int val)
 Set the allocated length in bytes of the data. More...
 
int getMaxLength () const
 Return the allocated length in bytes of the data. More...
 

Protected Attributes

DataT * data
 
int maxlength
 allocated length in bytes of contents. More...
 
int length
 length of datagram that was read or will be sent. More...
 
SocketAddressaddr
 The destination address for a send, or the remote senders address after a receive. More...
 

Detailed Description

template<class DataT>
class nidas::util::DatagramPacketT< DataT >

A DatagramPacket with a specific structure of data.

DatagramPacketT doesn not own the pointer to the data.

This class provides (default) copy constructors and assignment operators. The data pointer of the new copies will point to the same data as the original. The user is responsible for making sure that pointer is valid and the space deallocated when finished.

Constructor & Destructor Documentation

template<class DataT>
nidas::util::DatagramPacketT< DataT >::DatagramPacketT ( DataT *  buf,
int  n 
)
inline

Create a datagram packet from a pointer to some data.

The DatagramPacketT does not own the pointer to the data, and does not delete it in its destructor.

template<class DataT>
nidas::util::DatagramPacketT< DataT >::DatagramPacketT ( DataT *  buf,
int  n,
const Inet4Address add,
int  port 
)
inline

Create a DatagramPacket for sending.

Parameters
bufpointer to allocated space for contents. Pointer is owned by caller, not by the DatagramPacket. The DatagramPacket destructor does not delete it in its destructor.
nnumber of buffers of type DataT in the packet. Inet4Address to send packet to. port number to send packet to.
template<class DataT>
nidas::util::DatagramPacketT< DataT >::DatagramPacketT ( DataT *  buf,
int  n,
const SocketAddress add 
)
inline
template<class DataT>
nidas::util::DatagramPacketT< DataT >::DatagramPacketT ( const DatagramPacketT< DataT > &  x)
inline

Copy constructor.

The data pointer of the new copy points to the same data as the original. The user is responsible for making sure the pointer is valid and the space deallocated when finished.

Member Function Documentation

template<class DataT>
virtual const void* nidas::util::DatagramPacketT< DataT >::getConstDataVoidPtr ( ) const
inlinevirtual
struct sockaddr* nidas::util::DatagramPacketBase::getConstSockAddrPtr ( ) const
inlineinherited
template<class DataT>
DataT* nidas::util::DatagramPacketT< DataT >::getData ( )
inline
template<class DataT>
virtual void* nidas::util::DatagramPacketT< DataT >::getDataVoidPtr ( )
inlinevirtual

Get the pointer to the data portion of the packet.

Implements nidas::util::DatagramPacketBase.

virtual int nidas::util::DatagramPacketBase::getLength ( ) const
inlinevirtualinherited

Get the value for the current number of bytes in data.

Either the number of bytes read in a received packet, or the number of bytes to send().

References nidas::util::DatagramPacketBase::length.

Referenced by PacketReader::checkPacket(), PacketReader::logBadPacket(), PacketReader::loop(), nidas::core::DerivedDataReader::run(), WriterThread::run(), nidas::util::McSocketListener::run(), and nidas::util::McSocketMulticaster< SocketTT >::run().

int nidas::util::DatagramPacketBase::getMaxLength ( ) const
inlineinherited

Return the allocated length in bytes of the data.

References nidas::util::DatagramPacketBase::maxlength.

Referenced by PacketReader::loop().

int nidas::util::DatagramPacketBase::getSockAddrLen ( ) const
inlineinherited
struct sockaddr* nidas::util::DatagramPacketBase::getSockAddrPtr ( )
inlineinherited
SocketAddress& nidas::util::DatagramPacketBase::getSocketAddress ( ) const
inlineinherited
template<class DataT>
DatagramPacketT& nidas::util::DatagramPacketT< DataT >::operator= ( const DatagramPacketT< DataT > &  rhs)
inline

Assignment operator.

The data pointer of the new copy points to the same data as the right hand side. The user is responsible for making sure old pointer is freed and the new pointer is valid and the space deallocated when finished.

template<class DataT>
void nidas::util::DatagramPacketT< DataT >::setData ( DataT *  val)
inline

Set the pointer to the data portion of the packet.

/param val Pointer to an allocated section of memory. This pointer is owned by the caller, it is not deleted by the DatagramPacket destructor.

virtual void nidas::util::DatagramPacketBase::setLength ( int  val)
inlinevirtualinherited

Set the value for the current number of bytes in data.

/param val Number of bytes, must be <= max length.

References nidas::util::DatagramPacketBase::length.

Referenced by PacketReader::checkPacket().

void nidas::util::DatagramPacketBase::setMaxLength ( int  val)
inlineinherited

Set the allocated length in bytes of the data.

/param val Number of bytes allocated in data.

References nidas::util::DatagramPacketBase::maxlength.

void nidas::util::DatagramPacketBase::setSocketAddress ( const SocketAddress val)
inlineinherited

Member Data Documentation

SocketAddress* nidas::util::DatagramPacketBase::addr
protectedinherited
template<class DataT>
DataT* nidas::util::DatagramPacketT< DataT >::data
protected
int nidas::util::DatagramPacketBase::length
protectedinherited

length of datagram that was read or will be sent.

Must be <= maxlength.

Referenced by nidas::util::DatagramPacketBase::getLength(), nidas::util::DatagramPacketBase::operator=(), and nidas::util::DatagramPacketBase::setLength().

int nidas::util::DatagramPacketBase::maxlength
protectedinherited

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