The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
mha_tcp::buffered_socket_t Class Reference

An asio TCP socket with an associated streambuf buffer for receiving lines of text, as well as string buffers for sending responses. More...

Inherits asio::ip::tcp::socket, and std::enable_shared_from_this< buffered_socket_t >.

Public Member Functions

asio::streambuf & get_buffer ()
 Access to associated streambuf. More...
 
void queue_write (const std::string &message)
 Send the given message through this connection to the client asynchronously. More...
 

Private Attributes

asio::streambuf streambuf
 associated streambuf object to collect received pieces into lines More...
 
std::string current_message
 The message that is currently sent back to the client. More...
 
std::string next_message
 A buffer for the next message(s) that must be sent back to the client after the sending of current_message has completed. More...
 

Detailed Description

An asio TCP socket with an associated streambuf buffer for receiving lines of text, as well as string buffers for sending responses.

Used for communicating with MHA TCP clients. The life time of the connection objects is managed with shared pointers registered together with callbacks in the asio event loop. This is a common idiom in asio. To support this, we inherit from enable_shared_from_this which is also common in code that uses asio.

Member Function Documentation

◆ get_buffer()

asio::streambuf& mha_tcp::buffered_socket_t::get_buffer ( )
inline

Access to associated streambuf.

Needed to invoke async_read.

Returns
associated streambuf object by reference

◆ queue_write()

void mha_tcp::buffered_socket_t::queue_write ( const std::string &  message)

Send the given message through this connection to the client asynchronously.

Parameters
messageThe text to send. Method copies the message before returning.

Member Data Documentation

◆ streambuf

asio::streambuf mha_tcp::buffered_socket_t::streambuf
private

associated streambuf object to collect received pieces into lines

◆ current_message

std::string mha_tcp::buffered_socket_t::current_message
private

The message that is currently sent back to the client.

◆ next_message

std::string mha_tcp::buffered_socket_t::next_message
private

A buffer for the next message(s) that must be sent back to the client after the sending of current_message has completed.


The documentation for this class was generated from the following files: