mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-10 23:01:45 +02:00
Fix crash during client disconnect
This commit is contained in:
parent
1f1c00981b
commit
a9b042f78e
6 changed files with 19 additions and 47 deletions
|
@ -41,9 +41,9 @@ ControlSessionTcp::~ControlSessionTcp()
|
|||
void ControlSessionTcp::do_read()
|
||||
{
|
||||
const std::string delimiter = "\n";
|
||||
auto self(shared_from_this());
|
||||
boost::asio::async_read_until(
|
||||
socket_, streambuf_, delimiter, boost::asio::bind_executor(strand_, [this, self, delimiter](const std::error_code& ec, std::size_t bytes_transferred) {
|
||||
socket_, streambuf_, delimiter,
|
||||
boost::asio::bind_executor(strand_, [ this, self = shared_from_this(), delimiter ](const std::error_code& ec, std::size_t bytes_transferred) {
|
||||
if (ec)
|
||||
{
|
||||
LOG(ERROR) << "Error while reading from control socket: " << ec.message() << "\n";
|
||||
|
@ -92,7 +92,7 @@ void ControlSessionTcp::stop()
|
|||
|
||||
void ControlSessionTcp::sendAsync(const std::string& message)
|
||||
{
|
||||
strand_.post([this, message]() {
|
||||
strand_.post([ this, self = shared_from_this(), message ]() {
|
||||
messages_.emplace_back(message);
|
||||
if (messages_.size() > 1)
|
||||
{
|
||||
|
@ -105,10 +105,9 @@ void ControlSessionTcp::sendAsync(const std::string& message)
|
|||
|
||||
void ControlSessionTcp::send_next()
|
||||
{
|
||||
auto self(shared_from_this());
|
||||
auto message = messages_.front();
|
||||
boost::asio::async_write(socket_, boost::asio::buffer(message + "\r\n"),
|
||||
boost::asio::bind_executor(strand_, [this, self](std::error_code ec, std::size_t length) {
|
||||
boost::asio::bind_executor(strand_, [ this, self = shared_from_this() ](std::error_code ec, std::size_t length) {
|
||||
messages_.pop_front();
|
||||
if (ec)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue