diff --git a/connection.cpp b/connection.cpp index f5b16bd..1baf876 100644 --- a/connection.cpp +++ b/connection.cpp @@ -397,14 +397,18 @@ auto Connection::connect( const auto self = shared_from_this(); const size_t irc_buffer_size = 32'768; - auto& socket = stream_.reset(); { + // Name resolution auto resolver = boost::asio::ip::tcp::resolver{io}; const auto endpoints = co_await resolver.async_resolve(settings.host, std::to_string(settings.port), boost::asio::use_awaitable); + + // Connect to the IRC server + auto& socket = stream_.reset(); const auto endpoint = co_await boost::asio::async_connect(socket, endpoints, boost::asio::use_awaitable); BOOST_LOG_TRIVIAL(debug) << "CONNECTED: " << endpoint; + // Set socket options socket.set_option(boost::asio::ip::tcp::no_delay(true)); set_buffer_size(socket, irc_buffer_size); set_cloexec(socket.native_handle()); @@ -455,7 +459,4 @@ auto Connection::connect( watchdog_timer_.cancel(); stream_.close(); - - BOOST_LOG_TRIVIAL(debug) << "DISCONNECTED"; - sig_disconnect(); } diff --git a/main.cpp b/main.cpp index 09d4e96..874de48 100644 --- a/main.cpp +++ b/main.cpp @@ -43,12 +43,16 @@ auto start(boost::asio::io_context &io, const Settings &settings) -> void { if (e) std::rethrow_exception(e); + + BOOST_LOG_TRIVIAL(debug) << "DISCONNECTED"; } catch (const std::exception &e) { BOOST_LOG_TRIVIAL(debug) << "TERMINATED: " << e.what(); } + connection->sig_disconnect(); + auto timer = std::make_shared(io); timer->expires_after(5s);