[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp
Henry Castro
hcastro at collabora.com
Thu Apr 14 15:39:48 UTC 2016
loolwsd/LOOLWSD.cpp | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
New commits:
commit d11bd69c267bbda7ce3d53f750281902e978b2d9
Author: Henry Castro <hcastro at collabora.com>
Date: Thu Apr 14 11:22:19 2016 -0400
loolwsd: wait prison session until the peer is assigned
Some messages are not forwarded to the client session, this is caused
by the time the client session is assigned, the prison session,
it is already forwarding to not assigned peer session.
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ac16540..38d5935 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -31,6 +31,7 @@
#include <map>
#include <mutex>
#include <sstream>
+#include <thread>
#include <Poco/DOM/AutoPtr.h>
#include <Poco/DOM/DOMParser.h>
@@ -262,7 +263,7 @@ private:
std::unique_lock<std::mutex> lock(AvailableChildSessionMutex);
Log::debug() << "Waiting for client session [" << clientSession->getId() << "] to connect." << Log::end;
- while (retries-- && !isFound)
+ while (!TerminationFlag && retries-- && !isFound)
{
AvailableChildSessionCV.wait_for(
lock,
@@ -737,6 +738,24 @@ class PrisonerRequestHandler: public HTTPRequestHandler
{
public:
+ static bool waitBridgeCompleted(const std::shared_ptr<MasterProcessSession>& prisonSession)
+ {
+ // time to live, if the kit process cannot connect to a client session.
+ int ttl = 180;
+ bool isFound = true;
+ // Wait until the prison has connected with a client socket.
+ Log::debug() << "Waiting for prison session [" << prisonSession->getId() << "] to connect." << Log::end;
+ while (!TerminationFlag &&
+ (isFound = AvailableChildSessions.find(prisonSession->getId()) != AvailableChildSessions.end()) &&
+ ttl--)
+ {
+ std::this_thread::sleep_for(std::chrono::milliseconds(POLL_TIMEOUT_MS));
+ Log::debug() << "Sleeping prison session [" << prisonSession->getId() << "] to connect." << Log::end;
+ }
+
+ return isFound;
+ }
+
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) override
{
if (UnitWSD::get().filterHandleRequest(
@@ -872,6 +891,15 @@ public:
<< "\n";
Admin::instance().update(message.str());
+ if (waitBridgeCompleted(session))
+ {
+ ws->shutdown();
+ throw WebSocketException("Failed to connect to client session", WebSocket::WS_ENDPOINT_GOING_AWAY);
+ }
+ Log::debug("Connected " + session->getName() + ".");
+ // Now the bridge beetween the prison and the client is connected
+ // Let messages flow
+
IoUtil::SocketProcessor(ws, response,
[&session](const std::vector<char>& payload)
{
More information about the Libreoffice-commits
mailing list