#pragma once #include "linebuffer.hpp" #include "settings.hpp" #include "thread.hpp" #include #include #include #include #include #include #include #include #include #include #include #include struct ConnectEvent : Event { }; struct DisconnectEvent : Event { }; struct LineEvent : Event { explicit LineEvent(char * line) : line{line} {} char * line; }; class Connection : public std::enable_shared_from_this { boost::asio::ip::tcp::socket stream_; boost::asio::steady_timer write_timer_; std::list write_strings_; Dispatcher dispatcher_; auto writer() -> void; auto writer_() -> void; public: Connection(boost::asio::io_context & io); auto add_thread(std::shared_ptr thread) -> void; auto add_event(std::shared_ptr event) -> void; template auto make_event(Args&& ... args) { add_event(std::make_shared(std::forward(args)...)); } /// Write bytes into the socket. Messages should be properly newline terminated. auto write_raw(std::string message) -> void; auto connect( boost::asio::io_context & io, std::string host, std::string port ) -> boost::asio::awaitable; auto close() -> void; };