make disconnect signal reliable
This commit is contained in:
parent
ebe884e9d5
commit
bb7f09f2e9
@ -397,14 +397,18 @@ auto Connection::connect(
|
|||||||
const auto self = shared_from_this();
|
const auto self = shared_from_this();
|
||||||
const size_t irc_buffer_size = 32'768;
|
const size_t irc_buffer_size = 32'768;
|
||||||
|
|
||||||
auto& socket = stream_.reset();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
|
// Name resolution
|
||||||
auto resolver = boost::asio::ip::tcp::resolver{io};
|
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);
|
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);
|
const auto endpoint = co_await boost::asio::async_connect(socket, endpoints, boost::asio::use_awaitable);
|
||||||
BOOST_LOG_TRIVIAL(debug) << "CONNECTED: " << endpoint;
|
BOOST_LOG_TRIVIAL(debug) << "CONNECTED: " << endpoint;
|
||||||
|
|
||||||
|
// Set socket options
|
||||||
socket.set_option(boost::asio::ip::tcp::no_delay(true));
|
socket.set_option(boost::asio::ip::tcp::no_delay(true));
|
||||||
set_buffer_size(socket, irc_buffer_size);
|
set_buffer_size(socket, irc_buffer_size);
|
||||||
set_cloexec(socket.native_handle());
|
set_cloexec(socket.native_handle());
|
||||||
@ -455,7 +459,4 @@ auto Connection::connect(
|
|||||||
|
|
||||||
watchdog_timer_.cancel();
|
watchdog_timer_.cancel();
|
||||||
stream_.close();
|
stream_.close();
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(debug) << "DISCONNECTED";
|
|
||||||
sig_disconnect();
|
|
||||||
}
|
}
|
||||||
|
4
main.cpp
4
main.cpp
@ -43,12 +43,16 @@ auto start(boost::asio::io_context &io, const Settings &settings) -> void
|
|||||||
{
|
{
|
||||||
if (e)
|
if (e)
|
||||||
std::rethrow_exception(e);
|
std::rethrow_exception(e);
|
||||||
|
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "DISCONNECTED";
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
BOOST_LOG_TRIVIAL(debug) << "TERMINATED: " << e.what();
|
BOOST_LOG_TRIVIAL(debug) << "TERMINATED: " << e.what();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connection->sig_disconnect();
|
||||||
|
|
||||||
auto timer = std::make_shared<boost::asio::steady_timer>(io);
|
auto timer = std::make_shared<boost::asio::steady_timer>(io);
|
||||||
|
|
||||||
timer->expires_after(5s);
|
timer->expires_after(5s);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user