Open Lighting Architecture  0.9.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
ola::network::UDPSocketInterface Class Reference

Detailed Description

The interface for UDPSockets.

This only supports IPv4 sockets. Its an Interface so we can mock it out for testing.

Inheritance diagram for ola::network::UDPSocketInterface:
ola::io::BidirectionalFileDescriptor ola::io::ReadFileDescriptor ola::io::WriteFileDescriptor ola::network::UDPSocket ola::testing::MockUDPSocket

Public Member Functions

virtual bool Init ()=0
 Initialize the socket.
virtual bool Bind (const IPV4SocketAddress &endpoint)=0
 Bind this socket to an external address:port.
virtual bool GetSocketAddress (IPV4SocketAddress *address) const =0
 Return the local address this socket is bound to.
virtual bool Close ()=0
 Close the socket.
virtual ola::io::DescriptorHandle ReadDescriptor () const =0
 Returns the read descriptor for this socket.
virtual ola::io::DescriptorHandle WriteDescriptor () const =0
 Returns the write descriptor for this socket.
virtual ssize_t SendTo (const uint8_t *buffer, unsigned int size, const IPV4Address &ip, unsigned short port) const =0
 Send data on this UDPSocket.
virtual ssize_t SendTo (const uint8_t *buffer, unsigned int size, const IPV4SocketAddress &dest) const =0
 Send data on this UDPSocket.
virtual ssize_t SendTo (ola::io::IOVecInterface *data, const IPV4Address &ip, unsigned short port) const =0
 Send data from an IOVecInterface.
virtual ssize_t SendTo (ola::io::IOVecInterface *data, const IPV4SocketAddress &dest) const =0
 Send data from an IOVecInterface.
virtual bool RecvFrom (uint8_t *buffer, ssize_t *data_read) const =0
 Receive data.
virtual bool RecvFrom (uint8_t *buffer, ssize_t *data_read, IPV4Address &source) const =0
 Receive data.
virtual bool RecvFrom (uint8_t *buffer, ssize_t *data_read, IPV4Address &source, uint16_t &port) const =0
 Receive data and record the src address & port.
virtual bool RecvFrom (uint8_t *buffer, ssize_t *data_read, IPV4SocketAddress *source)=0
 Receive a datagram on the UDP Socket.
virtual bool EnableBroadcast ()=0
 Enable broadcasting for this socket.
virtual bool SetMulticastInterface (const IPV4Address &iface)=0
 Set the outgoing interface to be used for multicast transmission.
virtual bool JoinMulticast (const IPV4Address &iface, const IPV4Address &group, bool multicast_loop=false)=0
 Join a multicast group.
virtual bool LeaveMulticast (const IPV4Address &iface, const IPV4Address &group)=0
 Leave a multicast group.
virtual bool SetTos (uint8_t tos)=0
 Set the tos field for a socket.
- Public Member Functions inherited from ola::io::BidirectionalFileDescriptor
void SetOnData (ola::Callback0< void > *on_read)
 Set the callback to be run when data is available for reading.
void SetOnWritable (ola::Callback0< void > *on_write)
 Set the callback to be run when the descriptor can be written to.
void PerformRead ()
 Called when there is data available on the descriptor.
void PerformWrite ()
 Called when the descriptor can be written to.
- Public Member Functions inherited from ola::io::ReadFileDescriptor
bool ValidReadDescriptor () const
 Check if this file descriptor is valid.
- Public Member Functions inherited from ola::io::WriteFileDescriptor
bool ValidWriteDescriptor () const
 Check if this file descriptor is valid.

Member Function Documentation

virtual bool ola::network::UDPSocketInterface::Bind ( const IPV4SocketAddress endpoint)
pure virtual

Bind this socket to an external address:port.

Parameters
endpointthe local socket address to bind to.
Returns
true if the bind succeeded, false if it failed.

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual bool ola::network::UDPSocketInterface::Close ( )
pure virtual

Close the socket.

Returns
true if the call succeeded, false if it failed.

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual bool ola::network::UDPSocketInterface::EnableBroadcast ( )
pure virtual

Enable broadcasting for this socket.

Returns
true if it worked, false otherwise

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual bool ola::network::UDPSocketInterface::GetSocketAddress ( IPV4SocketAddress address) const
pure virtual

Return the local address this socket is bound to.

Parameters
[out]addressthe local socket address this socket is bound to.
Returns
true if the call succeeded, false if it failed.

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual bool ola::network::UDPSocketInterface::Init ( )
pure virtual

Initialize the socket.

Returns
false if initialization failed.

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual bool ola::network::UDPSocketInterface::JoinMulticast ( const IPV4Address iface,
const IPV4Address group,
bool  multicast_loop = false 
)
pure virtual

Join a multicast group.

Parameters
ifacethe address of the interface to use.
groupthe address of the group to join
multicast_loopenable multicast loop
Returns
true if it worked, false otherwise

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual bool ola::network::UDPSocketInterface::LeaveMulticast ( const IPV4Address iface,
const IPV4Address group 
)
pure virtual

Leave a multicast group.

Parameters
ifacethe address of the interface to use.
groupthe address of the group to join
Returns
true if it worked, false otherwise

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual ola::io::DescriptorHandle ola::network::UDPSocketInterface::ReadDescriptor ( ) const
pure virtual

Returns the read descriptor for this socket.

Returns
the DescriptorHandle for this descriptor.

Implements ola::io::ReadFileDescriptor.

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual bool ola::network::UDPSocketInterface::RecvFrom ( uint8_t *  buffer,
ssize_t *  data_read 
) const
pure virtual

Receive data.

Parameters
bufferthe buffer to store the data
data_readthe size of the buffer, updated with the number of bytes read
Returns
true or false

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual bool ola::network::UDPSocketInterface::RecvFrom ( uint8_t *  buffer,
ssize_t *  data_read,
IPV4Address source 
) const
pure virtual

Receive data.

Parameters
bufferthe buffer to store the data
data_readthe size of the buffer, updated with the number of bytes read
sourcethe src ip of the packet
Returns
true or false
Deprecated:
Use the IPV4SocketAddress version instead.

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual bool ola::network::UDPSocketInterface::RecvFrom ( uint8_t *  buffer,
ssize_t *  data_read,
IPV4Address source,
uint16_t &  port 
) const
pure virtual

Receive data and record the src address & port.

Parameters
bufferthe buffer to store the data
data_readthe size of the buffer, updated with the number of bytes read
sourcethe src ip of the packet
portthe src port of the packet in host byte order
Returns
true or false
Deprecated:
Use the IPV4SocketAddress version instead.

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual bool ola::network::UDPSocketInterface::RecvFrom ( uint8_t *  buffer,
ssize_t *  data_read,
IPV4SocketAddress source 
)
pure virtual

Receive a datagram on the UDP Socket.

Parameters
bufferthe buffer to store the data
data_readthe size of the buffer, updated with the number of bytes read
sourcethe source of the datagram.
Returns
true or false

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual ssize_t ola::network::UDPSocketInterface::SendTo ( const uint8_t *  buffer,
unsigned int  size,
const IPV4Address ip,
unsigned short  port 
) const
pure virtual

Send data on this UDPSocket.

Parameters
bufferthe data to send
sizethe length of the data
ipthe IP to send to
portthe port to send to in HOST byte order.
Returns
the number of bytes sent.
Deprecated:
Use the IPV4SocketAddress version instead.

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual ssize_t ola::network::UDPSocketInterface::SendTo ( const uint8_t *  buffer,
unsigned int  size,
const IPV4SocketAddress dest 
) const
pure virtual

Send data on this UDPSocket.

Parameters
bufferthe data to send
sizethe length of the data
destthe IP:Port to send the datagram to.
Returns
the number of bytes sent

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual ssize_t ola::network::UDPSocketInterface::SendTo ( ola::io::IOVecInterface data,
const IPV4Address ip,
unsigned short  port 
) const
pure virtual

Send data from an IOVecInterface.

Parameters
datathe IOVecInterface class to send.
ipthe IP to send to
portthe port to send to in HOST byte order.
Returns
the number of bytes sent.
Deprecated:
Use the IPV4SocketAddress version instead.

This will try to send as much data as possible. If the data exceeds the MTU the UDP packet will probably get fragmented at the IP layer (depends on OS really). Try to avoid this.

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual ssize_t ola::network::UDPSocketInterface::SendTo ( ola::io::IOVecInterface data,
const IPV4SocketAddress dest 
) const
pure virtual

Send data from an IOVecInterface.

Parameters
datathe IOVecInterface class to send.
destthe IPV4SocketAddress to send to
Returns
the number of bytes sent.

This will try to send as much data as possible. If the data exceeds the MTU the UDP packet will probably get fragmented at the IP layer (depends on OS really). Try to avoid this.

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual bool ola::network::UDPSocketInterface::SetMulticastInterface ( const IPV4Address iface)
pure virtual

Set the outgoing interface to be used for multicast transmission.

Parameters
ifacethe address of the interface to use.

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual bool ola::network::UDPSocketInterface::SetTos ( uint8_t  tos)
pure virtual

Set the tos field for a socket.

Parameters
tosthe tos field
Returns
true if it worked, false otherwise

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.

virtual ola::io::DescriptorHandle ola::network::UDPSocketInterface::WriteDescriptor ( ) const
pure virtual

Returns the write descriptor for this socket.

Returns
the DescriptorHandle for this descriptor.

Implements ola::io::WriteFileDescriptor.

Implemented in ola::network::UDPSocket, and ola::testing::MockUDPSocket.


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