143 std::shared_ptr<Socket> m_socket;
144 uint64_t m_connection_id;
145 size_t m_read_offset = 0;
146 std::vector<uint8_t> m_read_buffer;
147 std::vector<uint8_t> m_write_buffer;
149 mutable TracyLockableN (std::mutex, m_mutex,
"Connection Mutex");
150 mutable TracyLockableN (std::mutex, m_write_mutex,
"Write Mutex");
151 mutable TracyLockableN (std::mutex, m_read_mutex,
"Read Mutex");
a bufferised and thread safe RAII wrapper for a socket representing a connection.
Definition: Connection.hpp:29
Connection & operator=(const Connection &other)=delete
const uint8_t * getReadBufferPtr() const
Get a pointer to the read buffer, offset by the internal read offset.
Definition: Connection.cpp:35
~Connection()
Definition: Connection.cpp:8
void queueMessage(const std::vector< uint8_t > &msg)
add the message to the write buffer without sending it.
Definition: Connection.cpp:128
bool dataToSend() const
Check if there is data in the write buffer.
Definition: Connection.cpp:150
LockableBase(std::mutex) &ReadLock() const
get a ref to the read mutex
Connection(const Connection &other)=delete
size_t getReadBufferSize() const
Get the number of bytes that can be read from the read buffer.
Definition: Connection.cpp:41
const uint64_t & getConnectionId() const
Definition: Connection.cpp:139
void reduceReadBuffer(size_t size)
Notify the connection that size bytes have been read from the read buffer.
Definition: Connection.cpp:51
ssize_t recv()
will call recv on the socket on a non blocking way. Filling the read buffer.
Definition: Connection.cpp:67
const Socket & getSocket() const
Definition: Connection.cpp:134
const std::vector< uint8_t > & getWriteBufferRef() const
Get a ref to the write buffer.
Definition: Connection.cpp:46
LockableBase(std::mutex) &WriteLock() const
get a ref to the write mutex
void clearReadBuffer()
Clear the read buffer and reset the read offset.
Definition: Connection.cpp:57
static constexpr size_t READ_BUFFER_SIZE_MAX
a constant representing the maximum size of the read buffer. when reading the connection will stop wh...
Definition: Connection.hpp:35
void queueAndSendMessage(const std::vector< uint8_t > &msg)
add the message to the write buffer and try to send it.
Definition: Connection.cpp:121
ssize_t sendQueue()
will send as much data as possible from the write buffer.
Definition: Connection.cpp:100
void setConnectionId(const uint64_t &connection_id)
Definition: Connection.cpp:145
a RAII wrapper for a socket.
Definition: Socket.hpp:17