[Libreoffice-commits] online.git: loolwsd/LOOLSession.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Wed Sep 28 03:27:38 UTC 2016


 loolwsd/LOOLSession.cpp |   32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

New commits:
commit dfeae15038e29197abc26caed1fc237c3b8dabab
Author: Ashod Nakashian <ashod.nakashian at 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 <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at 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());


More information about the Libreoffice-commits mailing list