Go to the documentation of this file.
63 bool connect(
const size_t max_num_tries = 0,
64 const std::chrono::milliseconds reconnection_time = std::chrono::seconds(10))
97 bool read(uint8_t* buf,
const size_t buf_len,
size_t&
read);
108 bool write(
const uint8_t* buf,
const size_t buf_len,
size_t& written);
126 template <
typename T>
129 std::lock_guard<std::mutex> lock(write_mutex_);
133 template <
typename T>
136 std::lock_guard<std::mutex> lock(read_mutex_);
139 uint8_t* buf_pos = buf;
140 size_t remainder =
sizeof(
typename T::HeaderType::_package_size_type);
147 remainder = T::HeaderType::getPackageLength(buf);
148 if (remainder >= (buf_len -
sizeof(
typename T::HeaderType::_package_size_type)))
150 URCL_LOG_ERROR(
"Packet size %zd is larger than buffer %zu, discarding.", remainder, buf_len);
161 return remainder == 0;
Class for TCP socket abstraction.
The stream is an abstraction of the TCPSocket that offers reading a full UR data package out of the s...
bool connect(const size_t max_num_tries=0, const std::chrono::milliseconds reconnection_time=std::chrono::seconds(10))
Connects to the configured socket.
void disconnect()
Disconnects from the configured socket.
bool write(const uint8_t *buf, const size_t buf_len, size_t &written)
Writes directly to the underlying socket (with a mutex guard)
std::string getHost()
Get the host IP.
URStream(const std::string &host, int port)
Creates a new URStream object. Note, that this does not immediately open the socket,...
#define URCL_LOG_ERROR(...)
@ Closed
Connection to socket got closed.
#define URCL_LOG_DEBUG(...)
bool read(uint8_t *buf, const size_t buf_len, size_t &read)
Reads a full UR package out of a socket. For this, it looks into the package and reads the byte lengt...
bool setup(const std::string &host, const int port, const size_t max_num_tries=0, const std::chrono::milliseconds reconnection_time=DEFAULT_RECONNECTION_TIME)
bool write(const uint8_t *buf, const size_t buf_len, size_t &written)
Writes to the socket.
void close()
Closes the connection to the socket.
bool read(char *character)
Reads one byte from the socket.
bool closed()
Returns whether the underlying socket is currently closed.
SocketState getState()
Getter for the state of the socket.
ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Mon May 26 2025 02:35:58