dashel  1.3.3
Public Member Functions | List of all members
Dashel::PacketStream Class Referenceabstract

A data stream, that can be later send data as at UDP packet or read data from an UDP packet. More...

#include <dashel.h>

Inheritance diagram for Dashel::PacketStream:
Dashel::Stream

Public Member Functions

 PacketStream (const std::string &protocolName)
 Constructor.
 
virtual void send (const IPV4Address &dest)=0
 Send all written data to an IP address in a single packet. More...
 
virtual void receive (IPV4Address &source)=0
 Receive a packet and make its payload available for reading. More...
 
- Public Member Functions inherited from Dashel::Stream
void fail (DashelException::Source s, int se, const char *reason)
 Set stream to failed state. More...
 
bool failed () const
 Query failed state of stream. More...
 
const std::string & getFailReason () const
 Returns the reason the stream has failed. More...
 
const std::string & getProtocolName () const
 Returns the protocol name of the stream.
 
std::string getTargetName () const
 Returns the name of the target. More...
 
const std::string & getTargetParameter (const char *param) const
 Returns the value of a parameter extracted from the target. More...
 
const ParameterSet getTarget () const
 Returns the target description. More...
 
virtual void write (const void *data, const size_t size)=0
 Write data to the stream. More...
 
template<typename T >
void write (T v)
 Write a variable of basic type to the stream. More...
 
virtual void flush ()=0
 Flushes stream. More...
 
virtual void read (void *data, size_t size)=0
 Reads data from the stream. More...
 
template<typename T >
read ()
 Read a variable of basic type from the stream. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Dashel::Stream
 Stream (const std::string &protocolName)
 Constructor.
 
virtual ~Stream ()
 Virtual destructor, to ensure calls to destructors of sub-classes.
 
- Protected Attributes inherited from Dashel::Stream
ParameterSet target
 The target description.
 
std::string protocolName
 The protocol name.
 

Detailed Description

A data stream, that can be later send data as at UDP packet or read data from an UDP packet.

You can use PacketStream to write and read data as with normal stream, with the difference that: written byte will be collected in a send buffer until send() is called with the destination address; if you have written too much byte for send to transmit all of them an exception will occur. However, the underlying operating system may pretend that all data has been transmitted while discarding some of it anyway. In any case, send less bytes than ethernet MTU minus UDP header. you have to call receive() when there are bytes available on the stream to be able to read them; if your read past the received bytes an exception will occur.

Member Function Documentation

virtual void Dashel::PacketStream::receive ( IPV4Address source)
pure virtual

Receive a packet and make its payload available for reading.

Block until a packet is available.

Parameters
sourceIP address from where the packet originates.
virtual void Dashel::PacketStream::send ( const IPV4Address dest)
pure virtual

Send all written data to an IP address in a single packet.

Parameters
destIP address to send packet to

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