loolwsd/LOOLSession.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
New commits: commit dfeae15038e29197abc26caed1fc237c3b8dabab Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Tue Sep 27 22:04:13 2016 -0400 loolwsd: accessing the WS should be thread-safe Change-Id: I490e9b720024b93099ca63d66e840db2c1931720 Reviewed-on: https://gerrit.libreoffice.org/29335 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp index 6b37618..1af3ddb 100644 --- a/loolwsd/LOOLSession.cpp +++ b/loolwsd/LOOLSession.cpp @@ -66,7 +66,9 @@ LOOLSession::LOOLSession(const std::string& id, const Kind kind, { // Only a post request can have a null ws. if (_kind != Kind::ToClient) - assert(_ws); + { + assert(_ws && "Expected valid web-socket but got null."); + } } LOOLSession::~LOOLSession() @@ -75,18 +77,18 @@ LOOLSession::~LOOLSession() bool LOOLSession::sendTextFrame(const char* buffer, const int length) { - if (!_ws || _ws->poll(Poco::Timespan(0), Socket::SelectMode::SELECT_ERROR)) - { - Log::error(getName() + ": Bad socket while sending [" + getAbbreviatedMessage(buffer, length) + "]."); - return false; - } - Log::trace(getName() + ": Send: " + getAbbreviatedMessage(buffer, length)); try { std::unique_lock<std::mutex> lock(_mutex); - if ( length > SMALL_MESSAGE_SIZE ) + if (!_ws || _ws->poll(Poco::Timespan(0), Socket::SelectMode::SELECT_ERROR)) + { + Log::error(getName() + ": Bad socket while sending [" + getAbbreviatedMessage(buffer, length) + "]."); + return false; + } + + if (length > SMALL_MESSAGE_SIZE) { const std::string nextmessage = "nextmessage: size=" + std::to_string(length); _ws->sendFrame(nextmessage.data(), nextmessage.size()); @@ -107,18 +109,18 @@ bool LOOLSession::sendTextFrame(const char* buffer, const int length) bool LOOLSession::sendBinaryFrame(const char *buffer, int length) { - if (!_ws || _ws->poll(Poco::Timespan(0), Socket::SelectMode::SELECT_ERROR)) - { - Log::error(getName() + ": Bad socket while sending binary frame of " + std::to_string(length) + " bytes."); - return false; - } - Log::trace(getName() + ": Send: " + std::to_string(length) + " bytes"); try { std::unique_lock<std::mutex> lock(_mutex); - if ( length > SMALL_MESSAGE_SIZE ) + if (!_ws || _ws->poll(Poco::Timespan(0), Socket::SelectMode::SELECT_ERROR)) + { + Log::error(getName() + ": Bad socket while sending binary frame of " + std::to_string(length) + " bytes."); + return false; + } + + if (length > SMALL_MESSAGE_SIZE) { const std::string nextmessage = "nextmessage: size=" + std::to_string(length); _ws->sendFrame(nextmessage.data(), nextmessage.size()); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits