Fixed disconnect

This commit is contained in:
BenDroid 2018-04-14 23:47:45 +02:00
parent 10163ffe94
commit 09548d6b3b
2 changed files with 10 additions and 6 deletions

View file

@ -36,7 +36,7 @@ public:
~BoostConnection() ~BoostConnection()
{ {
disconnect();
} }
void connect(const std::string& server, uint16_t port) override void connect(const std::string& server, uint16_t port) override
@ -51,6 +51,8 @@ public:
boost::bind(&BoostConnection::handleConnect, this->shared_from_this(), boost::bind(&BoostConnection::handleConnect, this->shared_from_this(),
boost::asio::placeholders::error)); boost::asio::placeholders::error));
std::thread([this]() { ioService_.run(); }).detach(); std::thread([this]() { ioService_.run(); }).detach();
} }
@ -67,11 +69,8 @@ public:
void disconnect() override void disconnect() override
{ {
if (isConnected()) {
LOG_DEBUG("[%s:%d] Disconnecting", getConnectedIp().c_str(), getConnectedPort()); LOG_DEBUG("[%s:%d] Disconnecting", getConnectedIp().c_str(), getConnectedPort());
socket_.get().lowest_layer().close(); socket_.get().lowest_layer().close();
}
ioService_.stop(); ioService_.stop();
} }

View file

@ -322,6 +322,11 @@ void Client::close()
{ {
LOG_DEBUG("close"); LOG_DEBUG("close");
if (m_connection && m_connection) {
LOG_DEBUG("disconnecting");
m_connection->disconnect();
}
m_connection.reset(); m_connection.reset();
} }