Flexiport  2.0.0
Public Member Functions | List of all members
flexiport::UDPPort Class Reference

UDP implementation of the Port class. More...

#include <flexiport/udpport.h>

Inheritance diagram for flexiport::UDPPort:
Inheritance graph
[legend]
Collaboration diagram for flexiport::UDPPort:
Collaboration graph
[legend]

Public Member Functions

 UDPPort (std::map< std::string, std::string > options)
 
 ~UDPPort ()
 
void Open ()
 Open the port. More...
 
void Close ()
 Close the port. More...
 
ssize_t Read (void *const buffer, size_t count)
 Read from the port. More...
 
ssize_t ReadFull (void *const buffer, size_t count)
 Read the requested quantity of data from the port. More...
 
ssize_t ReadUntil (void *const buffer, size_t count, uint8_t terminator)
 Read data until a specified termination byte is received. More...
 
ssize_t ReadStringUntil (std::string &buffer, char terminator)
 Read a string until the specified termination character is received. More...
 
ssize_t Skip (size_t count)
 Dump data until the specified number of bytes have been read. More...
 
ssize_t SkipUntil (uint8_t terminator, unsigned int count)
 Read and dump data until the specified termination character has been seen count times. More...
 
ssize_t BytesAvailable ()
 Get the number of bytes waiting to be read at the port. Returns immediatly. More...
 
ssize_t BytesAvailableWait ()
 Get the number of bytes waiting after blocking for the timeout. More...
 
ssize_t Write (const void *const buffer, size_t count)
 Write data to the port. More...
 
void Flush ()
 Flush the port's input and output buffers, discarding all data. More...
 
void Drain ()
 Drain the port's input and output buffers. More...
 
std::string GetStatus () const
 Get the status of the port (type, device, etc). More...
 
void SetTimeout (Timeout timeout)
 Set the timeout value in milliseconds. More...
 
void SetCanRead (bool canRead)
 Set the read permissions of the port. More...
 
void SetCanWrite (bool canWrite)
 Set the write permissions of the port. More...
 
bool IsOpen () const
 Check if the port is open. More...
 
- Public Member Functions inherited from flexiport::Port
virtual ~Port ()
 
virtual ssize_t ReadString (std::string &buffer)
 Read a string. More...
 
virtual ssize_t ReadLine (char *const buffer, size_t count)
 Read a new-line terminated string of data. More...
 
virtual ssize_t ReadLine (std::string &buffer)
 Read a new-line terminated string of data. More...
 
virtual ssize_t WriteFull (const void *const buffer, size_t count)
 Write all the data to the port. More...
 
virtual ssize_t WriteString (const char *const buffer)
 Write a string to the port. More...
 
virtual ssize_t WriteString (const std::string &buffer)
 
std::string GetPortType () const
 Get the port type. More...
 
void SetDebug (int debug)
 Set the debug level. More...
 
int GetDebug () const
 Get the debug level. More...
 
virtual Timeout GetTimeout () const
 Get the timeout. More...
 
virtual bool IsBlocking () const
 Get the blocking property of the port. More...
 
virtual bool CanRead () const
 Get the read permissions of the port. More...
 
virtual bool CanWrite () const
 Get the write permissions of the port. More...
 

Additional Inherited Members

- Protected Member Functions inherited from flexiport::Port
 Port ()
 
 Port (unsigned int debug, Timeout timeout, bool canRead, bool canWrite, bool alwaysOpen)
 
void ProcessOptions (const std::map< std::string, std::string > &options)
 
- Protected Attributes inherited from flexiport::Port
std::string _type
 
unsigned int _debug
 
Timeout _timeout
 
bool _canRead
 
bool _canWrite
 
bool _alwaysOpen
 

Detailed Description

UDP implementation of the Port class.

This class provides UDP communication between two known end points. It cannot send to any address other than the configured address.

See the Port class documentation for how to use the common API. Note that some parts of the API do not apply due to the nature of the datagram-oriented protocol. Because each datagram is individual and no merging is typically performed between datagrams, several flexiport functions do not work (they were designed for stream-oriented communications). These are ReadStringUntil, ReadLine (std::string version), Skip, and SkipUntil. This will be (hopefully) be fixed soon.

TODO: Add support for configuring the destination address based on the first data received, to allow destination auto-configuration.

TODO: Add an option to turn buffering on, making the UDP protocol function like a stream-based protocol and so enabling the use of those parts of the API that do not function correctly for a datagram-based protocol. Alternatively, fix the functions that don't work yet so they read more than a byte at a time.

Options
  • dest_ip <string>
    • IP address to send data to.
    • Default: 127.0.0.1
  • dest_port <integer>
    • UDP port to send data to.
    • Default: 20000
  • recv_ip <string>
    • IP address to receive data on. Set to "*" for receiving on any interface.
    • Default: *
  • recv_port <integer>
    • UDP port to receive data on.
    • Default: 20000

Definition at line 83 of file udpport.h.

Constructor & Destructor Documentation

flexiport::UDPPort::UDPPort ( std::map< std::string, std::string >  options)
flexiport::UDPPort::~UDPPort ( )

Member Function Documentation

ssize_t flexiport::UDPPort::BytesAvailable ( )
virtual

Get the number of bytes waiting to be read at the port. Returns immediatly.

Implements flexiport::Port.

ssize_t flexiport::UDPPort::BytesAvailableWait ( )
virtual

Get the number of bytes waiting after blocking for the timeout.

Implements flexiport::Port.

void flexiport::UDPPort::Close ( )
virtual

Close the port.

Implements flexiport::Port.

void flexiport::UDPPort::Drain ( )
virtual

Drain the port's input and output buffers.

Implements flexiport::Port.

void flexiport::UDPPort::Flush ( )
virtual

Flush the port's input and output buffers, discarding all data.

Implements flexiport::Port.

std::string flexiport::UDPPort::GetStatus ( ) const
virtual

Get the status of the port (type, device, etc).

Reimplemented from flexiport::Port.

bool flexiport::UDPPort::IsOpen ( ) const
inlinevirtual

Check if the port is open.

Implements flexiport::Port.

Definition at line 127 of file udpport.h.

void flexiport::UDPPort::Open ( )
virtual

Open the port.

This will create a listening socket and a sending socket.

Implements flexiport::Port.

ssize_t flexiport::UDPPort::Read ( void *const  buffer,
size_t  count 
)
virtual

Read from the port.

Implements flexiport::Port.

ssize_t flexiport::UDPPort::ReadFull ( void *const  buffer,
size_t  count 
)
virtual

Read the requested quantity of data from the port.

Implements flexiport::Port.

ssize_t flexiport::UDPPort::ReadStringUntil ( std::string &  buffer,
char  terminator 
)
virtual

Read a string until the specified termination character is received.

Reimplemented from flexiport::Port.

ssize_t flexiport::UDPPort::ReadUntil ( void *const  buffer,
size_t  count,
uint8_t  terminator 
)
virtual

Read data until a specified termination byte is received.

Reimplemented from flexiport::Port.

void flexiport::UDPPort::SetCanRead ( bool  canRead)
virtual

Set the read permissions of the port.

Implements flexiport::Port.

void flexiport::UDPPort::SetCanWrite ( bool  canWrite)
virtual

Set the write permissions of the port.

Implements flexiport::Port.

void flexiport::UDPPort::SetTimeout ( Timeout  timeout)
virtual

Set the timeout value in milliseconds.

Implements flexiport::Port.

ssize_t flexiport::UDPPort::Skip ( size_t  count)
virtual

Dump data until the specified number of bytes have been read.

Reimplemented from flexiport::Port.

ssize_t flexiport::UDPPort::SkipUntil ( uint8_t  terminator,
unsigned int  count 
)
virtual

Read and dump data until the specified termination character has been seen count times.

Reimplemented from flexiport::Port.

ssize_t flexiport::UDPPort::Write ( const void *const  buffer,
size_t  count 
)
virtual

Write data to the port.

Implements flexiport::Port.


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