[Libreoffice-commits] online.git: wsd/LOOLWSD.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Wed Jan 4 04:32:51 UTC 2017


 wsd/LOOLWSD.cpp |   24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

New commits:
commit 59dfe338cbb3cbacf04732523fed9fca42405a76
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Tue Jan 3 17:09:13 2017 -0500

    wsd: safely count the number of current connections
    
    Change-Id: I90b2436f804acd9b0295ba2ce944e8b68a59db91
    Reviewed-on: https://gerrit.libreoffice.org/32715
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 141db3c..9895a76 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1203,8 +1203,8 @@ public:
                 request, response))
             return;
 
-#if MAX_CONNECTIONS > 0
-        if (++LOOLWSD::NumConnections > MAX_CONNECTIONS)
+        const auto connectionNum = ++LOOLWSD::NumConnections;
+        if (connectionNum > MAX_CONNECTIONS)
         {
             --LOOLWSD::NumConnections;
             LOG_ERR("Limit on maximum number of connections of " << MAX_CONNECTIONS << " reached.");
@@ -1213,18 +1213,24 @@ public:
             shutdownLimitReached(ws);
             return;
         }
-#endif
 
-        handleClientRequest(request, response);
+        try
+        {
+            const auto id = LOOLWSD::GenSessionId();
+            LOG_TRC("Accepted connection #" << connectionNum << " of " <<
+                    MAX_CONNECTIONS << " as session [" << id << "].");
+            handleClientRequest(request, response, id);
+        }
+        catch (const std::exception& exc)
+        {
+            // Nothing to do.
+        }
 
-#if MAX_CONNECTIONS > 0
         --LOOLWSD::NumConnections;
-#endif
     }
 
-    static void handleClientRequest(HTTPServerRequest& request, HTTPServerResponse& response)
+    static void handleClientRequest(HTTPServerRequest& request, HTTPServerResponse& response, const std::string& id)
     {
-        const auto id = LOOLWSD::GenSessionId();
         Util::setThreadName("client_ws_" + id);
 
         LOG_DBG("Thread started.");
@@ -2336,7 +2342,7 @@ void UnitWSD::testHandleRequest(TestRequest type, UnitHTTPServerRequest& request
     switch (type)
     {
     case TestRequest::Client:
-        ClientRequestHandler::handleClientRequest(request, response);
+        ClientRequestHandler::handleClientRequest(request, response, LOOLWSD::GenSessionId());
         break;
     case TestRequest::Prisoner:
         PrisonerRequestHandler::handlePrisonerRequest(request, response);


More information about the Libreoffice-commits mailing list