2023-11-22 19:59:34 -08:00
|
|
|
#pragma once
|
|
|
|
|
2025-01-23 12:46:52 -08:00
|
|
|
#include "ircmsg.hpp"
|
|
|
|
#include "irc_command.hpp"
|
2023-11-22 19:59:34 -08:00
|
|
|
|
|
|
|
#include <boost/asio.hpp>
|
2025-01-22 23:49:48 -08:00
|
|
|
#include <boost/signals2.hpp>
|
2023-11-22 19:59:34 -08:00
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2023-11-25 09:22:55 -08:00
|
|
|
|
2023-11-22 19:59:34 -08:00
|
|
|
class Connection : public std::enable_shared_from_this<Connection>
|
|
|
|
{
|
2023-11-25 20:09:20 -08:00
|
|
|
private:
|
2023-11-22 19:59:34 -08:00
|
|
|
boost::asio::ip::tcp::socket stream_;
|
|
|
|
boost::asio::steady_timer write_timer_;
|
|
|
|
std::list<std::string> write_strings_;
|
|
|
|
|
|
|
|
auto writer() -> void;
|
2024-03-03 12:27:36 -08:00
|
|
|
auto writer_immediate() -> void;
|
2025-01-23 12:46:52 -08:00
|
|
|
auto dispatch_line(char * line) -> void;
|
2023-11-22 19:59:34 -08:00
|
|
|
|
|
|
|
public:
|
2023-11-25 09:22:55 -08:00
|
|
|
Connection(boost::asio::io_context & io);
|
2023-11-25 20:09:20 -08:00
|
|
|
|
2025-01-22 23:49:48 -08:00
|
|
|
boost::signals2::signal<void()> sig_connect;
|
|
|
|
boost::signals2::signal<void()> sig_disconnect;
|
|
|
|
boost::signals2::signal<void(IrcCommand, const IrcMsg &)> sig_ircmsg;
|
2023-11-25 20:09:20 -08:00
|
|
|
|
|
|
|
auto get_executor() -> boost::asio::any_io_executor {
|
|
|
|
return stream_.get_executor();
|
|
|
|
}
|
2023-11-22 19:59:34 -08:00
|
|
|
|
2023-11-25 09:22:55 -08:00
|
|
|
/// Write bytes into the socket. Messages should be properly newline terminated.
|
2023-11-26 19:59:12 -08:00
|
|
|
auto write_line(std::string message) -> void;
|
2023-11-22 19:59:34 -08:00
|
|
|
|
|
|
|
auto connect(
|
|
|
|
boost::asio::io_context & io,
|
2023-11-25 09:22:55 -08:00
|
|
|
std::string host,
|
|
|
|
std::string port
|
2023-11-22 19:59:34 -08:00
|
|
|
) -> boost::asio::awaitable<void>;
|
2023-11-25 09:22:55 -08:00
|
|
|
|
|
|
|
auto close() -> void;
|
2023-11-22 19:59:34 -08:00
|
|
|
};
|
|
|
|
|