STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
daq_comms::transport::TCPClient Class Reference

Simple TCP client for Elodin database connection. More...

#include <TCPClient.hpp>

Collaboration diagram for daq_comms::transport::TCPClient:
[legend]

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

Detailed Description

Simple TCP client for Elodin database connection.

Standalone implementation without FSW dependencies.

Definition at line 22 of file TCPClient.hpp.

Constructor & Destructor Documentation

◆ TCPClient()

daq_comms::transport::TCPClient::TCPClient ( )

Definition at line 16 of file TCPClient.cpp.

References buffer_pos_, BUFFER_SIZE, connected_, socket_fd_, and write_buffer_.

◆ ~TCPClient()

daq_comms::transport::TCPClient::~TCPClient ( )

Definition at line 20 of file TCPClient.cpp.

References disconnect().

Member Function Documentation

◆ _flush_buffer()

void daq_comms::transport::TCPClient::_flush_buffer ( )
private

Definition at line 173 of file TCPClient.cpp.

References _write_all(), buffer_pos_, and write_buffer_.

Referenced by flush(), and write_buffered().

◆ _write_all()

bool daq_comms::transport::TCPClient::_write_all ( const void * data,
size_t len )
private

Definition at line 141 of file TCPClient.cpp.

References connected_, last_error_, and socket_fd_.

Referenced by _flush_buffer(), and write_all().

◆ connect()

bool daq_comms::transport::TCPClient::connect ( const std::string & host,
uint16_t port )

Connect to TCP server.

Parameters
hostServer hostname or IP address
portServer port
Returns
true if connection successful, false otherwise

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().

◆ disconnect()

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().

◆ flush()

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().

◆ is_connected()

bool daq_comms::transport::TCPClient::is_connected ( ) const

Check if connected.

Definition at line 85 of file TCPClient.cpp.

References connected_.

◆ last_error()

std::string daq_comms::transport::TCPClient::last_error ( ) const

Get last error message.

Definition at line 137 of file TCPClient.cpp.

References last_error_.

◆ read()

ssize_t daq_comms::transport::TCPClient::read ( void * buffer,
size_t max_len )

Read data from socket (non-blocking).

Parameters
bufferBuffer to read into
max_lenMaximum bytes to read
Returns
Number of bytes read, 0 if no data available, -1 on error

Definition at line 180 of file TCPClient.cpp.

References connected_, last_error_, read(), and socket_fd_.

Referenced by read(), and read_exact().

◆ read_exact()

bool daq_comms::transport::TCPClient::read_exact ( void * buffer,
size_t len )

Read exactly len bytes (blocking).

Parameters
bufferBuffer to read into
lenExact number of bytes to read
Returns
true if successful, false on error

Definition at line 206 of file TCPClient.cpp.

References connected_, last_error_, ptr, r, read(), and socket_fd_.

◆ set_recv_timeout_ms()

void daq_comms::transport::TCPClient::set_recv_timeout_ms ( int timeout_ms)

Set socket receive timeout (0 = blocking).

Parameters
timeout_msReceive timeout in milliseconds

Definition at line 251 of file TCPClient.cpp.

References socket_fd_.

◆ write_all()

bool daq_comms::transport::TCPClient::write_all ( const void * data,
size_t len )

Write data directly (for VTable registration).

Parameters
dataData to write
lenLength of data
Returns
true if successful

Definition at line 89 of file TCPClient.cpp.

References _write_all(), connected_, last_error_, lock, and write_mutex_.

◆ write_buffered()

bool daq_comms::transport::TCPClient::write_buffered ( const void * data,
size_t len )

Write data with buffering (for data publishing).

Parameters
dataData to write
lenLength of data
Returns
true if successful

Definition at line 99 of file TCPClient.cpp.

References _flush_buffer(), buffer_pos_, BUFFER_SIZE, connected_, last_error_, lock, write_buffer_, and write_mutex_.

Member Data Documentation

◆ buffer_pos_

size_t daq_comms::transport::TCPClient::buffer_pos_
private

Definition at line 101 of file TCPClient.hpp.

Referenced by _flush_buffer(), connect(), TCPClient(), and write_buffered().

◆ BUFFER_SIZE

size_t daq_comms::transport::TCPClient::BUFFER_SIZE = 8192
staticconstexprprivate

Definition at line 99 of file TCPClient.hpp.

Referenced by TCPClient(), and write_buffered().

◆ connected_

bool daq_comms::transport::TCPClient::connected_
private

◆ last_error_

std::string daq_comms::transport::TCPClient::last_error_
private

Definition at line 96 of file TCPClient.hpp.

Referenced by _write_all(), connect(), last_error(), read(), read_exact(), write_all(), and write_buffered().

◆ socket_fd_

int daq_comms::transport::TCPClient::socket_fd_
private

◆ write_buffer_

std::vector<uint8_t> daq_comms::transport::TCPClient::write_buffer_
private

Definition at line 100 of file TCPClient.hpp.

Referenced by _flush_buffer(), TCPClient(), and write_buffered().

◆ write_mutex_

std::mutex daq_comms::transport::TCPClient::write_mutex_
private

Definition at line 102 of file TCPClient.hpp.

Referenced by flush(), write_all(), and write_buffered().


The documentation for this class was generated from the following files:
  • daq-server/diablo_server/transport/include/transport/TCPClient.hpp
  • daq-server/diablo_server/transport/src/transport/TCPClient.cpp