[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp loolwsd/MasterProcessSession.hpp

2016-04-09 Thread Henry Castro
 loolwsd/LOOLWSD.cpp  |   83 +--
 loolwsd/MasterProcessSession.cpp |   48 --
 loolwsd/MasterProcessSession.hpp |2 
 3 files changed, 81 insertions(+), 52 deletions(-)

New commits:
commit 9ae7fa5b9b26ef4fa2bee1d48362ea384787ea65
Author: Henry Castro 
Date:   Sat Apr 9 11:54:22 2016 -0400

loolwsd: wait until bridge is completed

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 9e32cbd..34291f8 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -151,6 +151,12 @@ static std::mutex newChildrenMutex;
 static std::condition_variable newChildrenCV;
 static std::map docBrokers;
 static std::mutex docBrokersMutex;
+// Sessions to pre-spawned child processes that have connected but are not yet 
assigned a
+// document to work on.
+static std::mutex AvailableChildSessionMutex;
+static std::condition_variable AvailableChildSessionCV;
+static std::map 
AvailableChildSessions;
+
 
 static void forkChildren(const int number)
 {
@@ -244,6 +250,51 @@ class ClientRequestHandler: public HTTPRequestHandler
 {
 private:
 
+static bool waitBridgeCompleted(const 
std::shared_ptr& clientSession,
+const std::shared_ptr& 
docBroker)
+{
+int retries = 5;
+bool isFound = false;
+
+// Wait until the client has connected with a prison socket.
+std::shared_ptr prisonSession;
+std::unique_lock lock(AvailableChildSessionMutex);
+
+Log::debug() << "Waiting for client session [" << 
clientSession->getId() << "] to connect." << Log::end;
+while (retries-- && !isFound)
+{
+AvailableChildSessionCV.wait_for(
+lock,
+std::chrono::milliseconds(3000),
+[, ]
+{
+return (isFound = 
AvailableChildSessions.find(clientSession->getId()) != 
AvailableChildSessions.end());
+});
+
+if (!isFound)
+{
+Log::info() << "Retrying client permission... " << retries 
<< Log::end;
+// request again new URL session
+const std::string message = "request " + 
clientSession->getId() + " " + docBroker->getDocKey() + '\n';
+Log::trace("MasterToBroker: " + message.substr(0, 
message.length()-1));
+IoUtil::writeFIFO(LOOLWSD::ForKitWritePipe, message);
+}
+}
+
+if (isFound)
+{
+Log::debug("Waiting child session permission, done!");
+prisonSession = AvailableChildSessions[clientSession->getId()];
+AvailableChildSessions.erase(clientSession->getId());
+
+clientSession->setPeer(prisonSession);
+prisonSession->setPeer(clientSession);
+Log::debug("Connected " + clientSession->getName() + " - " + 
prisonSession->getName() + ".");
+}
+
+return isFound;
+}
+
 static void handlePostRequest(HTTPServerRequest& request, 
HTTPServerResponse& response, const std::string& id)
 {
 Log::info("Post request: [" + request.getURI() + "]");
@@ -295,6 +346,18 @@ private:
 docBroker->incSessions();
 lock.unlock();
 
+if (!waitBridgeCompleted(session, docBroker))
+{
+Log::error(session->getName() + ": Failed to connect 
to lokit child.");
+// Let the client know we can't serve now.
+
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_SERVICE_UNAVAILABLE);
+response.setContentLength(0);
+response.send();
+return;
+}
+// Now the bridge beetween the client and kit process is 
connected
+// Let messages flow
+
 std::string encodedFrom;
 URI::encode(docBroker->getPublicUri().getPath(), "", 
encodedFrom);
 const std::string load = "load url=" + encodedFrom;
@@ -495,6 +558,18 @@ private:
 if (wsSessionsCount == 1)
 session->setEditLock(true);
 
+if (!waitBridgeCompleted(session, docBroker))
+{
+Log::error(session->getName() + ": Failed to connect to child. 
Client cannot serve now.");
+// Let the client know we can't serve now.
+
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_SERVICE_UNAVAILABLE);
+response.setContentLength(0);
+response.send();
+return;
+}
+// Now the bridge beetween the client and kit process is connected
+// Let messages flow
+
 QueueHandler handler(queue, session, "wsd_queue_" + session->getId());
 
 Thread 

[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp loolwsd/MessageQueue.hpp loolwsd/QueueHandler.hpp

2016-03-28 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp  |   32 +++-
 loolwsd/MasterProcessSession.cpp |3 ++-
 loolwsd/MessageQueue.hpp |6 +-
 loolwsd/QueueHandler.hpp |8 +---
 4 files changed, 23 insertions(+), 26 deletions(-)

New commits:
commit 3217b4592a6e196486440c2149132233b79d5982
Author: Ashod Nakashian 
Date:   Sat Mar 26 22:56:10 2016 -0400

loolwsd: queue payload changed to vector

All messages now pass through the queue.
This resolves a race between single-line
messages and multi-line ones.

Previously, single-line messages were
processed on the queue (on a background
thread) while multi-line ones were handled
immediatly. This resulted in order-inversion
due to a race between the queue thread and the
next multi-line message, which caused stability
issues every so often.

Change-Id: Ia220791d1d75c4f3e3e0965dd0c6f81bae63a296
Reviewed-on: https://gerrit.libreoffice.org/23583
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 749b2e2..b4cc910 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -221,7 +221,7 @@ public:
 // Handler returns false to end.
 void SocketProcessor(std::shared_ptr ws,
  HTTPServerResponse& response,
- std::function 
handler)
+ std::function handler)
 {
 Log::info("Starting Socket Processor.");
 
@@ -322,7 +322,7 @@ void SocketProcessor(std::shared_ptr ws,
 }
 
 // Call the handler.
-if (!handler(payload.data(), payload.size()))
+if (!handler(payload))
 {
 Log::info("Socket handler flagged for finishing.");
 }
@@ -614,30 +614,20 @@ private:
 queueHandlerThread.start(handler);
 bool normalShutdown = false;
 
-SocketProcessor(ws, response, [, , 
](const char* data, const int size, const bool singleLine)
+SocketProcessor(ws, response, [, , 
](const std::vector& payload)
 {
-// FIXME: There is a race here when a request A gets in the 
queue and
-// is processed _after_ a later request B, because B gets 
processed
-// synchronously and A is waiting in the queue thread.
-// The fix is to push everything into the queue
-// (i.e. change MessageQueue to vector).
-const std::string firstLine = getFirstLine(data, size);
+const auto firstLine = getFirstLine(payload.data(), 
payload.size());
 time(>_lastMessageTime);
-if (singleLine || firstLine.find("paste") == 0)
+if (firstLine.compare(0, 10, "disconnect") == 0) // starts 
with "disconnect"
 {
-if (firstLine.compare(0, 10, "disconnect") == 0) // starts 
with "disconnect"
-{
-normalShutdown = true;
-return true;
-}
-
-queue.put(std::string(data, size));
-return true;
+normalShutdown = true;
 }
 else
 {
-return session->handleInput(data, size);
+queue.put(payload);
 }
+
+return true;
 });
 
 if (docBroker->getSessionsCount() == 1 && !normalShutdown)
@@ -831,9 +821,9 @@ public:
 lock.unlock();
 MasterProcessSession::AvailableChildSessionCV.notify_one();
 
-SocketProcessor(ws, response, [](const char* data, const 
int size, bool)
+SocketProcessor(ws, response, [](const std::vector& 
payload)
 {
-return session->handleInput(data, size);
+return session->handleInput(payload.data(), 
payload.size());
 });
 }
 catch (const Exception& exc)
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 62e4d6f..0fbf70c 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -500,7 +500,8 @@ bool MasterProcessSession::getPartPageRectangles(const char 
*buffer, int length)
 
 std::string MasterProcessSession::getSaveAs()
 {
-return _saveAsQueue.get();
+const auto payload = _saveAsQueue.get();
+return std::string(payload.data(), payload.size());
 }
 
 void MasterProcessSession::sendFontRendering(const char *buffer, int length, 
StringTokenizer& tokens)
diff --git a/loolwsd/MessageQueue.hpp b/loolwsd/MessageQueue.hpp
index 2d62173..5a0c439 100644
--- a/loolwsd/MessageQueue.hpp
+++ b/loolwsd/MessageQueue.hpp
@@ -21,7 +21,7 @@ class MessageQueue
 {
 

[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp loolwsd/MasterProcessSession.hpp

2016-03-25 Thread Miklos Vajna
 loolwsd/LOOLWSD.cpp  |   14 +++---
 loolwsd/MasterProcessSession.cpp |6 +++---
 loolwsd/MasterProcessSession.hpp |6 +++---
 3 files changed, 13 insertions(+), 13 deletions(-)

New commits:
commit 08b52fae72a7794b75d30f6bd4a9225199abd2c3
Author: Miklos Vajna 
Date:   Fri Mar 25 17:10:16 2016 +0100

MasterProcessSession: fix missing prefixes

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ea745ca..7412124 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -614,7 +614,7 @@ private:
 // The fix is to push everything into the queue
 // (i.e. change MessageQueue to vector).
 const std::string firstLine = getFirstLine(data, size);
-time(>lastMessageTime);
+time(>_lastMessageTime);
 if (singleLine || firstLine.find("paste") == 0)
 {
 if (firstLine.compare(0, 10, "disconnect") == 0) // starts 
with "disconnect"
@@ -1453,13 +1453,13 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 std::unique_lock sessionsLock(sessionsMutex);
 for (auto& it : sessions)
 {
-if (it->lastMessageTime > it->idleSaveTime &&
-it->lastMessageTime < now - 30)
+if (it->_lastMessageTime > it->_idleSaveTime &&
+it->_lastMessageTime < now - 30)
 {
 // Trigger a .uno:Save
 Log::info("Idle save triggered for session " + 
it->getId());
 
-it->idleSaveTime = now;
+it->_idleSaveTime = now;
 }
 }
 }
@@ -1471,13 +1471,13 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 std::unique_lock sessionsLock(sessionsMutex);
 for (auto& it : sessions)
 {
-if (it->lastMessageTime >= it->idleSaveTime &&
-it->lastMessageTime >= it->autoSaveTime)
+if (it->_lastMessageTime >= it->_idleSaveTime &&
+it->_lastMessageTime >= it->_autoSaveTime)
 {
 // Trigger a .uno:Save
 Log::info("Auto-save triggered for session " + 
it->getId());
 
-it->autoSaveTime = now;
+it->_autoSaveTime = now;
 }
 }
 }
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index f7b26ce..52e96c9 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -35,9 +35,9 @@ MasterProcessSession::MasterProcessSession(const std::string& 
id,

std::shared_ptr ws,
std::shared_ptr 
docBroker) :
 LOOLSession(id, kind, ws),
-lastMessageTime(0),
-idleSaveTime(0),
-autoSaveTime(0),
+_lastMessageTime(0),
+_idleSaveTime(0),
+_autoSaveTime(0),
 _curPart(0),
 _loadPart(-1),
 _docBroker(docBroker)
diff --git a/loolwsd/MasterProcessSession.hpp b/loolwsd/MasterProcessSession.hpp
index 7b0b0cb..defe5ea 100644
--- a/loolwsd/MasterProcessSession.hpp
+++ b/loolwsd/MasterProcessSession.hpp
@@ -50,9 +50,9 @@ class MasterProcessSession final : public LOOLSession, public 
std::enable_shared
 static std::mutex AvailableChildSessionMutex;
 static std::condition_variable AvailableChildSessionCV;
 
-time_t lastMessageTime;
-time_t idleSaveTime;
-time_t autoSaveTime;
+time_t _lastMessageTime;
+time_t _idleSaveTime;
+time_t _autoSaveTime;
 
  protected:
 bool invalidateTiles(const char *buffer, int length, 
Poco::StringTokenizer& tokens);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-03-13 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp  |2 ++
 loolwsd/MasterProcessSession.cpp |3 ---
 2 files changed, 2 insertions(+), 3 deletions(-)

New commits:
commit 38c4acd5f0ec6e96458e86ddb357e12177dd8dd0
Author: Ashod Nakashian 
Date:   Sat Mar 12 20:39:34 2016 -0500

loolwsd: moved document loading outside of MasterProcessSession

Change-Id: I8ecce82abcae6d0f07b86c188c91913ff9ca115a
Reviewed-on: https://gerrit.libreoffice.org/23219
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 28b1a8e..1d63532 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -681,6 +681,8 @@ public:
 }
 }
 
+docBroker->load(jailId);
+
 auto ws = std::make_shared(request, response);
 auto session = std::make_shared(sessionId, 
LOOLSession::Kind::ToPrisoner, ws, docBroker);
 
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index bdb730f..d78a762 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -801,9 +801,6 @@ void MasterProcessSession::dispatchChild()
 return;
 }
 
-const auto jailRoot = Poco::Path(LOOLWSD::ChildRoot, 
childSession->_childId);
-_docBroker->load(childSession->_childId);
-
 _peer = childSession;
 childSession->_peer = shared_from_this();
 childSession->_docBroker = _docBroker;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp loolwsd/MasterProcessSession.hpp

2016-03-13 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp  |   37 ++-
 loolwsd/MasterProcessSession.cpp |   41 +++
 loolwsd/MasterProcessSession.hpp |   12 +--
 3 files changed, 46 insertions(+), 44 deletions(-)

New commits:
commit 64d2ff98b8e8329a8f0a2b57dbdc490733ecb28a
Author: Ashod Nakashian 
Date:   Sat Mar 12 09:07:33 2016 -0500

loolwsd: document saving and restructuring

Change-Id: Ia4c644d07a16ba5284e9cdfaf7b838134fbf640b
Reviewed-on: https://gerrit.libreoffice.org/23212
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 162dae7..1e833d9 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -508,29 +508,13 @@ private:
 const auto uri = DocumentStoreManager::getUri(request.getURI());
 const auto docKey = uri.getPath();
 
-// This lock could become a bottleneck.
-// In that case, we can use a pool and index by publicPath.
-std::unique_lock lock(LOOLWSD::SessionsMutex);
-
-// Lookup this document.
-auto it = LOOLWSD::Sessions.find(docKey);
-std::shared_ptr document;
-if (it != LOOLWSD::Sessions.end())
-{
-// Get the DocumentStoreManager from the first session.
-auto sessionsMap = it->second;
-assert(!sessionsMap.empty());
-document = sessionsMap.begin()->second->getDocumentStoreManager();
-}
-else
-{
-// Set up the document and its storage.
-const auto jailRoot = Poco::Path(LOOLWSD::ChildRoot, id);
-document = DocumentStoreManager::create(uri, jailRoot.toString(), 
id);
-}
+// Request a kit process for this doc.
+const std::string aMessage = "request " + id + " " + docKey + "\r\n";
+Log::debug("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 
2));
+Util::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
 
 auto ws = std::make_shared(request, response);
-auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws, document);
+auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws, nullptr);
 
 // For ToClient sessions, we store incoming messages in a queue and 
have a separate
 // thread that handles them. This is so that we can empty the queue 
when we get a
@@ -646,7 +630,16 @@ public:
 Log::debug("Thread [" + thread_name + "] started.");
 
 auto ws = std::make_shared(request, response);
-auto session = std::make_shared(id, 
LOOLSession::Kind::ToPrisoner, ws, nullptr);
+auto session = std::make_shared(sessionId, 
LOOLSession::Kind::ToPrisoner, ws, nullptr);
+
+std::unique_lock 
lock(MasterProcessSession::AvailableChildSessionMutex);
+MasterProcessSession::AvailableChildSessions.emplace(sessionId, 
session);
+
+Log::info() << " mapped " << session << " jailId=" << jailId << ", 
id=" << sessionId
+<< " into _availableChildSessions, size=" << 
MasterProcessSession::AvailableChildSessions.size() << Log::end;
+
+lock.unlock();
+MasterProcessSession::AvailableChildSessionCV.notify_one();
 
 SocketProcessor(ws, response, [](const char* data, const 
int size, bool)
 {
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 46174c9..5e1e33b 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -117,7 +117,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, 
int length)
 // Note that this handles both forwarding requests from the client to 
the child process, and
 // forwarding replies from the child process to the client. Or does it?
 
-// Snoop at some  messages and manipulate tile cache information as 
needed
+// Snoop at some messages and manipulate tile cache information as 
needed
 auto peer = _peer.lock();
 
 if (_kind == Kind::ToPrisoner)
@@ -128,6 +128,27 @@ bool MasterProcessSession::_handleInput(const char 
*buffer, int length)
 return false;
 }
 
+if (tokens[0] == "unocommandresult:")
+{
+const std::string stringMsg(buffer, length);
+Log::info(getName() +"Command: " + stringMsg);
+const auto index = stringMsg.find_first_of("{");
+if (index != std::string::npos)
+{
+const std::string stringJSON = stringMsg.substr(index);
+Poco::JSON::Parser parser;
+const auto result = parser.parse(stringJSON);
+const auto object = 
result.extract();
+if 

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

2016-03-09 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp  |7 +--
 loolwsd/MasterProcessSession.cpp |   77 +++
 2 files changed, 41 insertions(+), 43 deletions(-)

New commits:
commit 237e0c0e9abdd62f4107fa249e04b18c043eb8a8
Author: Ashod Nakashian 
Date:   Wed Mar 9 23:17:26 2016 -0500

loolwsd: minor cleanups and const correctness

Change-Id: Ic3b26e1fbf5feba1667bc3dc1737d037590a5928
Reviewed-on: https://gerrit.libreoffice.org/23109
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index dee237c..5f841d8 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -501,10 +501,9 @@ private:
 
 //TODO: Authenticate the caller.
 // authenticate(request, response);
-
-NameValueCollection cookies;
-request.getCookies(cookies);
-Log::info("Cookie: " + cookies.get("PHPSESSID", ""));
+// NameValueCollection cookies;
+// request.getCookies(cookies);
+// Log::info("Cookie: " + cookies.get("PHPSESSID", ""));
 
 auto ws = std::make_shared(request, response);
 auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws);
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 92e2126..99b147e 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -446,39 +446,36 @@ bool MasterProcessSession::loadDocument(const char* 
/*buffer*/, int /*length*/,
 return false;
 }
 
-std::string timestamp;
-parseDocOptions(tokens, _loadPart, timestamp);
-
 try
 {
-// Strip query params because we need unique URI (need a better 
solution!).
-StringTokenizer urlTokens(_docURL, "?", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
+std::string timestamp;
+parseDocOptions(tokens, _loadPart, timestamp);
 
-// request new URL session
-const std::string aMessage = "request " + getId() + " " + urlTokens[0] 
+ "\r\n";
-Log::trace("MasterToBroker: " + aMessage.substr(0, 
aMessage.length()-2));
+// Request a kit process for this doc.
+Poco::URI uri(_docURL);
+const std::string aMessage = "request " + getId() + " " + 
uri.getPath() + "\n";
+Log::trace("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 
1));
 Util::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
+
+_tileCache.reset(new TileCache(_docURL, timestamp));
+
+// Finally, wait for the Child to connect to Master,
+// link the document in jail and dispatch load to child.
+dispatchChild();
+
+return true;
 }
 catch (const Poco::SyntaxException&)
 {
 sendTextFrame("error: cmd=load kind=uriinvalid");
-return false;
 }
 
-_tileCache.reset(new TileCache(_docURL, timestamp));
-
-// Finally, wait for the Child to connect to Master,
-// link the document in jail and dispatch load to child.
-dispatchChild();
-
-return true;
+return false;
 }
 
 bool MasterProcessSession::getStatus(const char *buffer, int length)
 {
-std::string status;
-
-status = _tileCache->getTextFile("status.txt");
+const std::string status = _tileCache->getTextFile("status.txt");
 if (status.size() > 0)
 {
 sendTextFrame(status);
@@ -500,7 +497,7 @@ bool MasterProcessSession::getCommandValues(const char 
*buffer, int length, Stri
 return false;
 }
 
-std::string cmdValues = _tileCache->getTextFile("cmdValues" + command + 
".txt");
+const std::string cmdValues = _tileCache->getTextFile("cmdValues" + 
command + ".txt");
 if (cmdValues.size() > 0)
 {
 sendTextFrame(cmdValues);
@@ -515,7 +512,7 @@ bool MasterProcessSession::getCommandValues(const char 
*buffer, int length, Stri
 
 bool MasterProcessSession::getPartPageRectangles(const char *buffer, int 
length)
 {
-std::string partPageRectangles = 
_tileCache->getTextFile("partpagerectangles.txt");
+const std::string partPageRectangles = 
_tileCache->getTextFile("partpagerectangles.txt");
 if (partPageRectangles.size() > 0)
 {
 sendTextFrame(partPageRectangles);
@@ -536,7 +533,6 @@ std::string MasterProcessSession::getSaveAs()
 void MasterProcessSession::sendFontRendering(const char *buffer, int length, 
StringTokenizer& tokens)
 {
 std::string font;
-
 if (tokens.count() < 2 ||
 !getTokenString(tokens[1], "font", font))
 {
@@ -544,7 +540,7 @@ void MasterProcessSession::sendFontRendering(const char 
*buffer, int length, Str
 return;
 }
 
-std::string response = "renderfont: " + Poco::cat(std::string(" "), 
tokens.begin() + 1, tokens.end()) + "\n";
+const std::string response = "renderfont: " + Poco::cat(std::string(" "), 
tokens.begin() + 1, tokens.end()) + "\n";
 
 std::vector output;

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

2016-01-24 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp  |   89 ++-
 loolwsd/MasterProcessSession.cpp |3 +
 2 files changed, 55 insertions(+), 37 deletions(-)

New commits:
commit b85b4423b0e189d24d0374f5c0511011ee58780c
Author: Ashod Nakashian 
Date:   Sat Jan 23 19:41:01 2016 -0500

loolwsd: break the wait on save-as queue and better failure handling

Change-Id: Ifee252b3c189ee0b1287bda891b38c5abddb7440
Reviewed-on: https://gerrit.libreoffice.org/21755
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 4db32fb..138fde7 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -344,9 +344,11 @@ public:
 
 if (!(request.find("Upgrade") != request.end() && 
Poco::icompare(request["Upgrade"], "websocket") == 0))
 {
+Log::info("Post request.");
 StringTokenizer tokens(request.getURI(), "/?");
 if (tokens.count() >= 2 && tokens[1] == "convert-to")
 {
+Log::info("Conversion request.");
 std::string fromPath;
 ConvertToPartHandler handler(fromPath);
 Poco::Net::HTMLForm form(request, request.stream(), handler);
@@ -354,51 +356,61 @@ public:
 if (form.has("format"))
 format = form.get("format");
 
-if (!fromPath.empty() && !format.empty())
+bool sent = false;
+if (!fromPath.empty())
 {
-// Load the document.
-std::shared_ptr ws;
-const LOOLSession::Kind kind = LOOLSession::Kind::ToClient;
-auto session = std::make_shared(id, 
kind, ws);
-const std::string filePrefix("file://");
-std::string encodedFrom;
-URI::encode(filePrefix + fromPath, std::string(), 
encodedFrom);
-const std::string load = "load url=" + encodedFrom;
-session->handleInput(load.data(), load.size());
-
-// Convert it to the requested format.
-Path toPath(fromPath);
-toPath.setExtension(format);
-std::string toJailURL = filePrefix + JailedDocumentRoot + 
toPath.getFileName();
-std::string encodedTo;
-URI::encode(toJailURL, std::string(), encodedTo);
-std::string saveas = "saveas url=" + encodedTo + " 
format=" + format + " options=";
-session->handleInput(saveas.data(), saveas.size());
-
-std::string toURL = session->getSaveAs();
-std::string resultingURL;
-URI::decode(toURL, resultingURL);
-
-// Send it back to the client.
-std::string mimeType = "application/octet-stream";
-if (resultingURL.find(filePrefix) == 0)
-resultingURL = 
resultingURL.substr(filePrefix.length());
-response.sendFile(resultingURL, mimeType);
+if (!format.empty())
+{
+// Load the document.
+std::shared_ptr ws;
+const LOOLSession::Kind kind = 
LOOLSession::Kind::ToClient;
+auto session = 
std::make_shared(id, kind, ws);
+const std::string filePrefix("file://");
+std::string encodedFrom;
+URI::encode(filePrefix + fromPath, std::string(), 
encodedFrom);
+const std::string load = "load url=" + encodedFrom;
+session->handleInput(load.data(), load.size());
+
+// Convert it to the requested format.
+Path toPath(fromPath);
+toPath.setExtension(format);
+std::string toJailURL = filePrefix + 
JailedDocumentRoot + toPath.getFileName();
+std::string encodedTo;
+URI::encode(toJailURL, std::string(), encodedTo);
+std::string saveas = "saveas url=" + encodedTo + " 
format=" + format + " options=";
+session->handleInput(saveas.data(), saveas.size());
+
+std::string toURL = session->getSaveAs();
+std::string resultingURL;
+URI::decode(toURL, resultingURL);
+
+// Send it back to the client.
+if (resultingURL.find(filePrefix) == 0)
+resultingURL = 
resultingURL.substr(filePrefix.length());
+if (!resultingURL.empty())
+{
+const