|
STAR
Cal STAR — firmware, DAQ server, and engine design
|
Simple TCP client for Elodin database connection. More...
#include <TCPClient.hpp>
Public Member Functions | |
| TCPClient () | |
| ~TCPClient () | |
| bool | connect (const std::string &host, uint16_t port) |
| Connect to TCP server. | |
| void | disconnect () |
| Disconnect from server. | |
| bool | is_connected () const |
| Check if connected. | |
| bool | write_all (const void *data, size_t len) |
| Write data directly (for VTable registration). | |
| bool | write_buffered (const void *data, size_t len) |
| Write data with buffering (for data publishing). | |
| void | flush () |
| Flush buffered data. | |
| ssize_t | read (void *buffer, size_t max_len) |
| Read data from socket (non-blocking). | |
| bool | read_exact (void *buffer, size_t len) |
| Read exactly len bytes (blocking). | |
| std::string | last_error () const |
| Get last error message. | |
| void | set_recv_timeout_ms (int timeout_ms) |
| Set socket receive timeout (0 = blocking). | |
Private Member Functions | |
| bool | _write_all (const void *data, size_t len) |
| void | _flush_buffer () |
Private Attributes | |
| int | socket_fd_ |
| bool | connected_ |
| std::string | last_error_ |
| std::vector< uint8_t > | write_buffer_ |
| size_t | buffer_pos_ |
| std::mutex | write_mutex_ |
Static Private Attributes | |
| static constexpr size_t | BUFFER_SIZE = 8192 |
Simple TCP client for Elodin database connection.
Standalone implementation without FSW dependencies.
Definition at line 22 of file TCPClient.hpp.
| daq_comms::transport::TCPClient::TCPClient | ( | ) |
Definition at line 16 of file TCPClient.cpp.
References buffer_pos_, BUFFER_SIZE, connected_, socket_fd_, and write_buffer_.
| daq_comms::transport::TCPClient::~TCPClient | ( | ) |
Definition at line 20 of file TCPClient.cpp.
References disconnect().
|
private |
Definition at line 173 of file TCPClient.cpp.
References _write_all(), buffer_pos_, and write_buffer_.
Referenced by flush(), and write_buffered().
|
private |
Definition at line 141 of file TCPClient.cpp.
References connected_, last_error_, and socket_fd_.
Referenced by _flush_buffer(), and write_all().
| bool daq_comms::transport::TCPClient::connect | ( | const std::string & | host, |
| uint16_t | port ) |
Connect to TCP server.
| host | Server hostname or IP address |
| port | Server port |
Definition at line 24 of file TCPClient.cpp.
References buffer_pos_, connect(), connected_, disconnect(), last_error_, port, and socket_fd_.
Referenced by connect(), and smart_calibration_gui.SmartCalibrationGUI::toggle_connection().
| void daq_comms::transport::TCPClient::disconnect | ( | ) |
Disconnect from server.
Definition at line 76 of file TCPClient.cpp.
References connected_, flush(), and socket_fd_.
Referenced by connect(), smart_calibration_gui.SmartCalibrationGUI::toggle_connection(), and ~TCPClient().
| void daq_comms::transport::TCPClient::flush | ( | ) |
Flush buffered data.
Definition at line 128 of file TCPClient.cpp.
References _flush_buffer(), connected_, lock, and write_mutex_.
Referenced by disconnect().
| bool daq_comms::transport::TCPClient::is_connected | ( | ) | const |
| std::string daq_comms::transport::TCPClient::last_error | ( | ) | const |
| ssize_t daq_comms::transport::TCPClient::read | ( | void * | buffer, |
| size_t | max_len ) |
Read data from socket (non-blocking).
| buffer | Buffer to read into |
| max_len | Maximum bytes to read |
Definition at line 180 of file TCPClient.cpp.
References connected_, last_error_, read(), and socket_fd_.
Referenced by read(), and read_exact().
| bool daq_comms::transport::TCPClient::read_exact | ( | void * | buffer, |
| size_t | len ) |
Read exactly len bytes (blocking).
| buffer | Buffer to read into |
| len | Exact number of bytes to read |
Definition at line 206 of file TCPClient.cpp.
References connected_, last_error_, ptr, r, read(), and socket_fd_.
| void daq_comms::transport::TCPClient::set_recv_timeout_ms | ( | int | timeout_ms | ) |
Set socket receive timeout (0 = blocking).
| timeout_ms | Receive timeout in milliseconds |
Definition at line 251 of file TCPClient.cpp.
References socket_fd_.
| bool daq_comms::transport::TCPClient::write_all | ( | const void * | data, |
| size_t | len ) |
Write data directly (for VTable registration).
| data | Data to write |
| len | Length of data |
Definition at line 89 of file TCPClient.cpp.
References _write_all(), connected_, last_error_, lock, and write_mutex_.
| bool daq_comms::transport::TCPClient::write_buffered | ( | const void * | data, |
| size_t | len ) |
Write data with buffering (for data publishing).
| data | Data to write |
| len | Length of data |
Definition at line 99 of file TCPClient.cpp.
References _flush_buffer(), buffer_pos_, BUFFER_SIZE, connected_, last_error_, lock, write_buffer_, and write_mutex_.
|
private |
Definition at line 101 of file TCPClient.hpp.
Referenced by _flush_buffer(), connect(), TCPClient(), and write_buffered().
|
staticconstexprprivate |
Definition at line 99 of file TCPClient.hpp.
Referenced by TCPClient(), and write_buffered().
|
private |
Definition at line 95 of file TCPClient.hpp.
Referenced by _write_all(), connect(), disconnect(), flush(), is_connected(), read(), read_exact(), TCPClient(), write_all(), and write_buffered().
|
private |
Definition at line 96 of file TCPClient.hpp.
Referenced by _write_all(), connect(), last_error(), read(), read_exact(), write_all(), and write_buffered().
|
private |
Definition at line 94 of file TCPClient.hpp.
Referenced by _write_all(), connect(), disconnect(), read(), read_exact(), set_recv_timeout_ms(), and TCPClient().
|
private |
Definition at line 100 of file TCPClient.hpp.
Referenced by _flush_buffer(), TCPClient(), and write_buffered().
|
private |
Definition at line 102 of file TCPClient.hpp.
Referenced by flush(), write_all(), and write_buffered().