diff options
| -rw-r--r-- | src/control_connection.cpp | 15 | ||||
| -rw-r--r-- | src/control_connection.hpp | 5 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/control_connection.cpp b/src/control_connection.cpp index 88a136e..094a058 100644 --- a/src/control_connection.cpp +++ b/src/control_connection.cpp @@ -34,6 +34,21 @@ void control_connection::start() } } +void control_connection::send(std::string message) +{ + m_output << message; + boost::asio::async_write(m_socket, m_out, boost::asio::transfer_exactly(message.size()), [that = shared_from_this(), this](auto const &error, auto const length) { + if (error) + { + // TODO: Handle error + } + else + { + m_out.consume(length); + } + }); +} + void control_connection::close() { if (auto error = boost::system::error_code{}; m_socket.cancel(error)) diff --git a/src/control_connection.hpp b/src/control_connection.hpp index e868f99..50eee82 100644 --- a/src/control_connection.hpp +++ b/src/control_connection.hpp @@ -5,7 +5,9 @@ #include <boost/asio.hpp> +#include <istream> #include <memory> +#include <ostream> #include <set> #include <string> @@ -56,6 +58,8 @@ struct control_connection : keyed<control_connection>, std::enable_shared_from_t */ void close(); + void send(std::string message); + private: friend pointer make_control_connection(protocol::socket &&socket); @@ -65,6 +69,7 @@ struct control_connection : keyed<control_connection>, std::enable_shared_from_t boost::asio::streambuf m_in{}; boost::asio::streambuf m_out{}; std::istream m_input{&m_in}; + std::ostream m_output{&m_out}; std::set<std::shared_ptr<listener>> m_listeners{}; bool m_running{}; }; |
