Skip to content

Commit

Permalink
Fix Discord Webhooks logging sink not working
Browse files Browse the repository at this point in the history
Seems like a recent update broke them. Before we were not closing the SSL
stream (we were just closing the tcp socket outright), now we read the
remaining data, close the SSL stream and finally the socket.
  • Loading branch information
DyXel committed Dec 14, 2023
1 parent 163d918 commit ef35d86
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/Multirole/Service/LogHandler/DiscordWebhookSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class DiscordWebhookSink::Connection final : public std::enable_shared_from_this
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> socket;
const Endpoints& endpoints;
const std::string payload;
std::string read_buffer;

void DoHandshake() noexcept
{
Expand All @@ -62,7 +63,32 @@ class DiscordWebhookSink::Connection final : public std::enable_shared_from_this
{
auto self(shared_from_this());
boost::asio::async_write(socket, boost::asio::buffer(payload),
[self](boost::system::error_code /*unused*/, std::size_t /*unused*/){});
[this, self](boost::system::error_code ec, std::size_t /*unused*/)
{
if(ec)
return;
DoRead();
});
}

void DoRead() noexcept
{
auto self(shared_from_this());
boost::asio::async_read_until(socket, boost::asio::dynamic_buffer(read_buffer), "\r\n\r\n",
[this, self](boost::system::error_code ec, std::size_t /*unused*/)
{
if(ec)
return;
DoShutdown();
});
}

void DoShutdown() noexcept
{
auto self(shared_from_this());
socket.async_shutdown([this, self](boost::system::error_code ec){
socket.lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
});
}
};

Expand Down

0 comments on commit ef35d86

Please sign in to comment.