Fixed string buffer not being compied

This commit is contained in:
Fredy 2020-06-27 21:12:33 +02:00
parent 66ed68bf7b
commit 060c226801
5 changed files with 9 additions and 3 deletions

View File

@ -46,7 +46,9 @@ bool GWSocket::close()
std::lock_guard<std::recursive_mutex> guard(this->queueMutex);
this->writeQueue.emplace_back(OUT_DISCONNECT);
}
this->checkWriting();
if (expected == STATE_CONNECTED) {
this->checkWriting();
}
return true;
}

View File

@ -99,6 +99,7 @@ protected:
void checkWriting();
void hostResolvedStep(const boost::system::error_code &ec, tcp::resolver::iterator it);
bool writing = { false };
std::string messageToWrite = "";
void doClose();
bool setDisconnectingCAS();
std::unordered_map<std::string, std::string> cookies;

View File

@ -102,7 +102,8 @@ void SSLWebSocket::asyncRead()
void SSLWebSocket::asyncWrite(std::string message)
{
this->getWS()->async_write(boost::asio::buffer(message), boost::bind(&SSLWebSocket::onWrite, this, boost::placeholders::_1, boost::placeholders::_2));
this->messageToWrite = message;
this->getWS()->async_write(boost::asio::buffer(this->messageToWrite), boost::bind(&SSLWebSocket::onWrite, this, boost::placeholders::_1, boost::placeholders::_2));
}
void SSLWebSocket::closeSocket()

View File

@ -23,7 +23,8 @@ void WebSocket::asyncRead()
void WebSocket::asyncWrite(std::string message)
{
this->getWS()->async_write(boost::asio::buffer(message), boost::bind(&WebSocket::onWrite, this, boost::placeholders::_1, boost::placeholders::_2));
this->messageToWrite = message;
this->getWS()->async_write(boost::asio::buffer(this->messageToWrite), boost::bind(&WebSocket::onWrite, this, boost::placeholders::_1, boost::placeholders::_2));
}
void WebSocket::closeSocket()

View File

@ -21,6 +21,7 @@ protected:
void asyncWrite(std::string message);
void asyncCloseSocket();
void closeSocket();
std::string messageToWrite = "";
std::atomic<websocket::stream<tcp::socket>*> ws{ nullptr };
//This is not an atomic function, it only ensures visibility.
//Callers have to make sure that atomicity is not required/ensured otherwise