|
STAR
Cal STAR — firmware, DAQ server, and engine design
|
UDP socket implementation. More...
#include <NetworkSocket.hpp>
Public Member Functions | |
| UDPSocket (const std::string &bind_address, uint16_t bind_port) | |
| Create UDP socket bound to local address. | |
| UDPSocket (const std::string &remote_address, uint16_t remote_port, bool is_sender, const std::string &bind_address="") | |
| Create UDP socket for sending to remote address. | |
| ~UDPSocket () override | |
| ssize_t | receive (uint8_t *buffer, size_t max_size) override |
| Receive data from the socket. | |
| ssize_t | send (const uint8_t *data, size_t size) override |
| Send data through the socket. | |
| bool | is_valid () const override |
| Check if socket is valid and ready. | |
| std::string | last_error () const override |
| Get the last error message. | |
| ssize_t | receive_from (uint8_t *buffer, size_t max_size, std::string &source_address, uint16_t &source_port) |
| Receive with source address information. | |
| ssize_t | send_to (const std::string &dest_address, uint16_t dest_port, const uint8_t *data, size_t size) |
| Send UDP packet to specific destination (works on bound sockets). | |
| bool | set_broadcast (bool enable) |
| Enable broadcast (required before send_to to 255.255.255.255). | |
| Public Member Functions inherited from daq_comms::transport::NetworkSocket | |
| virtual | ~NetworkSocket ()=default |
Private Member Functions | |
| void | setup_socket () |
Private Attributes | |
| int | socket_fd_ |
| bool | is_bound_ |
| std::string | remote_address_ |
| uint16_t | remote_port_ |
| std::string | last_error_ |
UDP socket implementation.
Definition at line 50 of file NetworkSocket.hpp.
| daq_comms::transport::UDPSocket::UDPSocket | ( | const std::string & | bind_address, |
| uint16_t | bind_port ) |
Create UDP socket bound to local address.
| bind_address | Local address to bind to (e.g., "0.0.0.0") |
| bind_port | Local port to bind to |
Definition at line 17 of file NetworkSocket.cpp.
References is_bound_, last_error_, remote_port_, and socket_fd_.
| daq_comms::transport::UDPSocket::UDPSocket | ( | const std::string & | remote_address, |
| uint16_t | remote_port, | ||
| bool | is_sender, | ||
| const std::string & | bind_address = "" ) |
Create UDP socket for sending to remote address.
| remote_address | Remote address to send to |
| remote_port | Remote port to send to |
| is_sender | Tag selecting this overload |
| bind_address | Local address to send from, pinning the egress NIC. Empty or "0.0.0.0" leaves the interface to the kernel — which is only safe on a host with one route to the boards. See lib/include/net/DaqInterface.hpp. |
Definition at line 60 of file NetworkSocket.cpp.
References is_bound_, last_error_, remote_address_, remote_port_, and socket_fd_.
|
override |
Definition at line 92 of file NetworkSocket.cpp.
References socket_fd_.
|
overridevirtual |
Check if socket is valid and ready.
Implements daq_comms::transport::NetworkSocket.
Definition at line 209 of file NetworkSocket.cpp.
References socket_fd_.
|
overridevirtual |
Get the last error message.
Implements daq_comms::transport::NetworkSocket.
Definition at line 213 of file NetworkSocket.cpp.
References last_error_.
|
overridevirtual |
Receive data from the socket.
| buffer | Buffer to store received data |
| max_size | Maximum bytes to receive |
Implements daq_comms::transport::NetworkSocket.
Definition at line 98 of file NetworkSocket.cpp.
References last_error_, and socket_fd_.
| ssize_t daq_comms::transport::UDPSocket::receive_from | ( | uint8_t * | buffer, |
| size_t | max_size, | ||
| std::string & | source_address, | ||
| uint16_t & | source_port ) |
Receive with source address information.
| buffer | Buffer to store received data |
| max_size | Maximum bytes to receive |
| source_address | Output parameter for source IP |
| source_port | Output parameter for source port |
Definition at line 116 of file NetworkSocket.cpp.
References last_error_, and socket_fd_.
|
overridevirtual |
Send data through the socket.
| data | Data to send |
| size | Number of bytes to send |
Implements daq_comms::transport::NetworkSocket.
Definition at line 176 of file NetworkSocket.cpp.
References is_bound_, last_error_, remote_address_, remote_port_, and socket_fd_.
Referenced by fsw::fsw::FSWConfigManager::send_config_to_board().
| ssize_t daq_comms::transport::UDPSocket::send_to | ( | const std::string & | dest_address, |
| uint16_t | dest_port, | ||
| const uint8_t * | data, | ||
| size_t | size ) |
Send UDP packet to specific destination (works on bound sockets).
| dest_address | Destination IP (e.g. "255.255.255.255" for broadcast) |
| dest_port | Destination port |
| data | Data to send |
| size | Number of bytes |
Definition at line 152 of file NetworkSocket.cpp.
References last_error_, and socket_fd_.
| bool daq_comms::transport::UDPSocket::set_broadcast | ( | bool | enable | ) |
Enable broadcast (required before send_to to 255.255.255.255).
Definition at line 141 of file NetworkSocket.cpp.
References enable(), last_error_, and socket_fd_.
|
private |
|
private |
Definition at line 105 of file NetworkSocket.hpp.
Referenced by send(), UDPSocket(), and UDPSocket().
|
private |
Definition at line 108 of file NetworkSocket.hpp.
Referenced by last_error(), receive(), receive_from(), send(), send_to(), set_broadcast(), UDPSocket(), and UDPSocket().
|
private |
Definition at line 106 of file NetworkSocket.hpp.
Referenced by send(), and UDPSocket().
|
private |
Definition at line 107 of file NetworkSocket.hpp.
Referenced by send(), UDPSocket(), and UDPSocket().
|
private |
Definition at line 104 of file NetworkSocket.hpp.
Referenced by is_valid(), receive(), receive_from(), send(), send_to(), set_broadcast(), UDPSocket(), UDPSocket(), and ~UDPSocket().