Fawkes API  Fawkes Development Version
fawkes::MulticastDatagramSocket Class Reference

Multicast datagram socket. More...

#include <netcomm/socket/datagram.h>

Inheritance diagram for fawkes::MulticastDatagramSocket:

Public Member Functions

 MulticastDatagramSocket (AddrType addr_type, const char *multicast_addr_s, unsigned short port, float timeout=0.f)
 Constructor. More...
 
 MulticastDatagramSocket (MulticastDatagramSocket &s)
 Copy constructor. More...
 
virtual ~MulticastDatagramSocket ()
 Destructor. More...
 
virtual Socketclone ()
 Clone socket. More...
 
virtual void bind ()
 Bind socket. More...
 
virtual void bind (const unsigned short int port)
 Bind socket. More...
 
virtual void bind (const unsigned short int port, const char *hostname)
 Bind socket to a specific address. More...
 
virtual void send (void *buf, size_t buf_len)
 Send data. More...
 
virtual void send (void *buf, size_t buf_len, const struct sockaddr *to_addr, socklen_t addr_len)
 Send message. More...
 
void set_loop (bool loop)
 Set loopback of sent packets. More...
 
void set_ttl (int ttl)
 Set multicast time-to-live (TTL) More...
 
- Public Member Functions inherited from fawkes::Socket
 Socket (AddrType addr_type, SocketType sock_type, float timeout=0.f)
 Constructor similar to syscall. More...
 
 Socket (Socket &socket)
 Copy constructor. More...
 
virtual ~Socket ()
 Destructor. More...
 
virtual void connect (const char *hostname, const unsigned short int port)
 Connect socket. More...
 
virtual void connect (const struct ::sockaddr_storage &addr_port)
 Connect socket. More...
 
virtual void connect (const struct sockaddr *addr_port, socklen_t struct_size)
 Connect socket. More...
 
virtual void listen (int backlog=1)
 Listen on socket. More...
 
virtual Socketaccept ()
 Accept connection. More...
 
virtual void close ()
 Close socket. More...
 
virtual bool available ()
 Check if data is available. More...
 
virtual size_t read (void *buf, size_t count, bool read_all=true)
 Read from socket. More...
 
virtual void write (const void *buf, size_t count)
 Write to the socket. More...
 
virtual size_t recv (void *buf, size_t buf_len)
 Read from socket. More...
 
virtual size_t recv (void *buf, size_t buf_len, struct sockaddr *from_addr, socklen_t *addr_len)
 Receive data. More...
 
virtual short poll (int timeout=-1, short what=POLL_IN|POLL_HUP|POLL_PRI|POLL_RDHUP)
 Wait for some event on socket. More...
 
virtual bool listening ()
 Is socket listening for connections? More...
 
virtual unsigned int mtu ()
 Maximum Transfer Unit (MTU) of socket. More...
 
template<class SocketTypeC >
SocketTypeC * accept ()
 Accept connection. More...
 

Additional Inherited Members

- Public Types inherited from fawkes::Socket
enum  AddrType { UNSPECIFIED, IPv4, IPv6 }
 Address type specification. More...
 
enum  SocketType { TCP, UDP }
 Socket type. More...
 
- Static Public Attributes inherited from fawkes::Socket
static const short POLL_IN = POLLIN
 Data can be read. More...
 
static const short POLL_OUT = POLLOUT
 Writing will not block. More...
 
static const short POLL_PRI = POLLPRI
 There is urgent data to read (e.g., out-of-band data on TCP socket; pseudo-terminal master in packet mode has seen state change in slave). More...
 
static const short POLL_RDHUP = 0
 Stream socket peer closed connection, or shut down writing half of connection. More...
 
static const short POLL_ERR = POLLERR
 Error condition. More...
 
static const short POLL_HUP = POLLHUP
 Hang up. More...
 
static const short POLL_NVAL = POLLNVAL
 Invalid request. More...
 
- Protected Member Functions inherited from fawkes::Socket
 Socket (SocketType sock_type, float timeout=0.f)
 IPv4 Constructor. More...
 
 Socket ()
 Constructor. More...
 
- Protected Attributes inherited from fawkes::Socket
AddrType addr_type
 Address type/family of socket. More...
 
int sock_fd
 Socket file descriptor. More...
 
float timeout
 Timeout in seconds for various operations. More...
 
struct ::sockaddr_storage * client_addr
 Client address, set if connected. More...
 
unsigned int client_addr_len
 length in bytes of client address. More...
 

Detailed Description

Multicast datagram socket.

An multicast UDP socket on top of IP.

Author
Tim Niemueller

Definition at line 32 of file datagram_multicast.h.

Constructor & Destructor Documentation

◆ MulticastDatagramSocket() [1/2]

fawkes::MulticastDatagramSocket::MulticastDatagramSocket ( AddrType  addr_type,
const char *  multicast_addr_s,
unsigned short  port,
float  timeout = 0.f 
)

Constructor.

Parameters
addr_typeSpecify IPv4 or IPv6
multicast_addr_stextual representation of the multicast IP address to use for multicast communication. NOT a hostname!
portport
timeouttimeout, if 0 all operationsare blocking, otherwise it is tried for timeout seconds.

Definition at line 51 of file datagram_multicast.cpp.

References set_loop().

Referenced by clone().

◆ MulticastDatagramSocket() [2/2]

fawkes::MulticastDatagramSocket::MulticastDatagramSocket ( MulticastDatagramSocket datagram_socket)

Copy constructor.

Parameters
datagram_socketsocket to copy.

Definition at line 82 of file datagram_multicast.cpp.

◆ ~MulticastDatagramSocket()

fawkes::MulticastDatagramSocket::~MulticastDatagramSocket ( )
virtual

Destructor.

Definition at line 73 of file datagram_multicast.cpp.

Member Function Documentation

◆ bind() [1/3]

void fawkes::MulticastDatagramSocket::bind ( )
virtual

Bind socket.

This will make the socket listen for incoming traffic. It will also add this host to the appropriate multicast group.

Definition at line 95 of file datagram_multicast.cpp.

References fawkes::Socket::sock_fd.

Referenced by bind(), and Msl2010RefBoxProcessor::~Msl2010RefBoxProcessor().

◆ bind() [2/3]

void fawkes::MulticastDatagramSocket::bind ( const unsigned short int  port)
virtual

Bind socket.

Can only be called on stream sockets.

Parameters
portport to bind
Exceptions
SocketExceptionthrown if socket cannot bind, check errno for cause

Reimplemented from fawkes::Socket.

Definition at line 121 of file datagram_multicast.cpp.

References bind().

◆ bind() [3/3]

void fawkes::MulticastDatagramSocket::bind ( const unsigned short int  port,
const char *  ipaddr 
)
virtual

Bind socket to a specific address.

Parameters
portport to bind
ipaddrtextual IP address of a local interface to bind to, must match the address type passed to the constructor.
Exceptions
SocketExceptionthrown if socket cannot bind, check errno for cause

Reimplemented from fawkes::Socket.

Definition at line 129 of file datagram_multicast.cpp.

References bind().

◆ clone()

Socket * fawkes::MulticastDatagramSocket::clone ( )
virtual

Clone socket.

Returns
a copied instance of MulticastDatagramSocket.

Implements fawkes::Socket.

Definition at line 149 of file datagram_multicast.cpp.

References MulticastDatagramSocket().

◆ send() [1/2]

void fawkes::MulticastDatagramSocket::send ( void *  buf,
size_t  buf_len 
)
virtual

Send data.

This will send the given data to the multicast address specified in the constructor.

Parameters
bufbuffer to write
buf_lenlength of buffer, number of bytes to write to stream

Reimplemented from fawkes::Socket.

Definition at line 162 of file datagram_multicast.cpp.

References fawkes::Exception::append(), and fawkes::Socket::send().

Referenced by send().

◆ send() [2/2]

virtual void fawkes::MulticastDatagramSocket::send ( void *  buf,
size_t  buf_len,
const struct sockaddr *  addr,
socklen_t  addr_len 
)
inlinevirtual

Send message.

Parameters
bufbuffer with data to send
buf_lenlength of buffer, all data will be send.
addraddr to send data to.
addr_lenlength of address

Reimplemented from fawkes::Socket.

Definition at line 49 of file datagram_multicast.h.

References send(), set_loop(), and set_ttl().

◆ set_loop()

void fawkes::MulticastDatagramSocket::set_loop ( bool  loop)

Set loopback of sent packets.

Parameters
looptrue to deliver sent packets to local sockets, false prevent delivering

Definition at line 177 of file datagram_multicast.cpp.

References fawkes::Socket::sock_fd.

Referenced by MulticastDatagramSocket(), send(), and Msl2010RefBoxProcessor::~Msl2010RefBoxProcessor().

◆ set_ttl()

void fawkes::MulticastDatagramSocket::set_ttl ( int  ttl)

Set multicast time-to-live (TTL)

Parameters
ttltime-to-live

Definition at line 190 of file datagram_multicast.cpp.

References fawkes::Socket::sock_fd.

Referenced by send().


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