Open Lighting Architecture: ola::network::UDPSocketInterface Class Reference

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
Public Member Functions | List of all members
ola::network::UDPSocketInterface Class Referenceabstract

## 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:

## 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

## ◆ Bind()

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

Bind this socket to an external address:port.

Parameters

  endpoint | the local socket address to bind to.

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

Implemented in ola::network::UDPSocket, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ Close()

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, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ EnableBroadcast()

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, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ GetSocketAddress()

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

Return the local address this socket is bound to.

Parameters

  [out] | address | the local socket address this socket is bound to.

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

Implemented in ola::network::UDPSocket, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ Init()

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

Initialize the socket.

Returns
  false if initialization failed.

Implemented in ola::network::UDPSocket, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ JoinMulticast()

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

Join a multicast group.

Parameters

  iface | the address of the interface to use.
  group | the address of the group to join
  multicast_loop | enable multicast loop

Returns
  true if it worked, false otherwise

Implemented in ola::network::UDPSocket, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ LeaveMulticast()

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

Leave a multicast group.

Parameters

  iface | the address of the interface to use.
  group | the address of the group to join

Returns
  true if it worked, false otherwise

Implemented in ola::network::UDPSocket, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ ReadDescriptor()

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, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ RecvFrom() [1/4]

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

Receive data.

Parameters

  buffer | the buffer to store the data
  data_read | the size of the buffer, updated with the number of bytes read

Returns
  true or false

Implemented in ola::network::UDPSocket, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ RecvFrom() [2/4]

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

Receive data.

Parameters

  buffer | the buffer to store the data
  data_read | the size of the buffer, updated with the number of bytes read
  source | the src ip of the packet

Returns
  true or false

Deprecated
  Use the IPV4SocketAddress version instead.

Implemented in ola::network::UDPSocket, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ RecvFrom() [3/4]

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

  buffer | the buffer to store the data
  data_read | the size of the buffer, updated with the number of bytes read
  source | the src ip of the packet
  port | the src port of the packet in host byte order

Returns
  true or false

Deprecated
  Use the IPV4SocketAddress version instead.

Implemented in ola::network::UDPSocket, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ RecvFrom() [4/4]

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

  buffer | the buffer to store the data
  data_read | the size of the buffer, updated with the number of bytes read
  source | the source of the datagram.

Returns
  true or false

Implemented in ola::network::UDPSocket, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ SendTo() [1/4]

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

  buffer | the data to send
  size | the length of the data
  ip | the IP to send to
  port | the 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, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ SendTo() [2/4]

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

  buffer | the data to send
  size | the length of the data
  dest | the IP:Port to send the datagram to.

Returns
  the number of bytes sent

Implemented in ola::network::UDPSocket, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ SendTo() [3/4]

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

  data | the IOVecInterface class to send.
  ip | the IP to send to
  port | the 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, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ SendTo() [4/4]

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

Send data from an IOVecInterface.

Parameters

  data | the IOVecInterface class to send.
  dest | the 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, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ SetMulticastInterface()

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

Set the outgoing interface to be used for multicast transmission.

Parameters

  iface | the address of the interface to use.

Implemented in ola::network::UDPSocket, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ SetTos()

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

Set the tos field for a socket.

Parameters

  tos | the tos field

Returns
  true if it worked, false otherwise

Implemented in ola::network::UDPSocket, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

## ◆ WriteDescriptor()

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, ola::plugin::artnet::UDPSocket, ola::plugin::espnet::UDPSocket, ola::plugin::kinet::UDPSocket, ola::plugin::pathport::UDPSocket, ola::plugin::sandnet::UDPSocket, ola::plugin::shownet::UDPSocket, and UDPSocket.

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

- include/ola/network/Socket.h