Class UDPSocketReceive

Inheritance Relationships

Base Types

Class Documentation

class UDPSocketReceive : public ska::pst::recv::UDPSocket, public ska::pst::recv::SocketReceive

Provides implementation of a standard UDP socket for receiving UDP packets. Abstracts the complexity of interacting with linux socket libraries.

Public Functions

UDPSocketReceive()

Construct a new UDPSocketReceive object.

~UDPSocketReceive()

Destroy the UDPSocketReceive object.

virtual void allocate_resources(size_t bufsz, size_t packet_size)

Resize the linux kernel’s socket buffer to the specified size. The socket buffer is used to receive packets asynchronously whilst the application is busy on other tasks. Linux kernel restrictions might restrict the maximum size.

Parameters
  • bufsz – new size of the socket buffer

  • packet_size – size of the UDP payload

Returns

size_t size of the actual sock buffer allocated

virtual void configure(const std::string &ip_address, int port)

Open the UDP receiving socket at the specified endpoint. Opens the UDP socket at the interface associated with the specified address, or if “any” is specified, listen on any interface.

Parameters
  • ip_address – IPv4 address for receiving UDP socke

  • port – Port number for the UDP socket.

virtual void deconfigure_beam()

Release the resources in use by the receiving socket.

virtual size_t clear_buffered_packets()

Discard all packets that are waiting in the kernel’s socket buffer.

Returns

size_t number of bytes cleared.

virtual int acquire_packet()

Receive a single UDP packet into the socket buffer. If the previously received packet was not consumed via consume_packet, then no packet is received. If the socket is blocking, this method will block until a packet is received. If the socket is non-blocking, this method will busy-wait until a packet is received. In the latter case, the busy-wait may be interrupted by setting UDPSocketReceiver::keep_receiving to false.

Returns

ssize_t Number of bytes received

inline virtual void release_packet(int slot)

Marks the most recently received packet as consumed.

virtual uint64_t process_sleeps()

Return the number of accumulated sleeps, resetting the internal counter to 0.

Returns

uint64_t Number of accumulated sleeps since last reset.

virtual char *get_buf_ptr(int slot_index)

Return a pointer to the packet that is received in the specified slot.

Parameters

slot_index

Returns

char *

Public Members

char *buf_ptr = {nullptr}

Pointer to the internal socket buffer.

Public Static Attributes

static constexpr int min_size = 8

minimum valid size of a UDP packet in bytes

Protected Attributes

bool have_packet = {false}

flag for whether bufsz contains a packet

size_t kernel_socket_bufsz = {0}

Size of the kernel receive buffer in bytes.