23 #include <sys/socket.h> 24 #include <sys/types.h> 94 bool read(uint8_t* buf,
const size_t buf_len,
size_t&
read);
105 bool write(
const uint8_t* buf,
const size_t buf_len,
size_t& written);
108 virtual bool open(
int socket_fd,
struct sockaddr* address,
size_t address_len)
110 return ::connect(socket_fd, address, address_len) == 0;
119 template <
typename T>
126 template <
typename T>
132 uint8_t* buf_pos = buf;
133 size_t remainder =
sizeof(
typename T::HeaderType::_package_size_type);
141 remainder = T::HeaderType::getPackageLength(buf);
142 if (remainder >= (buf_len -
sizeof(
typename T::HeaderType::_package_size_type)))
144 URCL_LOG_ERROR(
"Packet size %zd is larger than buffer %zu, discarding.", remainder, buf_len);
155 return remainder == 0;
#define URCL_LOG_ERROR(...)
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 write(const uint8_t *buf, const size_t buf_len, size_t &written)
Writes to the socket.
Connection to socket got closed.
The stream is an abstraction of the TCPSocket that offers reading a full UR data package out of the s...
bool closed()
Returns whether the underlying socket is currently closed.
bool write(const uint8_t *buf, const size_t buf_len, size_t &written)
Writes directly to the underlying socket (with a mutex guard)
virtual bool open(int socket_fd, struct sockaddr *address, size_t address_len)
bool connect()
Connects to the configured socket.
bool read(char *character)
Reads one byte from the socket.
void disconnect()
Disconnects from the configured socket.
SocketState getState()
Getter for the state of the socket.
#define URCL_LOG_DEBUG(...)
bool setup(std::string &host, int port)
void close()
Closes the connection to the socket.
Class for TCP socket abstraction.
URStream(const std::string &host, int port)
Creates a new URStream object. Note, that this does not immediately open the socket, that has to be done separately by calling the connect() function.
virtual void setOptions(int socket_fd)
int getSocketFD()
Getter for the file descriptor of the socket.