karoo::datagram_message Class Reference

This class represents a datagram message (received, or to send). More...

#include <datagram.h>

Inheritance diagram for karoo::datagram_message:

karoo::referable karoo::rock_datagram_message

List of all members.

Public Member Functions

 datagram_message (size_t alloc_size)
 Create a messsage with no address, but with a buffer allocated to contain data.
 datagram_message (size_t alloc_size, const text &ip, int port)
 Create a messsage with address, and a buffer allocated to contain data.
 datagram_message (const void *data, size_t size, const text &ip, int port)
 Create a messsage with address, and a buffer allocated and initialised.
virtual datagram_messageclone (size_t alloc_size=0) const =0
 Create a copy of the message.
virtual datagram_messageclone (int port, size_t alloc_size=0) const =0
 Create a copy of the message, but change its port number.
void init (const text &ip, int port)
 This method is called by the constructors to initialise the message.
size_t getSize () const
 get the size of data actually written into the buffer
uint8_t * getDataPtr ()
 get a direct pointer to the actual data

Protected Attributes

size_t addrlen
 The length of the address structure (this is dependant on the type of address).
struct sockaddr * addr
 The address structure.
size_t size
 The size of the data in the allocated data.
size_t alloc_size
 The allocated size of the date.
uint8_t * data
 The data buffer.

Friends

class datagram_server
class datagram_client


Detailed Description

This class represents a datagram message (received, or to send).

It contains all the information about the message: its size, data, and address.


Constructor & Destructor Documentation

karoo::datagram_message::datagram_message ( size_t  alloc_size,
const text ip,
int  port 
)

Create a messsage with address, and a buffer allocated to contain data.

Parameters:
alloc_size the size of the buffer to allocate for data
ip the IP address (this can be an empty string to mean localhost, or it can be a host name, or in nnn.nnn.nnn.nnn format)
port the port to send to
Exceptions:
bad_address exception if there was a problem with the address

karoo::datagram_message::datagram_message ( const void *  data,
size_t  size,
const text ip,
int  port 
)

Create a messsage with address, and a buffer allocated and initialised.

Parameters:
data the data to initialise with
size the amount of data to initialise
ip the IP address (this can be an empty string to mean localhost, or it can be a host name, or in nnn.nnn.nnn.nnn format)
port the port to send to
Exceptions:
bad_address exception if there was a problem with the address


Member Function Documentation

virtual datagram_message* karoo::datagram_message::clone ( int  port,
size_t  alloc_size = 0 
) const [pure virtual]

Create a copy of the message, but change its port number.

This is usually used to create a message already addressed to reply to an incoming message.

Parameters:
alloc_size if this is zero, then the new allocated size will be identical to this one's allocated size, otherwise, it will use the new value). Note that this clone must copy the old address across, but it creates a data buffer that is initialised to contain nothing. By "containing nothing", this means that the data buffer is allocated, but the size value is zero. In other words, the amount of valid data in the buffer is none.

Implemented in karoo::rock_datagram_message.

virtual datagram_message* karoo::datagram_message::clone ( size_t  alloc_size = 0  )  const [pure virtual]

Create a copy of the message.

Parameters:
alloc_size if this is zero, then the new allocated size will be identical to this one's allocated size, otherwise, it will use the new value). Note that this clone must copy the old address across, but it creates a data buffer that is initialised to contain nothing. By "containing nothing", this means that the data buffer is allocated, but the size value is zero. In other words, the amount of valid data in the buffer is none.

Implemented in karoo::rock_datagram_message.


Member Data Documentation

The length of the address structure (this is dependant on the type of address).

The allocated size of the date.

uint8_t* karoo::datagram_message::data [protected]

The data buffer.

Referenced by getDataPtr().

size_t karoo::datagram_message::size [protected]

The size of the data in the allocated data.

(This may be less than the allocated buffer).

Referenced by getSize().


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

Generated on Tue Feb 16 15:04:30 2010 for Karoo by  doxygen 1.5.8