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

2016-11-23 Thread Miklos Vajna
 loolwsd/DocumentBroker.cpp |2 --
 1 file changed, 2 deletions(-)

New commits:
commit b7065d603de8e8277d485a5d6d8e323de81a5855
Author: Miklos Vajna 
Date:   Wed Nov 23 09:06:48 2016 +0100

DocumentBroker: clean up redundant member init

Change-Id: I5b8f7afe5329c2d1f8abb404c086dcd08c6f1a1f

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 9fa56ae..14bbd4b 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -161,8 +161,6 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 _cursorPosY(0),
 _cursorWidth(0),
 _cursorHeight(0),
-_mutex(),
-_saveMutex(),
 _tileVersion(0),
 _debugRenderedTileCount(0)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-21 Thread Miklos Vajna
 loolwsd/DocumentBroker.cpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit c989ead6b842e62ee6ad68e327bc930d2eae1933
Author: Miklos Vajna 
Date:   Mon Nov 21 10:02:27 2016 +0100

DocumentBroker: fix uninitialized getInfoCallDuration

It was written in one conditional branch and was read in an other
conditional branch. So make sure no uninitialized data is read.

Change-Id: I230c6a4d3b048ee9d7f96881baf00eb041204ff0

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 39702cc..74dada2 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -247,7 +247,7 @@ bool DocumentBroker::load(std::shared_ptr& 
session, const std::st
 
 // Call the storage specific file info functions
 std::string userid, username;
-std::chrono::duration getInfoCallDuration;
+std::chrono::duration getInfoCallDuration(0);
 if (dynamic_cast(_storage.get()) != nullptr)
 {
 const WopiStorage::WOPIFileInfo wopifileinfo = 
static_cast(_storage.get())->getWOPIFileInfo(uriPublic);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-19 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   31 ++-
 1 file changed, 26 insertions(+), 5 deletions(-)

New commits:
commit 827c0865e7683eb29016fb80c909f4d4316a0ae2
Author: Ashod Nakashian 
Date:   Sat Nov 19 10:04:42 2016 -0500

loolwsd: handle exceptions from socket calls

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 95fdd4d..9e4cc3d 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -584,7 +584,14 @@ void DocumentBroker::alertAllUsers(const std::string& msg)
 
 for (auto& it : _sessions)
 {
-it.second->sendTextFrame(msg);
+try
+{
+it.second->sendTextFrame(msg);
+}
+catch (const std::exception& ex)
+{
+LOG_ERR("Error while alerting all users [" << msg << "]: " << 
ex.what());
+}
 }
 }
 
@@ -926,7 +933,14 @@ void DocumentBroker::childSocketTerminated()
 // For now, close the connections to cleanup.
 for (auto& pair : _sessions)
 {
-pair.second->shutdown(Poco::Net::WebSocket::WS_ENDPOINT_GOING_AWAY);
+try
+{
+
pair.second->shutdown(Poco::Net::WebSocket::WS_ENDPOINT_GOING_AWAY);
+}
+catch (const std::exception& ex)
+{
+LOG_ERR("Error while terminating client connection [" << 
pair.first << "]: " << ex.what());
+}
 }
 }
 
@@ -940,9 +954,16 @@ void 
DocumentBroker::terminateChild(std::unique_lock& lock, const st
 // Close all running sessions
 for (auto& pair : _sessions)
 {
-// See protocol.txt for this application-level close frame
-pair.second->sendTextFrame("close: " + closeReason);
-pair.second->shutdown(Poco::Net::WebSocket::WS_ENDPOINT_GOING_AWAY, 
closeReason);
+try
+{
+// See protocol.txt for this application-level close frame.
+pair.second->sendTextFrame("close: " + closeReason);
+
pair.second->shutdown(Poco::Net::WebSocket::WS_ENDPOINT_GOING_AWAY, 
closeReason);
+}
+catch (const std::exception& ex)
+{
+LOG_ERR("Error while terminating client connection [" << 
pair.first << "]: " << ex.what());
+}
 }
 
 // First flag to stop as it might be waiting on our lock
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-19 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

New commits:
commit 0c44eeb39a8401c9430556f7ee3da155f03f0371
Author: Ashod Nakashian 
Date:   Sat Nov 19 09:50:42 2016 -0500

loolwsd: support loading same document from aliased hosts

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 1b35377..95fdd4d 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -131,9 +131,15 @@ Poco::URI DocumentBroker::sanitizeURI(const std::string& 
uri)
 
 std::string DocumentBroker::getDocKey(const Poco::URI& uri)
 {
-// Keep the host as part of the key to close a potential security hole.
+// If multiple host-names are used to access us, then
+// they must be aliases. Permission to access aliased hosts
+// is checked at the point of accepting incoming connections.
+// At this point storing the hostname artificially discriminates
+// between aliases and forces same document (when opened from
+// alias hosts) to load as separate documents and sharing doesn't
+// work. Worse, saving overwrites one another.
 std::string docKey;
-Poco::URI::encode(uri.getHost() + uri.getPath(), "", docKey);
+Poco::URI::encode(uri.getPath(), "", docKey);
 return docKey;
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-19 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |7 ++-
 loolwsd/DocumentBroker.hpp |7 ++-
 loolwsd/LOOLWSD.cpp|   11 ---
 loolwsd/Util.hpp   |   22 --
 4 files changed, 32 insertions(+), 15 deletions(-)

New commits:
commit d3e64b1aa478f6b6b5c62cfc5877c7bd29785645
Author: Ashod Nakashian 
Date:   Thu Nov 17 09:00:05 2016 -0500

loolwsd: improved alertAllUsers

More flexible reason message and other cleanups
to help use altertAllUsers in other situations.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 6cc4847..1b35377 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -517,7 +517,7 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 // even if in this case it might be a totally different location (file 
system, or
 // some other type of storage somewhere). This message is not sent to 
all clients,
 // though, just to all sessions of this document.
-alertAllUsersOfDocument("internal", "diskfull");
+alertAllUsers("internal", "diskfull");
 throw;
 }
 
@@ -572,13 +572,10 @@ size_t DocumentBroker::removeSession(const std::string& 
id)
 return _sessions.size();
 }
 
-void DocumentBroker::alertAllUsersOfDocument(const std::string& cmd, const 
std::string& kind)
+void DocumentBroker::alertAllUsers(const std::string& msg)
 {
 Util::assertIsLocked(_mutex);
 
-std::stringstream ss;
-ss << "error: cmd=" << cmd << " kind=" << kind;
-const auto msg = ss.str();
 for (auto& it : _sessions)
 {
 it.second->sendTextFrame(msg);
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 7e94fa2..6672aaf 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -242,7 +242,12 @@ public:
 /// Removes a session by ID. Returns the new number of sessions.
 size_t removeSession(const std::string& id);
 
-void alertAllUsersOfDocument(const std::string& cmd, const std::string& 
kind);
+void alertAllUsers(const std::string& msg);
+
+void alertAllUsers(const std::string& cmd, const std::string& kind)
+{
+alertAllUsers("error: cmd=" + cmd + " kind=" + kind);
+}
 
 /// Invalidate the cursor position.
 void invalidateCursor(int x, int y, int w, int h)
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 8a3fd40..0a34591 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -2078,7 +2078,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 // and wait until sockets close.
 LOG_INF("Stopping server socket listening. ShutdownFlag: " <<
 ShutdownFlag << ", TerminationFlag: " << TerminationFlag);
-Util::alertAllUsers("internal", "shutdown");
+Util::alertAllUsers("close: shutdown");
 
 srv.stop();
 srv2.stop();
@@ -2149,14 +2149,19 @@ namespace Util
 
 void alertAllUsers(const std::string& cmd, const std::string& kind)
 {
+alertAllUsers("error: cmd=" + cmd + " kind=" + kind);
+}
+
+void alertAllUsers(const std::string& msg)
+{
 std::lock_guard DocBrokersLock(DocBrokersMutex);
 
-LOG_INF("Alerting all users: cmd=" << cmd << ", kind=" << kind);
+LOG_INF("Alerting all users: [" << msg << "]");
 
 for (auto& brokerIt : DocBrokers)
 {
 auto lock = brokerIt.second->getLock();
-brokerIt.second->alertAllUsersOfDocument(cmd, kind);
+brokerIt.second->alertAllUsers(msg);
 }
 }
 
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index 40bcc30..e567972 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -47,14 +47,24 @@ namespace Util
 bool windowingAvailable();
 
 #ifndef BUILDING_TESTS
-// Send a 'error:' message with the specified cmd and kind parameters to 
all connected
-// clients. This function can be called either in loolwsd or loolkit 
processes, even if only
-// loolwsd obviously has contact with the actual clients; in loolkit it 
will be forwarded to
-// loolwsd for redistribution. (This function must be implemented 
separately in each program
-// that uses it, it is not in Util.cpp.)
+
+/// Send a message to all clients.
+void alertAllUsers(const std::string& msg);
+
+/// Send a 'error:' message with the specified cmd and kind parameters to 
all connected
+/// clients. This function can be called either in loolwsd or loolkit 
processes, even if only
+/// loolwsd obviously has contact with the actual clients; in loolkit it 
will be forwarded to
+/// loolwsd for redistribution. (This function must be implemented 
separately in each program
+/// that uses it, it is not in Util.cpp.)
 void alertAllUsers(const std::string& cmd, const std::string& kind);
 

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

2016-11-13 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |1 -
 loolwsd/LOOLWSD.cpp|   15 +--
 2 files changed, 13 insertions(+), 3 deletions(-)

New commits:
commit 92ca5225a56bd511ac81bbb456f12f2670625a5b
Author: Ashod Nakashian 
Date:   Sun Nov 13 16:14:58 2016 -0500

loolwsd: logs and consistent formatting

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 5412c4b..51badf4 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -68,7 +68,6 @@ void ChildProcess::socketProcessor()
 
 LOG_DBG("Child [" << getPid() << "] WS terminated. Notifying DocBroker.");
 
-
 // Notify the broker that we're done.
 auto docBroker = _docBroker.lock();
 if (docBroker && !_stop)
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 4655a91..bb2bd85 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1926,7 +1926,11 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 findFreeMasterPort(MasterPortNumber) :
 getMasterSocket(MasterPortNumber));
 if (!psvs2)
+{
+LOG_FTL("Failed to listen on master port (" <<
+MasterPortNumber << ") or find a free port. Exiting.");
 return Application::EXIT_SOFTWARE;
+}
 
 HTTPServer srv2(new PrisonerRequestHandlerFactory(), threadPool, *psvs2, 
params2);
 LOG_INF("Starting prisoner server listening on " << MasterPortNumber);
@@ -1946,7 +1950,11 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 findFreeServerPort(ClientPortNumber) :
 getServerSocket(ClientPortNumber, true));
 if (!psvs)
+{
+LOG_FTL("Failed to listen on client port (" <<
+ClientPortNumber << ") or find a free port. Exiting.");
 return Application::EXIT_SOFTWARE;
+}
 
 HTTPServer srv(new ClientRequestHandlerFactory(), threadPool, *psvs, 
params1);
 LOG_INF("Starting master server listening on " << ClientPortNumber);
@@ -1962,7 +1970,9 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 {
 UnitWSD::get().invokeTest();
 if (TerminationFlag)
+{
 break;
+}
 
 const pid_t pid = waitpid(forKitPid, , WUNTRACED | WNOHANG);
 if (pid > 0)
@@ -2018,7 +2028,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 // No child processes.
 LOG_FTL("No Forkit instance. Terminating.");
 TerminationFlag = true;
-continue;
+break;
 }
 }
 else // pid == 0, no children have died
@@ -2058,6 +2068,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 {
 LOG_INF((time(nullptr) - startTimeSpan) << " seconds gone, 
finishing as requested.");
 TerminationFlag = true;
+break;
 }
 #endif
 }
@@ -2070,7 +2081,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 threadPool.joinAll();
 
 // Terminate child processes
-LOG_INF("Requesting child process " << forKitPid << " to terminate.");
+LOG_INF("Requesting forkit process " << forKitPid << " to terminate.");
 Util::requestTermination(forKitPid);
 for (auto& child : NewChildren)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-10 Thread Pranav Kant
 loolwsd/DocumentBroker.cpp |2 --
 1 file changed, 2 deletions(-)

New commits:
commit b1cec28cc33bb453e509be41fc6a9f03d2a686ac
Author: Pranav Kant 
Date:   Thu Nov 10 16:30:17 2016 +0530

This was only meant for debugging.

Change-Id: Ia31847ab45c1aa18b5d9d4187ac552d7486331e7

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 295e07c..edc453e 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -917,8 +917,6 @@ void 
DocumentBroker::terminateChild(std::unique_lock& lock, const st
 pair.second->shutdown(Poco::Net::WebSocket::WS_ENDPOINT_GOING_AWAY, 
closeReason);
 }
 
-std::this_thread::sleep_for (std::chrono::seconds(5));
-
 // First flag to stop as it might be waiting on our lock
 // to process some incoming message.
 _childProcess->stop();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-06 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   47 +
 loolwsd/DocumentBroker.hpp |2 -
 2 files changed, 23 insertions(+), 26 deletions(-)

New commits:
commit 2507f7f89cbdc6787c6fa806b7b7fe7970dc68cd
Author: Ashod Nakashian 
Date:   Sun Nov 6 23:14:23 2016 -0500

loolwsd: refactor DocumentBroker load and addSession

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 50208ba..723b73b 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -165,8 +165,12 @@ DocumentBroker::~DocumentBroker()
 _childProcess.reset();
 }
 
-bool DocumentBroker::load(const std::string& sessionId, const std::string& 
jailId)
+bool DocumentBroker::load(std::shared_ptr& session, const 
std::string& jailId)
 {
+Util::assertIsLocked(_mutex);
+
+const std::string sessionId = session->getId();
+
 LOG_INF("Loading [" << _docKey << "] for session [" << sessionId << "] and 
jail [" << jailId << "].");
 
 {
@@ -182,14 +186,6 @@ bool DocumentBroker::load(const std::string& sessionId, 
const std::string& jailI
 return false;
 }
 
-auto it = _sessions.find(sessionId);
-if (it == _sessions.end() || !it->second)
-{
-LOG_ERR("Session with sessionId [" << sessionId << "] not found while 
loading");
-return false;
-}
-
-auto session = it->second;
 const Poco::URI& uriPublic = session->getPublicUri();
 LOG_DBG("Loading from URI: " << uriPublic.toString());
 
@@ -466,21 +462,13 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 const auto id = session->getId();
 const std::string aMessage = "session " + id + " " + _docKey;
 
-std::lock_guard lock(_mutex);
-
-auto ret = _sessions.emplace(id, session);
-if (!ret.second)
-{
-LOG_WRN("DocumentBroker: Trying to add already existing session.");
-}
+std::unique_lock lock(_mutex);
 
 try
 {
 // First load the document, since this can fail.
-if (!load(id, std::to_string(_childProcess->getPid(
+if (!load(session, std::to_string(_childProcess->getPid(
 {
-_sessions.erase(id);
-
 const auto msg = "Failed to load document with URI [" + 
session->getPublicUri().toString() + "].";
 LOG_ERR(msg);
 throw std::runtime_error(msg);
@@ -489,7 +477,6 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 catch (const StorageSpaceLowException&)
 {
 LOG_ERR("Out of storage while loading document with URI [" << 
session->getPublicUri().toString() << "].");
-_sessions.erase(id);
 
 // We use the same message as is sent when some of lool's own 
locations are full,
 // even if in this case it might be a totally different location (file 
system, or
@@ -504,14 +491,23 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 _lastEditableSession = false;
 _markToDestroy = false;
 
-// Request a new session from the child kit.
-_childProcess->sendTextFrame(aMessage);
-
 if (session->isReadOnly())
 {
 LOG_DBG("Adding a readonly session [" << id << "]");
 }
 
+if (!_sessions.emplace(id, session).second)
+{
+LOG_WRN("DocumentBroker: Trying to add already existing session.");
+}
+
+const auto count = _sessions.size();
+
+lock.unlock();
+
+// Request a new session from the child kit.
+_childProcess->sendTextFrame(aMessage);
+
 // Tell the admin console about this new doc
 Admin::instance().addDoc(_docKey, getPid(), getFilename(), id);
 
@@ -521,7 +517,7 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 session->setPeer(prisonerSession);
 prisonerSession->setPeer(session);
 
-return _sessions.size();
+return count;
 }
 
 size_t DocumentBroker::removeSession(const std::string& id)
@@ -550,9 +546,10 @@ void DocumentBroker::alertAllUsersOfDocument(const 
std::string& cmd, const std::
 
 std::stringstream ss;
 ss << "error: cmd=" << cmd << " kind=" << kind;
+const auto msg = ss.str();
 for (auto& it : _sessions)
 {
-it.second->sendTextFrame(ss.str());
+it.second->sendTextFrame(msg);
 }
 }
 
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 60a7099..34195c9 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -198,7 +198,7 @@ public:
 ~DocumentBroker();
 
 /// Loads a document from the public URI into the jail.
-bool load(const std::string& sessionId, const std::string& jailId);
+bool load(std::shared_ptr& session, const std::string& 
jailId);
 bool isLoaded() const { return _isLoaded; }
 void setLoaded() { 

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

2016-11-06 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

New commits:
commit f6698918925b3a8a934329fabbdc8bfad003cf87
Author: Ashod Nakashian 
Date:   Sun Nov 6 22:29:19 2016 -0500

loolwsd: name the child socket thread

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index f18b049..7e250e4 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -34,12 +34,13 @@ using Poco::StringTokenizer;
 
 void ChildProcess::socketProcessor()
 {
+Util::setThreadName("child_ws_" + std::to_string(_pid));
+
 IoUtil::SocketProcessor(_ws,
 [this](const std::vector& payload)
 {
 const auto message = LOOLProtocol::getAbbreviatedMessage(payload);
-LOG_TRC("Recv from child " << this->_pid <<
-": [" << message << "].");
+LOG_TRC("Recv from child [" << message << "].");
 
 if (UnitWSD::get().filterChildMessage(payload))
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-06 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |3 +++
 1 file changed, 3 insertions(+)

New commits:
commit f3ffd5986039058a1dda24cb0ce3d8ca3fd331a2
Author: Ashod Nakashian 
Date:   Sun Nov 6 23:01:29 2016 -0500

loolwsd: assert ChildProcess doesn't destroy DocumentBroker

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 7e250e4..50208ba 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -50,6 +50,9 @@ void ChildProcess::socketProcessor()
 auto docBroker = this->_docBroker.lock();
 if (docBroker)
 {
+// We should never destroy the broker, since
+// it owns us and will wait on this thread.
+assert(docBroker.use_count() > 1);
 return docBroker->handleInput(payload);
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-06 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   52 -
 1 file changed, 28 insertions(+), 24 deletions(-)

New commits:
commit f1f1ff7057871e27be98b3fe6a92ad4d8a72608d
Author: Ashod Nakashian 
Date:   Sun Nov 6 22:11:59 2016 -0500

loolwsd: correct document loading and error handling

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 1613aec..f18b049 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -462,33 +462,21 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 const auto id = session->getId();
 const std::string aMessage = "session " + id + " " + _docKey;
 
-try
-{
-std::lock_guard lock(_mutex);
-
-// Request a new session from the child kit.
-_childProcess->sendTextFrame(aMessage);
+std::lock_guard lock(_mutex);
 
-auto ret = _sessions.emplace(id, session);
-if (!ret.second)
-{
-LOG_WRN("DocumentBroker: Trying to add already existing session.");
-}
+auto ret = _sessions.emplace(id, session);
+if (!ret.second)
+{
+LOG_WRN("DocumentBroker: Trying to add already existing session.");
+}
 
-if (session->isReadOnly())
+try
+{
+// First load the document, since this can fail.
+if (!load(id, std::to_string(_childProcess->getPid(
 {
-LOG_DBG("Adding a readonly session [" << id << "]");
-}
+_sessions.erase(id);
 
-// Below values are recalculated when startDestroy() is called (before 
destroying the
-// document). It is safe to reset their values to their defaults 
whenever a new session is added.
-_lastEditableSession = false;
-_markToDestroy = false;
-
-bool loaded;
-loaded = load(id, std::to_string(_childProcess->getPid()));
-if (!loaded)
-{
 const auto msg = "Failed to load document with URI [" + 
session->getPublicUri().toString() + "].";
 LOG_ERR(msg);
 throw std::runtime_error(msg);
@@ -496,6 +484,9 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 }
 catch (const StorageSpaceLowException&)
 {
+LOG_ERR("Out of storage while loading document with URI [" << 
session->getPublicUri().toString() << "].");
+_sessions.erase(id);
+
 // We use the same message as is sent when some of lool's own 
locations are full,
 // even if in this case it might be a totally different location (file 
system, or
 // some other type of storage somewhere). This message is not sent to 
all clients,
@@ -504,6 +495,19 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 throw;
 }
 
+// Below values are recalculated when startDestroy() is called (before 
destroying the
+// document). It is safe to reset their values to their defaults whenever 
a new session is added.
+_lastEditableSession = false;
+_markToDestroy = false;
+
+// Request a new session from the child kit.
+_childProcess->sendTextFrame(aMessage);
+
+if (session->isReadOnly())
+{
+LOG_DBG("Adding a readonly session [" << id << "]");
+}
+
 // Tell the admin console about this new doc
 Admin::instance().addDoc(_docKey, getPid(), getFilename(), id);
 
@@ -538,7 +542,7 @@ size_t DocumentBroker::removeSession(const std::string& id)
 
 void DocumentBroker::alertAllUsersOfDocument(const std::string& cmd, const 
std::string& kind)
 {
-std::lock_guard lock(_mutex);
+Util::assertIsLocked(_mutex);
 
 std::stringstream ss;
 ss << "error: cmd=" << cmd << " kind=" << kind;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-06 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

New commits:
commit 71f2f4921d4edd344d7742ee3b737faf4d3f46e7
Author: Ashod Nakashian 
Date:   Sun Nov 6 22:11:35 2016 -0500

loolwsd: better use named variable than it->second

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index cbc710c..1613aec 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -38,7 +38,7 @@ void ChildProcess::socketProcessor()
 [this](const std::vector& payload)
 {
 const auto message = LOOLProtocol::getAbbreviatedMessage(payload);
-LOG_WRN("Recv from child " << this->_pid <<
+LOG_TRC("Recv from child " << this->_pid <<
 ": [" << message << "].");
 
 if (UnitWSD::get().filterChildMessage(payload))
@@ -179,13 +179,14 @@ bool DocumentBroker::load(const std::string& sessionId, 
const std::string& jailI
 }
 
 auto it = _sessions.find(sessionId);
-if (it == _sessions.end())
+if (it == _sessions.end() || !it->second)
 {
 LOG_ERR("Session with sessionId [" << sessionId << "] not found while 
loading");
 return false;
 }
 
-const Poco::URI& uriPublic = it->second->getPublicUri();
+auto session = it->second;
+const Poco::URI& uriPublic = session->getPublicUri();
 LOG_DBG("Loading from URI: " << uriPublic.toString());
 
 _jailId = jailId;
@@ -232,12 +233,12 @@ bool DocumentBroker::load(const std::string& sessionId, 
const std::string& jailI
 if (!wopifileinfo._userCanWrite)
 {
 LOG_DBG("Setting the session as readonly");
-it->second->setReadOnly();
+session->setReadOnly();
 }
 
 if (!wopifileinfo._postMessageOrigin.empty())
 {
-it->second->sendTextFrame("wopi: postmessageorigin " + 
wopifileinfo._postMessageOrigin);
+session->sendTextFrame("wopi: postmessageorigin " + 
wopifileinfo._postMessageOrigin);
 }
 
 getInfoCallDuration = wopifileinfo._callDuration;
@@ -250,8 +251,8 @@ bool DocumentBroker::load(const std::string& sessionId, 
const std::string& jailI
 }
 
 LOG_DBG("Setting username [" << username << "] and userId [" << userid << 
"] for session [" << sessionId << "]");
-it->second->setUserId(userid);
-it->second->setUserName(username);
+session->setUserId(userid);
+session->setUserName(username);
 
 // Get basic file information from the storage
 const auto fileInfo = _storage->getFileInfo();
@@ -283,7 +284,7 @@ bool DocumentBroker::load(const std::string& sessionId, 
const std::string& jailI
 callDuration += getInfoCallDuration;
 const std::string msg = "stats: wopiloadduration " + 
std::to_string(callDuration.count());
 LOG_TRC("Sending to Client [" << msg << "].");
-it->second->sendTextFrame(msg);
+session->sendTextFrame(msg);
 }
 
 return true;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-06 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |  131 +++--
 1 file changed, 69 insertions(+), 62 deletions(-)

New commits:
commit 4e13f1b37c94a4e39197ec45d1db30acdae904fa
Author: Ashod Nakashian 
Date:   Sun Nov 6 13:54:00 2016 -0500

loolwsd: cleanup document and storage loading in WSD

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index cf66a4a..1462d3c 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -163,6 +163,8 @@ DocumentBroker::~DocumentBroker()
 
 bool DocumentBroker::load(const std::string& sessionId, const std::string& 
jailId)
 {
+LOG_INF("Loading [" << _docKey << "] for session [" << sessionId << "] and 
jail [" << jailId << "].");
+
 {
 bool result;
 if (UnitWSD::get().filterLoad(sessionId, jailId, result))
@@ -172,6 +174,7 @@ bool DocumentBroker::load(const std::string& sessionId, 
const std::string& jailI
 if (_markToDestroy)
 {
 // Tearing down.
+LOG_WRN("Will not load document marked to destroy. DocKey: [" << 
_docKey << "].");
 return false;
 }
 
@@ -193,11 +196,12 @@ bool DocumentBroker::load(const std::string& sessionId, 
const std::string& jailI
 // user/doc/jailId
 const auto jailPath = Poco::Path(JAILED_DOCUMENT_ROOT, jailId);
 std::string jailRoot = getJailRoot();
-
-LOG_INF("jailPath: " << jailPath.toString() << ", jailRoot: " << jailRoot);
-
 if (LOOLWSD::NoCapsForKit)
+{
 jailRoot = jailPath.toString() + "/" + getJailRoot();
+}
+
+LOG_INF("jailPath: " << jailPath.toString() << ", jailRoot: " << jailRoot);
 
 if (_storage == nullptr)
 {
@@ -206,80 +210,83 @@ bool DocumentBroker::load(const std::string& sessionId, 
const std::string& jailI
 // different query params like access token etc.)
 LOG_DBG("Creating new storage instance for URI [" << 
uriPublic.toString() << "].");
 _storage = StorageBase::create(uriPublic, jailRoot, 
jailPath.toString());
-}
-
-if (_storage)
-{
-// Call the storage specific file info functions
-std::string userid, username;
-std::chrono::duration getInfoCallDuration;
-if (dynamic_cast(_storage.get()) != nullptr)
+if (_storage == nullptr)
 {
-const WopiStorage::WOPIFileInfo wopifileinfo = 
static_cast(_storage.get())->getWOPIFileInfo(uriPublic);
-userid = wopifileinfo._userid;
-username = wopifileinfo._username;
+// We should get an exception, not null.
+LOG_ERR("Failed to create Storage instance for [" << _docKey << "] 
in " << jailPath.toString());
+return false;
+}
+}
 
-if (!wopifileinfo._userCanWrite)
-{
-LOG_DBG("Setting the session as readonly");
-it->second->setReadOnly();
-}
+assert(_storage != nullptr);
 
-if (!wopifileinfo._postMessageOrigin.empty())
-{
-it->second->sendTextFrame("wopi: postmessageorigin " + 
wopifileinfo._postMessageOrigin);
-}
+// Call the storage specific file info functions
+std::string userid, username;
+std::chrono::duration getInfoCallDuration;
+if (dynamic_cast(_storage.get()) != nullptr)
+{
+const WopiStorage::WOPIFileInfo wopifileinfo = 
static_cast(_storage.get())->getWOPIFileInfo(uriPublic);
+userid = wopifileinfo._userid;
+username = wopifileinfo._username;
 
-getInfoCallDuration = wopifileinfo._callDuration;
-}
-else if (dynamic_cast(_storage.get()) != nullptr)
+if (!wopifileinfo._userCanWrite)
 {
-const LocalStorage::LocalFileInfo localfileinfo = 
static_cast(_storage.get())->getLocalFileInfo(uriPublic);
-userid = localfileinfo._userid;
-username = localfileinfo._username;
+LOG_DBG("Setting the session as readonly");
+it->second->setReadOnly();
 }
 
-LOG_DBG("Setting username [" << username << "] and userId [" << userid 
<< "] for session [" << sessionId << "]");
-it->second->setUserId(userid);
-it->second->setUserName(username);
-
-// Get basic file information from the storage
-const auto fileInfo = _storage->getFileInfo();
-if (!fileInfo.isValid())
+if (!wopifileinfo._postMessageOrigin.empty())
 {
-LOG_ERR("Invalid fileinfo for URI [" << uriPublic.toString() << 
"].");
-return false;
+it->second->sendTextFrame("wopi: postmessageorigin " + 

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

2016-11-06 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   21 ++---
 loolwsd/DocumentBroker.hpp |2 --
 2 files changed, 2 insertions(+), 21 deletions(-)

New commits:
commit 11a0d016cabf13b990f975af8d06b44ca15cd8bf
Author: Ashod Nakashian 
Date:   Sun Nov 6 21:55:37 2016 -0500

loolwsd: inline and simplify connectPeers

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 1462d3c..cbc710c 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -509,29 +509,12 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 auto prisonerSession = std::make_shared(id, 
shared_from_this());
 
 // Connect the prison session to the client.
-if (!connectPeers(prisonerSession))
-{
-LOG_WRN("Failed to connect " << session->getName() << " to its peer.");
-}
+session->setPeer(prisonerSession);
+prisonerSession->setPeer(session);
 
 return _sessions.size();
 }
 
-bool DocumentBroker::connectPeers(std::shared_ptr& session)
-{
-const auto id = session->getId();
-
-auto it = _sessions.find(id);
-if (it != _sessions.end())
-{
-it->second->setPeer(session);
-session->setPeer(it->second);
-return true;
-}
-
-return false;
-}
-
 size_t DocumentBroker::removeSession(const std::string& id)
 {
 Util::assertIsLocked(_mutex);
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 73b1697..fdb7fac 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -221,8 +221,6 @@ public:
 
 /// Add a new session. Returns the new number of sessions.
 size_t addSession(std::shared_ptr& session);
-/// Connect a prison session to its client peer.
-bool connectPeers(std::shared_ptr& session);
 /// Removes a session by ID. Returns the new number of sessions.
 size_t removeSession(const std::string& id);
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-06 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |  127 +
 loolwsd/DocumentBroker.hpp |   16 ++---
 2 files changed, 58 insertions(+), 85 deletions(-)

New commits:
commit 9bb6d73fdad7b16382a4cf03d6c826e1810cff19
Author: Ashod Nakashian 
Date:   Sun Nov 6 11:59:59 2016 -0500

loolwsd: DocumentBroker logs updated

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 507362c..cf66a4a 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -115,29 +115,6 @@ std::string DocumentBroker::getDocKey(const Poco::URI& uri)
 return docKey;
 }
 
-DocumentBroker::DocumentBroker() :
-_uriPublic(),
-_docKey(),
-_childRoot(),
-_cacheRoot(),
-_childProcess(),
-_lastSaveTime(std::chrono::steady_clock::now()),
-_markToDestroy(true),
-_lastEditableSession(true),
-_isLoaded(false),
-_isModified(false),
-_cursorPosX(0),
-_cursorPosY(0),
-_cursorWidth(0),
-_cursorHeight(0),
-_mutex(),
-_saveMutex(),
-_tileVersion(0),
-_debugRenderedTileCount(0)
-{
-Log::info("Empty DocumentBroker (marked to destroy) created.");
-}
-
 DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
const std::string& docKey,
const std::string& childRoot,
@@ -164,8 +141,7 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 assert(!_docKey.empty());
 assert(!_childRoot.empty());
 
-LOG_INF("DocumentBroker [" << _uriPublic.toString() <<
-"] created. DocKey: [" << _docKey << "]");
+LOG_INF("DocumentBroker [" << _uriPublic.toString() << "] created. DocKey: 
[" << _docKey << "]");
 }
 
 DocumentBroker::~DocumentBroker()
@@ -173,8 +149,7 @@ DocumentBroker::~DocumentBroker()
 Admin::instance().rmDoc(_docKey);
 
 LOG_INF("~DocumentBroker [" << _uriPublic.toString() <<
-"] destroyed with " << _sessions.size() <<
-" sessions left.");
+"] destroyed with " << _sessions.size() << " sessions left.");
 
 if (!_sessions.empty())
 {
@@ -203,12 +178,12 @@ bool DocumentBroker::load(const std::string& sessionId, 
const std::string& jailI
 auto it = _sessions.find(sessionId);
 if (it == _sessions.end())
 {
-Log::error("Session with sessionId [" + sessionId + "] not found while 
loading");
+LOG_ERR("Session with sessionId [" << sessionId << "] not found while 
loading");
 return false;
 }
 
 const Poco::URI& uriPublic = it->second->getPublicUri();
-Log::debug("Loading from URI: " + uriPublic.toString());
+LOG_DBG("Loading from URI: " << uriPublic.toString());
 
 _jailId = jailId;
 
@@ -219,7 +194,7 @@ bool DocumentBroker::load(const std::string& sessionId, 
const std::string& jailI
 const auto jailPath = Poco::Path(JAILED_DOCUMENT_ROOT, jailId);
 std::string jailRoot = getJailRoot();
 
-Log::info("jailPath: " + jailPath.toString() + ", jailRoot: " + jailRoot);
+LOG_INF("jailPath: " << jailPath.toString() << ", jailRoot: " << jailRoot);
 
 if (LOOLWSD::NoCapsForKit)
 jailRoot = jailPath.toString() + "/" + getJailRoot();
@@ -229,7 +204,7 @@ bool DocumentBroker::load(const std::string& sessionId, 
const std::string& jailI
 // TODO: Maybe better to pass docKey to storage here instead of 
uriPublic here because
 // uriPublic would be different for each view of the document (due to
 // different query params like access token etc.)
-Log::debug("Creating new storage instance for URI [" + 
uriPublic.toString() + "].");
+LOG_DBG("Creating new storage instance for URI [" << 
uriPublic.toString() << "].");
 _storage = StorageBase::create(uriPublic, jailRoot, 
jailPath.toString());
 }
 
@@ -246,7 +221,7 @@ bool DocumentBroker::load(const std::string& sessionId, 
const std::string& jailI
 
 if (!wopifileinfo._userCanWrite)
 {
-Log::debug("Setting the session as readonly");
+LOG_DBG("Setting the session as readonly");
 it->second->setReadOnly();
 }
 
@@ -264,7 +239,7 @@ bool DocumentBroker::load(const std::string& sessionId, 
const std::string& jailI
 username = localfileinfo._username;
 }
 
-Log::debug("Setting username [" + username + "] and userId [" + userid 
+ "] for session [" + sessionId + "]");
+LOG_DBG("Setting username [" << username << "] and userId [" << userid 
<< "] for session [" << sessionId << "]");
 it->second->setUserId(userid);
 it->second->setUserName(username);
 
@@ -272,7 +247,7 @@ bool DocumentBroker::load(const std::string& sessionId, 
const 

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

2016-11-06 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |9 +-
 loolwsd/DocumentBroker.hpp |6 +
 loolwsd/LOOLWSD.cpp|  147 ++---
 3 files changed, 81 insertions(+), 81 deletions(-)

New commits:
commit 3993757ee806d7bdde2408852f6227b8f848f1d8
Author: Ashod Nakashian 
Date:   Sat Nov 5 22:15:44 2016 -0400

loolwsd: fix race while creating new documents

This fixes the race rather than trying to patch it.
It still minimizes the locking necessary to a minimum
to maximize parallelism.

The approach is to have at least the DocBrokers lock
or the DocumentBroker lock (if we already have a doc)
while creating new document views.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 97e21b4..19dbb97 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -358,9 +358,10 @@ bool DocumentBroker::save(const std::string& sessionId, 
bool success, const std:
 return false;
 }
 
-bool DocumentBroker::autoSave(const bool force, const size_t waitTimeoutMs)
+bool DocumentBroker::autoSave(const bool force, const size_t waitTimeoutMs, 
std::unique_lock& lock)
 {
-std::unique_lock lock(_mutex);
+Util::assertIsLocked(lock);
+
 if (_sessions.empty() || _storage == nullptr || !_isLoaded ||
 !_childProcess->isAlive() || (!_isModified && !force))
 {
@@ -549,7 +550,7 @@ bool 
DocumentBroker::connectPeers(std::shared_ptr& session)
 
 size_t DocumentBroker::removeSession(const std::string& id)
 {
-std::lock_guard lock(_mutex);
+Util::assertIsLocked(_mutex);
 
 auto it = _sessions.find(id);
 if (it != _sessions.end())
@@ -804,7 +805,7 @@ void DocumentBroker::handleTileCombinedResponse(const 
std::vector& payload
 
 bool DocumentBroker::startDestroy(const std::string& id)
 {
-std::unique_lock lock(_mutex);
+Util::assertIsLocked(_mutex);
 
 const auto currentSession = _sessions.find(id);
 assert(currentSession != _sessions.end());
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 17de968..e58b642 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -195,7 +195,7 @@ public:
 /// complete before returning, or timeout.
 /// @return true if attempts to save or it also waits
 /// and receives save notification. Otherwise, false.
-bool autoSave(const bool force, const size_t waitTimeoutMs);
+bool autoSave(const bool force, const size_t waitTimeoutMs, 
std::unique_lock& lock);
 
 Poco::URI getPublicUri() const { return _uriPublic; }
 Poco::URI getJailedUri() const { return _uriJailed; }
@@ -206,7 +206,7 @@ public:
 bool isAlive() const { return _childProcess && _childProcess->isAlive(); }
 size_t getSessionsCount() const
 {
-std::lock_guard lock(_mutex);
+Util::assertIsLocked(_mutex);
 return _sessions.size();
 }
 
@@ -273,6 +273,8 @@ public:
 /// Get the PID of the associated child process
 Poco::Process::PID getPid() const { return _childProcess->getPid(); }
 
+std::unique_lock getLock() { return 
std::unique_lock(_mutex); }
+
 private:
 /// Sends the .uno:Save command to LoKit.
 bool sendUnoSave(const bool dontSaveIfUnmodified);
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 9b91e1c..7ec35a1 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -271,6 +271,8 @@ static void forkChildren(const int number)
 /// Returns true if removed at least one.
 static bool cleanupChildren()
 {
+Util::assertIsLocked(NewChildrenMutex);
+
 bool removed = false;
 for (int i = NewChildren.size() - 1; i >= 0; --i)
 {
@@ -558,6 +560,7 @@ private:
 }
 
 docBrokersLock.lock();
+auto docLock = docBroker->getLock();
 sessionsCount = docBroker->removeSession(id);
 if (sessionsCount == 0)
 {
@@ -723,93 +726,92 @@ private:
 cleanupDocBrokers();
 
 // Lookup this document.
-auto it = DocBrokers.find(docKey);
-if (it != DocBrokers.end())
+auto it = DocBrokers.lower_bound(docKey);
+if (it != DocBrokers.end() && it->first == docKey)
 {
 // Get the DocumentBroker from the Cache.
 Log::debug("Found DocumentBroker for docKey [" + docKey + "].");
 docBroker = it->second;
 assert(docBroker);
-}
-else
-{
-// New Document.
-#if MAX_DOCUMENTS > 0
-if (DocBrokers.size() + 1 > MAX_DOCUMENTS)
-{
-Log::error() << "Limit on maximum number of open documents of "
- << MAX_DOCUMENTS 

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

2016-11-06 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   23 +++
 loolwsd/DocumentBroker.hpp |7 +++
 loolwsd/LOOLWSD.cpp|   25 ++---
 3 files changed, 48 insertions(+), 7 deletions(-)

New commits:
commit 800e711321e19b02f5e15f496525d42edcba4376
Author: Ashod Nakashian 
Date:   Sat Nov 5 23:00:16 2016 -0400

loolwsd: proper ChildProcess cleanup

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 19dbb97..507362c 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -180,6 +180,10 @@ DocumentBroker::~DocumentBroker()
 {
 LOG_WRN("DocumentBroker still has unremoved sessions.");
 }
+
+// Need to first make sure the child exited, socket closed,
+// and thread finished before we are destroyed.
+_childProcess.reset();
 }
 
 bool DocumentBroker::load(const std::string& sessionId, const std::string& 
jailId)
@@ -922,4 +926,23 @@ void DocumentBroker::childSocketTerminated()
 }
 }
 
+void DocumentBroker::terminateChild(std::unique_lock& lock)
+{
+Util::assertIsLocked(_mutex);
+Util::assertIsLocked(lock);
+
+Log::info() << "Terminating child [" << getPid() << "] of doc [" << 
_docKey << "]." << Log::end;
+
+assert(_sessions.empty() && "DocumentBroker still has unremoved 
sessions!");
+
+// First flag to stop as it might be waiting on our lock
+// to process some incoming message.
+_childProcess->stop();
+
+// Release the lock and wait for the thread to finish.
+lock.unlock();
+
+_childProcess->close(false);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index e58b642..0075fb6 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -270,6 +270,13 @@ public:
 /// or upon failing to process an incoming message.
 void childSocketTerminated();
 
+/// This gracefully terminates the connection
+/// with the child and cleans up ChildProcess etc.
+/// We must be called under lock and it must be
+/// passed to us so we unlock before waiting on
+/// the ChildProcess thread, which can take our lock.
+void terminateChild(std::unique_lock& lock);
+
 /// Get the PID of the associated child process
 Poco::Process::PID getPid() const { return _childProcess->getPid(); }
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 7ec35a1..ed5810a 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -565,11 +565,9 @@ private:
 if (sessionsCount == 0)
 {
 // At this point we're done.
-// We can't save if we hadn't, just kill.
-Log::debug("Closing child for docKey [" + docKey + 
"].");
-child->close(true);
-Log::debug("Removing DocumentBroker for docKey [" + 
docKey + "].");
+LOG_DBG("Removing DocumentBroker for docKey [" << 
docKey << "].");
 DocBrokers.erase(docKey);
+docBroker->terminateChild(docLock);
 }
 else
 {
@@ -928,9 +926,22 @@ private:
 
 if (sessionsCount == 0)
 {
-std::unique_lock DocBrokersLock(DocBrokersMutex);
-Log::debug("Removing DocumentBroker for docKey [" + docKey + 
"].");
-DocBrokers.erase(docKey);
+// We've supposedly destroyed the last session and can do away 
with
+// DocBroker. But first we need to take both locks in the 
correct
+// order and check again. We can't take the DocBrokersMutex 
while
+// holding the docBroker lock as that can deadlock with 
autoSave below.
+std::unique_lock docBrokersLock2(DocBrokersMutex);
+it = DocBrokers.find(docKey);
+if (it != DocBrokers.end() && it->second)
+{
+auto lock = it->second->getLock();
+if (it->second->getSessionsCount() == 0)
+{
+Log::info("Removing DocumentBroker for docKey [" + 
docKey + "].");
+DocBrokers.erase(docKey);
+docBroker->terminateChild(lock);
+}
+}
 }
 
 LOOLWSD::dumpEventTrace(docBroker->getJailId(), id, "EndSession: " 
+ uri);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-06 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

New commits:
commit 8b9372d51728b373512c9c05b8b77481581c4d47
Author: Ashod Nakashian 
Date:   Sat Nov 5 17:48:15 2016 -0400

loolwsd: improved ChildProcess message handling logs

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 5d187b8..97e21b4 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -37,6 +37,10 @@ void ChildProcess::socketProcessor()
 IoUtil::SocketProcessor(_ws,
 [this](const std::vector& payload)
 {
+const auto message = LOOLProtocol::getAbbreviatedMessage(payload);
+LOG_WRN("Recv from child " << this->_pid <<
+": [" << message << "].");
+
 if (UnitWSD::get().filterChildMessage(payload))
 {
 return true;
@@ -48,14 +52,14 @@ void ChildProcess::socketProcessor()
 return docBroker->handleInput(payload);
 }
 
-Log::warn() << "Child " << this->_pid << " has no DocumentBroker 
to handle message: ["
-<< LOOLProtocol::getAbbreviatedMessage(payload) << 
"]." << Log::end;
+LOG_WRN("Child " << this->_pid <<
+" has no DocumentBroker to handle message: [" << message 
<< "].");
 return true;
 },
 []() { },
 [this]() { return TerminationFlag || this->_stop; });
 
-Log::debug() << "Child [" << getPid() << "] WS terminated. Notifying 
DocBroker." << Log::end;
+LOG_DBG("Child [" << getPid() << "] WS terminated. Notifying DocBroker.");
 
 
 // Notify the broker that we're done.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-03 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |9 +
 loolwsd/LOOLKit.cpp|9 +
 2 files changed, 10 insertions(+), 8 deletions(-)

New commits:
commit d17d148880a4fc4f491b979a2207a05fca18ba8b
Author: Ashod Nakashian 
Date:   Fri Nov 4 00:50:51 2016 -0400

loolwsd: logging improvements

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index cbca3cd..754b836 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -160,16 +160,17 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 assert(!_docKey.empty());
 assert(!_childRoot.empty());
 
-Log::info("DocumentBroker [" + _uriPublic.toString() + "] created. DocKey: 
[" + _docKey + "]");
+LOG_INF("DocumentBroker [" << _uriPublic.toString() <<
+"] created. DocKey: [" << _docKey << "]");
 }
 
 DocumentBroker::~DocumentBroker()
 {
 Admin::instance().rmDoc(_docKey);
 
-Log::info() << "~DocumentBroker [" << _uriPublic.toString()
-<< "] destroyed with " << _sessions.size()
-<< " sessions left." << Log::end;
+LOG_INF("~DocumentBroker [" << _uriPublic.toString() <<
+"] destroyed with " << _sessions.size() <<
+" sessions left.");
 
 if (!_sessions.empty())
 {
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index c257e0b..cadd10d 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -789,7 +789,7 @@ private:
 }
 catch (const std::exception& exc)
 {
-Log::error("Exception while loading [" + uri + "] : " + 
exc.what());
+LOG_ERR("Exception while loading [" << uri << "] : " << 
exc.what());
 return nullptr;
 }
 
@@ -806,13 +806,13 @@ private:
 void onUnload(const ChildSession& session) override
 {
 const auto& sessionId = session.getId();
-Log::info("Unloading [" + sessionId + "].");
+LOG_INF("Unloading session [" << sessionId << "] on url [" << _url << 
"].");
 
 _tileQueue->removeCursorPosition(session.getViewId());
 
 if (_loKitDocument == nullptr)
 {
-Log::error("Unloading session [" + sessionId + "] without 
loKitDocument.");
+LOG_ERR("Unloading session [" << sessionId << "] without 
loKitDocument.");
 return;
 }
 
@@ -829,7 +829,8 @@ private:
 _loKitDocument->registerCallback(nullptr, nullptr);
 _loKitDocument->destroyView(viewId);
 _viewIdToCallbackDescr.erase(viewId);
-Log::debug("Destroyed view " + std::to_string(viewId));
+LOG_DBG("Destroyed view [" << viewId << "] with session [" <<
+sessionId << "] on url [" << _url << "].");
 
 // Get the list of view ids from the core
 const int viewCount = _loKitDocument->getViewsCount();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-03 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |4 +---
 loolwsd/DocumentBroker.hpp |1 +
 2 files changed, 2 insertions(+), 3 deletions(-)

New commits:
commit 61488cce78baa188e7f53bad352b1d80dcd7be7a
Author: Ashod Nakashian 
Date:   Fri Nov 4 00:13:47 2016 -0400

loolwsd: move child communication logging

...and simplify the message (new line not needed).

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index d19bfdd..cbca3cd 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -469,14 +469,13 @@ std::string DocumentBroker::getJailRoot() const
 size_t DocumentBroker::addSession(std::shared_ptr& session)
 {
 const auto id = session->getId();
-const std::string aMessage = "session " + id + " " + _docKey + "\n";
+const std::string aMessage = "session " + id + " " + _docKey;
 
 try
 {
 std::lock_guard lock(_mutex);
 
 // Request a new session from the child kit.
-Log::debug("DocBroker to Child: " + aMessage.substr(0, 
aMessage.length() - 1));
 _childProcess->sendTextFrame(aMessage);
 
 auto ret = _sessions.emplace(id, session);
@@ -840,7 +839,6 @@ bool DocumentBroker::forwardToChild(const std::string& 
viewId, const std::string
 if (it != _sessions.end())
 {
 const auto msg = "child-" + viewId + ' ' + message;
-Log::debug("DocBroker to Child: " + msg);
 _childProcess->sendTextFrame(msg);
 return true;
 }
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index c1d0936..17de968 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -108,6 +108,7 @@ public:
 {
 try
 {
+LOG_TRC("DocBroker to Child: " << data);
 _ws->sendFrame(data.data(), data.size());
 return true;
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-03 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

New commits:
commit 84fb2d43fbc60c19935a6220c3ce615a7f742950
Author: Ashod Nakashian 
Date:   Thu Nov 3 23:05:48 2016 -0400

loolwsd: warn if sessions remain by ~DocumentBroker

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index a332af6..d19bfdd 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -171,7 +171,10 @@ DocumentBroker::~DocumentBroker()
 << "] destroyed with " << _sessions.size()
 << " sessions left." << Log::end;
 
-//assert(_sessions.empty());
+if (!_sessions.empty())
+{
+LOG_WRN("DocumentBroker still has unremoved sessions.");
+}
 }
 
 bool DocumentBroker::load(const std::string& sessionId, const std::string& 
jailId)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-02 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   19 ---
 1 file changed, 16 insertions(+), 3 deletions(-)

New commits:
commit 05d4234208df0777ea8d8da9dceda200222d5a58
Author: Ashod Nakashian 
Date:   Mon Oct 31 21:25:19 2016 -0400

loolwsd: more efficient client message forwarding

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 5f417f1..a332af6 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -851,8 +851,21 @@ bool DocumentBroker::forwardToChild(const std::string& 
viewId, const std::string
 
 bool DocumentBroker::forwardToClient(const std::string& prefix, const 
std::vector& payload)
 {
-std::string message(payload.data() + prefix.size(), payload.size() - 
prefix.size());
-Util::ltrim(message);
+assert(payload.size() > prefix.size());
+
+// Remove the prefix and trim.
+size_t index = prefix.size();
+for ( ; index < payload.size(); ++index)
+{
+if (payload[index] != ' ')
+{
+break;
+}
+}
+
+auto data = payload.data() + index;
+auto size = payload.size() - index;
+const auto message = getAbbreviatedMessage(data, size);
 Log::trace("Forwarding payload to " + prefix + ' ' + message);
 
 std::string name;
@@ -865,7 +878,7 @@ bool DocumentBroker::forwardToClient(const std::string& 
prefix, const std::vecto
 const auto peer = it->second->getPeer();
 if (peer)
 {
-return peer->handleInput(message.data(), message.size());
+return peer->handleInput(data, size);
 }
 else
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-01 Thread Michael Meeks
 loolwsd/DocumentBroker.cpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit e48f9d7557a2e4153df039706516a751a4a55d8b
Author: Michael Meeks 
Date:   Wed Nov 2 01:23:00 2016 +

loolwsd: remove assertion that sessions are cleaned up nicely.

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 728f5fb..5f417f1 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -171,7 +171,7 @@ DocumentBroker::~DocumentBroker()
 << "] destroyed with " << _sessions.size()
 << " sessions left." << Log::end;
 
-assert(_sessions.empty());
+//assert(_sessions.empty());
 }
 
 bool DocumentBroker::load(const std::string& sessionId, const std::string& 
jailId)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-01 Thread Michael Meeks
 loolwsd/DocumentBroker.cpp |2 ++
 1 file changed, 2 insertions(+)

New commits:
commit 2b9ae4b263c90f814c608e79c92cdb599d440a98
Author: Michael Meeks 
Date:   Tue Nov 1 23:38:25 2016 +

DocumentBroker - hold mutex while iterating over _sessions.

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index eda6eeb..728f5fb 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -887,6 +887,8 @@ bool DocumentBroker::forwardToClient(const std::string& 
prefix, const std::vecto
 
 void DocumentBroker::childSocketTerminated()
 {
+std::lock_guard lock(_mutex);
+
 if (!_childProcess->isAlive())
 {
 Log::error("Child for doc [" + _docKey + "] terminated prematurely.");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-10-31 Thread Tor Lillqvist
 loolwsd/DocumentBroker.cpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit be22779c21fad4502b7b2ee5d624478a7ff3b66b
Author: Tor Lillqvist 
Date:   Mon Oct 31 17:45:14 2016 +0200

Assertion failures are for developers to read

'_sessions.empty()' does not need a verbal explanation. We don't do
those in other assertions in the same file anyway.

(Also, I dislike the use of exclamation marks, especially in contexts
that by themselves already are alerts, like in assertion failure
messages. Exposure to LibreOffice source code with its style (in some
neighbourhoods) of multiple exclamation marks, even, in comments,
makes you like that. Exclamation marks makes your comments or messages
look like check-out tabloid headlines.)

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 7516cc5..eda6eeb 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -171,7 +171,7 @@ DocumentBroker::~DocumentBroker()
 << "] destroyed with " << _sessions.size()
 << " sessions left." << Log::end;
 
-assert(_sessions.empty() && "DocumentBroker still has unremoved 
sessions!");
+assert(_sessions.empty());
 }
 
 bool DocumentBroker::load(const std::string& sessionId, const std::string& 
jailId)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-10-31 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   29 ++---
 loolwsd/TileCache.cpp  |8 
 2 files changed, 14 insertions(+), 23 deletions(-)

New commits:
commit c8eb2ba6127f9d3da56811c25860c89ce085f588
Author: Ashod Nakashian 
Date:   Sun Oct 30 15:24:27 2016 -0400

loolwsd: cleanup tile response handling

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 185d610..7516cc5 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -740,29 +740,27 @@ void DocumentBroker::cancelTileRequests(const 
std::shared_ptr& se
 void DocumentBroker::handleTileResponse(const std::vector& payload)
 {
 const std::string firstLine = getFirstLine(payload);
+Log::debug("Handling tile combined: " + firstLine);
+
 try
 {
-auto tile = TileDesc::parse(firstLine);
-const auto buffer = payload.data();
 const auto length = payload.size();
-
 if (firstLine.size() < static_cast(length) - 1)
 {
+const auto tile = TileDesc::parse(firstLine);
+const auto buffer = payload.data();
 const auto offset = firstLine.size() + 1;
 tileCache().saveTileAndNotify(tile, buffer + offset, length - 
offset);
 }
 else
 {
 Log::debug() << "Render request declined for " << firstLine << 
Log::end;
-std::unique_lock 
tileBeingRenderedLock(tileCache().getTilesBeingRenderedLock());
-tileCache().forgetTileBeingRendered(tile);
+// They will get re-issued if we don't forget them.
 }
 }
 catch (const std::exception& exc)
 {
 Log::error("Failed to process tile response [" + firstLine + "]: " + 
exc.what() + ".");
-//FIXME: Return error.
-//sendTextFrame("error: cmd=tile kind=syntax");
 }
 }
 
@@ -773,13 +771,12 @@ void DocumentBroker::handleTileCombinedResponse(const 
std::vector& payload
 
 try
 {
-auto tileCombined = TileCombined::parse(firstLine);
-const auto buffer = payload.data();
 const auto length = payload.size();
-auto offset = firstLine.size() + 1;
-
 if (firstLine.size() < static_cast(length) - 1)
 {
+const auto tileCombined = TileCombined::parse(firstLine);
+const auto buffer = payload.data();
+auto offset = firstLine.size() + 1;
 for (const auto& tile : tileCombined.getTiles())
 {
 tileCache().saveTileAndNotify(tile, buffer + offset, 
tile.getImgSize());
@@ -788,19 +785,13 @@ void DocumentBroker::handleTileCombinedResponse(const 
std::vector& payload
 }
 else
 {
-Log::error() << "Render request failed for " << firstLine << 
Log::end;
-std::unique_lock 
tileBeingRenderedLock(tileCache().getTilesBeingRenderedLock());
-for (const auto& tile : tileCombined.getTiles())
-{
-tileCache().forgetTileBeingRendered(tile);
-}
+Log::error() << "Render request declined for " << firstLine << 
Log::end;
+// They will get re-issued if we don't forget them.
 }
 }
 catch (const std::exception& exc)
 {
 Log::error("Failed to process tile response [" + firstLine + "]: " + 
exc.what() + ".");
-//FIXME: Return error.
-//sendTextFrame("error: cmd=tile kind=syntax");
 }
 }
 
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index e8ebdd1..d26db3b 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -444,14 +444,14 @@ void TileCache::subscribeToTileRendering(const TileDesc& 
tile, const std::shared
 {
 assert(subscriber->getKind() == LOOLSession::Kind::ToClient);
 
-std::unique_lock lock(_tilesBeingRenderedMutex);
-
-std::shared_ptr tileBeingRendered = 
findTileBeingRendered(tile);
-
 std::ostringstream oss;
 oss << '(' << tile.getPart() << ',' << tile.getTilePosX() << ',' << 
tile.getTilePosY() << ')';
 const auto name = oss.str();
 
+std::unique_lock lock(_tilesBeingRenderedMutex);
+
+std::shared_ptr tileBeingRendered = 
findTileBeingRendered(tile);
+
 if (tileBeingRendered)
 {
 for (const auto  : tileBeingRendered->_subscribers)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-10-23 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |3 ++-
 loolwsd/DocumentBroker.hpp |   16 ++--
 2 files changed, 12 insertions(+), 7 deletions(-)

New commits:
commit f0c3365f9f0ea454eccb9d26fd5ffcbdec3b2a19
Author: Ashod Nakashian 
Date:   Sat Oct 22 19:10:07 2016 -0400

loolwsd: improve ChildProcess cleanup

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index e64dfff..850d570 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -60,8 +60,9 @@ void ChildProcess::socketProcessor()
 
 // Notify the broker that we're done.
 auto docBroker = _docBroker.lock();
-if (docBroker)
+if (docBroker && !_stop)
 {
+// No need to notify if asked to stop.
 docBroker->childSocketTerminated();
 }
 }
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 170613c..39bc19a 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -55,11 +55,8 @@ public:
 
 ~ChildProcess()
 {
-if (_pid > 0)
-{
-Log::info("~ChildProcess dtor [" + std::to_string(_pid) + "].");
-close(false);
-}
+Log::debug("~ChildProcess dtor [" + std::to_string(_pid) + "].");
+close(true);
 }
 
 void setDocumentBroker(const std::shared_ptr& docBroker)
@@ -68,11 +65,18 @@ public:
 _docBroker = docBroker;
 }
 
+void stop()
+{
+Log::debug("Stopping ChildProcess [" + std::to_string(_pid) + "]");
+_stop = true;
+}
+
 void close(const bool rude)
 {
 try
 {
-_stop = true;
+Log::debug("Closing ChildProcess [" + std::to_string(_pid) + "].");
+stop();
 IoUtil::shutdownWebSocket(_ws);
 if (_thread.joinable())
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/Util.hpp

2016-10-23 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |1 -
 loolwsd/Util.hpp   |7 ---
 2 files changed, 8 deletions(-)

New commits:
commit 47ed5e40dd743ded1bbe2ec66f4aa1e0885b9e5c
Author: Ashod Nakashian 
Date:   Sat Oct 22 19:02:01 2016 -0400

loolwsd: kill assertIsNotLocked

It was intended to assert that the *same* thread
hadn't locked, not any. As it stands, it's problematic
and was decided to let go.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index ca10d50..e64dfff 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -525,7 +525,6 @@ size_t DocumentBroker::removeSession(const std::string& id)
 
 void DocumentBroker::alertAllUsersOfDocument(const std::string& cmd, const 
std::string& kind)
 {
-Util::assertIsNotLocked(_mutex);
 std::lock_guard lock(_mutex);
 
 std::stringstream ss;
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index 21ef610..40f0793 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -106,13 +106,6 @@ namespace Util
 assert(!mtx.try_lock());
 }
 
-inline
-void assertIsNotLocked(std::mutex& mtx)
-{
-assert(mtx.try_lock());
-mtx.unlock();
-}
-
 /// Safely remove a file or directory.
 /// Supresses exception when the file is already removed.
 /// This can happen when there is a race (unavoidable) or when
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-10-23 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

New commits:
commit 167f0bf70cc73a8b3b264d0f96734403b1268cee
Author: Ashod Nakashian 
Date:   Thu Oct 20 19:06:00 2016 -0400

loolwsd: throw an exception rather than rethrow nothing

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index f45e28a..61c1fc5 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -449,8 +449,9 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 loaded = load(id, std::to_string(_childProcess->getPid()));
 if (!loaded)
 {
-Log::error("Error loading document with URI [" + 
session->getPublicUri().toString() + "].");
-throw;
+const auto msg = "Failed to load document with URI [" + 
session->getPublicUri().toString() + "].";
+Log::error(msg);
+throw std::runtime_error(msg);
 }
 }
 catch (const StorageSpaceLowException&)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-10-20 Thread Andras Timar
 loolwsd/DocumentBroker.cpp |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

New commits:
commit 0cdc9d70b501749de5d836b7043f5617583d105f
Author: Andras Timar 
Date:   Thu Oct 20 11:03:24 2016 +0200

loolwsd: fix error: declaration of ‘isLoaded’ shadows a member of 
'this' [-Werror=shadow]

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 3960ef2..9ae52af 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -439,8 +439,8 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 _lastEditableSession = false;
 _markToDestroy = false;
 
-bool isLoaded = load(id, std::to_string(_childProcess->getPid()));
-if (!isLoaded)
+bool loaded = load(id, std::to_string(_childProcess->getPid()));
+if (!loaded)
 {
 Log::error("Error loading document with URI [" + 
session->getPublicUri().toString() + "].");
 throw;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/Util.hpp

2016-10-18 Thread Michael Meeks
 loolwsd/DocumentBroker.cpp |   39 ---
 loolwsd/Util.hpp   |7 +++
 2 files changed, 27 insertions(+), 19 deletions(-)

New commits:
commit 8d4c5d4e68eaf196a9e6c7478fbee15285beac04
Author: Michael Meeks 
Date:   Tue Oct 18 21:51:11 2016 +0100

Avoid deadlock when notifying users of document load failure.

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 624b2be..3adc1ad 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -410,30 +410,30 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 const auto id = session->getId();
 const std::string aMessage = "session " + id + " " + _docKey + "\n";
 
-std::lock_guard lock(_mutex);
+try
+{
+std::lock_guard lock(_mutex);
 
-// Request a new session from the child kit.
-Log::debug("DocBroker to Child: " + aMessage.substr(0, aMessage.length() - 
1));
-_childProcess->sendTextFrame(aMessage);
+// Request a new session from the child kit.
+Log::debug("DocBroker to Child: " + aMessage.substr(0, 
aMessage.length() - 1));
+_childProcess->sendTextFrame(aMessage);
 
-auto ret = _sessions.emplace(id, session);
-if (!ret.second)
-{
-Log::warn("DocumentBroker: Trying to add already existing session.");
-}
+auto ret = _sessions.emplace(id, session);
+if (!ret.second)
+{
+Log::warn("DocumentBroker: Trying to add already existing 
session.");
+}
 
-if (session->isReadOnly())
-{
-Log::debug("Adding a readonly session [" + id + "]");
-}
+if (session->isReadOnly())
+{
+Log::debug("Adding a readonly session [" + id + "]");
+}
 
-// Below values are recalculated when startDestroy() is called (before 
destroying the
-// document). It is safe to reset their values to their defaults whenever 
a new session is added.
-_lastEditableSession = false;
-_markToDestroy = false;
+// Below values are recalculated when startDestroy() is called (before 
destroying the
+// document). It is safe to reset their values to their defaults 
whenever a new session is added.
+_lastEditableSession = false;
+_markToDestroy = false;
 
-try
-{
 load(id, std::to_string(_childProcess->getPid()));
 }
 catch (const StorageSpaceLowException&)
@@ -491,6 +491,7 @@ size_t DocumentBroker::removeSession(const std::string& id)
 
 void DocumentBroker::alertAllUsersOfDocument(const std::string& cmd, const 
std::string& kind)
 {
+Util::assertIsNotLocked(_mutex);
 std::lock_guard lock(_mutex);
 
 std::stringstream ss;
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index a55c70e..d99fd36 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -106,6 +106,13 @@ namespace Util
 assert(!mtx.try_lock());
 }
 
+inline
+void assertIsNotLocked(std::mutex& mtx)
+{
+assert(mtx.try_lock());
+mtx.unlock();
+}
+
 /// Safely remove a file or directory.
 /// Supresses exception when the file is already removed.
 /// This can happen when there is a race (unavoidable) or when
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-10-16 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   27 ++-
 loolwsd/DocumentBroker.hpp |2 ++
 2 files changed, 28 insertions(+), 1 deletion(-)

New commits:
commit 4f4472ffa6e11bf8b77c8e64198c5e159dbd9daa
Author: Ashod Nakashian 
Date:   Sat Oct 15 17:07:40 2016 -0400

loolwsd: shutdown client sockets and cleanup when kit dies

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 0d36497..dceb1c5 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -53,6 +53,16 @@ void ChildProcess::socketProcessor()
 },
 []() { },
 [this]() { return TerminationFlag || this->_stop; });
+
+Log::debug() << "Child [" << getPid() << "] WS terminated. Notifying 
DocBroker." << Log::end;
+
+
+// Notify the broker that we're done.
+auto docBroker = _docBroker.lock();
+if (docBroker)
+{
+docBroker->childSocketTerminated();
+}
 }
 
 namespace
@@ -286,7 +296,7 @@ bool DocumentBroker::autoSave(const bool force, const 
size_t waitTimeoutMs)
 {
 std::unique_lock lock(_mutex);
 if (_sessions.empty() || _storage == nullptr || !_isLoaded ||
-(!_isModified && !force))
+!_childProcess->isAlive() || (!_isModified && !force))
 {
 // Nothing to do.
 Log::trace("Nothing to autosave [" + _docKey + "].");
@@ -824,4 +834,19 @@ const std::chrono::duration 
DocumentBroker::getStorageLoadDuration() con
 return std::chrono::duration::zero();
 }
 
+void DocumentBroker::childSocketTerminated()
+{
+if (!_childProcess->isAlive())
+{
+Log::error("Child for doc [" + _docKey + "] terminated prematurely.");
+}
+
+// We could restore the kit if this was unexpected.
+// For now, close the connections to cleanup.
+for (auto& pair : _sessions)
+{
+pair.second->shutdown(Poco::Net::WebSocket::WS_ENDPOINT_GOING_AWAY);
+}
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index d5e8b42..7972903 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -266,6 +266,8 @@ public:
 /// Currently, only makes sense in case storage is WOPI
 const std::chrono::duration getStorageLoadDuration() const;
 
+void childSocketTerminated();
+
 private:
 
 /// Sends the .uno:Save command to LoKit.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-10-16 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |4 ++--
 loolwsd/DocumentBroker.hpp |2 +-
 loolwsd/LOOLWSD.cpp|   10 --
 3 files changed, 7 insertions(+), 9 deletions(-)

New commits:
commit 7043b95f4d9a1d01043f6b519d5845a52375f1d2
Author: Ashod Nakashian 
Date:   Fri Oct 14 22:52:33 2016 -0400

loolwsd: fix convert-to after removing Prisoner WS

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index fd29bf5..77aa6ba 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -126,12 +126,12 @@ DocumentBroker::DocumentBroker() :
 DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
const std::string& docKey,
const std::string& childRoot,
-   std::shared_ptr childProcess) :
+   const std::shared_ptr& 
childProcess) :
 _uriPublic(uriPublic),
 _docKey(docKey),
 _childRoot(childRoot),
 _cacheRoot(getCachePath(uriPublic.toString())),
-_childProcess(std::move(childProcess)),
+_childProcess(childProcess),
 _lastSaveTime(std::chrono::steady_clock::now()),
 _markToDestroy(false),
 _lastEditableSession(false),
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 00d27e2..d5e8b42 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -171,7 +171,7 @@ public:
 DocumentBroker(const Poco::URI& uriPublic,
const std::string& docKey,
const std::string& childRoot,
-   std::shared_ptr childProcess);
+   const std::shared_ptr& childProcess);
 
 ~DocumentBroker()
 {
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 957749f..f709749 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -472,17 +472,11 @@ private:
 std::shared_ptr ws;
 auto session = std::make_shared(id, ws, 
docBroker, uriPublic);
 
-// Request the child to connect to us and add this session.
 auto sessionsCount = docBroker->addSession(session);
 Log::trace(docKey + ", ws_sessions++: " + 
std::to_string(sessionsCount));
 
 lock.unlock();
 
-// Wait until the client has connected with a prison 
socket.
-waitBridgeCompleted(session);
-// Now the bridge between the client and kit processes is 
connected
-// Let messages flow
-
 std::string encodedFrom;
 URI::encode(docBroker->getPublicUri().getPath(), "", 
encodedFrom);
 const std::string load = "load url=" + encodedFrom;
@@ -524,6 +518,10 @@ private:
 sessionsCount = docBroker->removeSession(id);
 if (sessionsCount == 0)
 {
+// At this point we're done.
+// We can't save if we hadn't, just kill.
+Log::debug("Closing child for docKey [" + docKey + 
"].");
+child->close(true);
 Log::debug("Removing DocumentBroker for docKey [" + 
docKey + "].");
 docBrokers.erase(docKey);
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-10-16 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   12 ++--
 loolwsd/DocumentBroker.hpp |   19 ++-
 2 files changed, 24 insertions(+), 7 deletions(-)

New commits:
commit 75c99ed9b6939f9ee0be68cec2d82572d63ac48c
Author: Ashod Nakashian 
Date:   Tue Oct 11 18:22:51 2016 -0400

loolwsd: cleanup child process WS interface

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index c562048..adadee2 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -405,7 +405,7 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 
 // Request a new session from the child kit.
 Log::debug("DocBroker to Child: " + aMessage.substr(0, aMessage.length() - 
1));
-_childProcess->getWebSocket()->sendFrame(aMessage.data(), aMessage.size());
+_childProcess->sendTextFrame(aMessage);
 
 auto ret = _sessions.emplace(id, session);
 if (!ret.second)
@@ -454,7 +454,7 @@ size_t DocumentBroker::removeSession(const std::string& id)
 
 // Let the child know the client has disconnected.
 const std::string msg("child-" + id + " disconnect");
-_childProcess->getWebSocket()->sendFrame(msg.data(), msg.size());
+_childProcess->sendTextFrame(msg);
 }
 
 return _sessions.size();
@@ -561,7 +561,7 @@ void DocumentBroker::handleTileRequest(TileDesc& tile,
 // Forward to child to render.
 Log::debug() << "Sending render request for tile (" << tile.getPart() << 
',' << tile.getTilePosX() << ',' << tile.getTilePosY() << ")." << Log::end;
 const std::string request = "tile " + tile.serialize();
-_childProcess->getWebSocket()->sendFrame(request.data(), request.size());
+_childProcess->sendTextFrame(request);
 _debugRenderedTileCount++;
 }
 
@@ -620,7 +620,7 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 // Forward to child to render.
 const auto req = newTileCombined.serialize("tilecombine");
 Log::debug() << "Sending residual tilecombine: " << req << Log::end;
-_childProcess->getWebSocket()->sendFrame(req.data(), req.size());
+_childProcess->sendTextFrame(req);
 }
 }
 
@@ -632,7 +632,7 @@ void DocumentBroker::cancelTileRequests(const 
std::shared_ptr& se
 if (!canceltiles.empty())
 {
 Log::debug() << "Forwarding canceltiles request: " << canceltiles << 
Log::end;
-_childProcess->getWebSocket()->sendFrame(canceltiles.data(), 
canceltiles.size());
+_childProcess->sendTextFrame(canceltiles);
 }
 }
 
@@ -748,7 +748,7 @@ bool DocumentBroker::forwardToChild(const std::string& 
viewId, const char *buffe
 {
 const auto msg = "child-" + viewId + ' ' + message;
 Log::debug("DocBroker to Child: " + msg);
-_childProcess->getWebSocket()->sendFrame(msg.data(), msg.size());
+_childProcess->sendTextFrame(msg);
 return true;
 }
 else
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index a1aa06d..5d0b414 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -87,7 +87,24 @@ public:
 }
 
 Poco::Process::PID getPid() const { return _pid; }
-std::shared_ptr getWebSocket() const { return _ws; }
+
+/// Send a text payload to the child-process WS.
+bool sendTextFrame(const std::string& data)
+{
+try
+{
+_ws->sendFrame(data.data(), data.size());
+return true;
+}
+catch (const std::exception& exc)
+{
+Log::error() << "Failed to send child [" << _pid << "] data ["
+ << data << "] due to: " << exc.what() << Log::end;
+throw;
+}
+
+return false;
+}
 
 /// Check whether this child is alive and able to respond.
 bool isAlive() const
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/LOOLKit.cpp loolwsd/protocol.txt

2016-10-10 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |4 
 loolwsd/LOOLKit.cpp|7 +++
 loolwsd/protocol.txt   |   18 ++
 3 files changed, 29 insertions(+)

New commits:
commit 4fa7e53eaeb43233ac039525b58eb8c588968019
Author: Ashod Nakashian 
Date:   Sun Oct 9 16:37:13 2016 -0400

loolwsd: unload child view when client disconnects

Using a new internal command, when a client disconnects
an internal 'disconnect' message is dispatched so
the child process cleans up the ChildSession in question.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 02686fa..4e7e618 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -441,6 +441,10 @@ size_t DocumentBroker::removeSession(const std::string& id)
 if (it != _sessions.end())
 {
 _sessions.erase(it);
+
+// Let the child know the client has disconnected.
+const std::string msg("child-" + id + " disconnect");
+_childProcess->getWebSocket()->sendFrame(msg.data(), msg.size());
 }
 
 return _sessions.size();
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 3bb689d..17f7f3f 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -1264,6 +1264,13 @@ private:
 const auto it = _connections.find(viewId);
 if (it != _connections.end())
 {
+if (message == "disconnect")
+{
+Log::debug("Removing ChildSession " + value);
+_connections.erase(it);
+return true;
+}
+
 auto session = it->second->getSession();
 if (session)
 {
diff --git a/loolwsd/protocol.txt b/loolwsd/protocol.txt
index 418986d..d617354 100644
--- a/loolwsd/protocol.txt
+++ b/loolwsd/protocol.txt
@@ -373,6 +373,24 @@ saveas: url=
  is a URL of the destination, encoded. Sent from the child to the
 parent after a saveAs() completed.
 
+client- 
+
+Forwarding message between a child and its parent session.
+The payload message is forwarded to the ClientSession.
+
+parent -> child
+===
+
+child- 
+
+Forwarding message between a parent and its child session.
+The payload message is forwarded to the ChildSession.
+
+disconnect
+
+Signals to the child that the client for the respective connection
+has disconnected.
+
 Admin console
 ===
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-10-10 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   38 +++---
 loolwsd/DocumentBroker.hpp |3 +++
 2 files changed, 38 insertions(+), 3 deletions(-)

New commits:
commit f17ff9c1d9d3081251f5341a5954161dd548f450
Author: Ashod Nakashian 
Date:   Sat Oct 8 13:13:23 2016 -0400

loolwsd: forward client messages to the respective client's WS

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 896e7e4..e8bab09 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -465,15 +465,20 @@ bool DocumentBroker::handleInput(const std::vector& 
payload)
 
 LOOLWSD::dumpOutgoingTrace(getJailId(), "0", msg);
 
-if (msg.find("tile:") == 0)
+const auto command = LOOLProtocol::getFirstToken(msg);
+if (command == "tile:")
 {
 handleTileResponse(payload);
 }
-else if (msg.find("tilecombine:") == 0)
+else if (command == "tilecombine:")
 {
handleTileCombinedResponse(payload);
 }
-else if (msg.find("errortoall:") == 0)
+else if (LOOLProtocol::getFirstToken(command, '-') == "client")
+{
+forwardToClient(command, payload);
+}
+else if (command == "errortoall:")
 {
 StringTokenizer tokens(msg, " ", StringTokenizer::TOK_IGNORE_EMPTY | 
StringTokenizer::TOK_TRIM);
 assert(tokens.count() == 3);
@@ -717,4 +722,31 @@ void DocumentBroker::setModified(const bool value)
 _isModified = value;
 }
 
+bool DocumentBroker::forwardToClient(const std::string& prefix, const 
std::vector& payload)
+{
+const std::string message(payload.data() + prefix.size(), payload.size() - 
prefix.size());
+Log::trace("Forwarding payload to client: " + message);
+
+std::string name;
+std::string sid;
+if (LOOLProtocol::parseNameValuePair(prefix, name, sid, '-') && name == 
"client")
+{
+const auto it = _sessions.find(sid);
+if (it != _sessions.end())
+{
+return it->second->sendTextFrame(message);
+}
+else
+{
+Log::warn() << "Client session [" << sid << "] not found to 
forward message: " << message << Log::end;
+}
+}
+else
+{
+Log::error("Failed to parse prefix of forward-to-client message: " + 
message);
+}
+
+return false;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 4909e34..80e93b2 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -238,6 +238,9 @@ private:
 /// Saves the document to Storage (assuming LO Core saved to local copy).
 bool saveToStorage();
 
+/// Forward a message from child process to a certain client.
+bool forwardToClient(const std::string& prefix, const std::vector& 
payload);
+
 private:
 const Poco::URI _uriPublic;
 const std::string _docKey;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-10-10 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   39 ---
 loolwsd/DocumentBroker.hpp |   16 +++-
 loolwsd/LOOLWSD.cpp|9 +
 3 files changed, 32 insertions(+), 32 deletions(-)

New commits:
commit 22fb71c6729cb9139714054bf7096619c3c0aa1e
Author: Ashod Nakashian 
Date:   Sat Oct 8 10:31:35 2016 -0400

loolwsd: cleanup lastEditableSession flag in DocumentBroker

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index d6aba21..896e7e4 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -109,12 +109,12 @@ DocumentBroker::DocumentBroker() :
 _lastSaveTime(std::chrono::steady_clock::now()),
 _markToDestroy(true),
 _lastEditableSession(true),
+_isLoaded(false),
+_isModified(false),
 _cursorPosX(0),
 _cursorPosY(0),
 _cursorWidth(0),
 _cursorHeight(0),
-_isLoaded(false),
-_isModified(false),
 _mutex(),
 _saveMutex(),
 _tileVersion(0)
@@ -134,12 +134,12 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 _lastSaveTime(std::chrono::steady_clock::now()),
 _markToDestroy(false),
 _lastEditableSession(false),
+_isLoaded(false),
+_isModified(false),
 _cursorPosX(0),
 _cursorPosY(0),
 _cursorWidth(0),
 _cursorHeight(0),
-_isLoaded(false),
-_isModified(false),
 _mutex(),
 _saveMutex(),
 _tileVersion(0)
@@ -244,7 +244,7 @@ bool DocumentBroker::save(bool success, const std::string& 
result)
 // If we aren't destroying the last editable session just yet, and the file
 // timestamp hasn't changed, skip saving.
 const auto newFileModifiedTime = 
Poco::File(_storage->getLocalRootPath()).getLastModified();
-if (!isLastEditableSession() && newFileModifiedTime == 
_lastFileModifiedTime)
+if (!_lastEditableSession && newFileModifiedTime == _lastFileModifiedTime)
 {
 // Nothing to do.
 Log::debug() << "Skipping unnecessary saving to URI [" << uri
@@ -409,7 +409,7 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 }
 
 // Below values are recalculated when startDestroy() is called (before 
destroying the
-// document). It is safe to reset their values to their defaults whenever 
a new session is added
+// document). It is safe to reset their values to their defaults whenever 
a new session is added.
 _lastEditableSession = false;
 _markToDestroy = false;
 
@@ -683,31 +683,32 @@ void DocumentBroker::handleTileCombinedResponse(const 
std::vector& payload
 }
 }
 
-void DocumentBroker::startDestroy(const std::string& id)
+bool DocumentBroker::startDestroy(const std::string& id)
 {
 std::unique_lock lock(_mutex);
 
-auto currentSession = _sessions.find(id);
+const auto currentSession = _sessions.find(id);
 assert(currentSession != _sessions.end());
 
-// Check if session which is being destroyed is last non-readonly session
-bool lastEditableSession = !currentSession->second->isReadOnly();
-for (auto& it: _sessions)
+// Check if the session being destroyed is the last non-readonly session 
or not.
+_lastEditableSession = !currentSession->second->isReadOnly();
+if (_lastEditableSession && !_sessions.empty())
 {
-if (it.second->getId() == id)
-continue;
-
-if (!it.second->isReadOnly())
+for (const auto& it: _sessions)
 {
-lastEditableSession = false;
+if (it.second->getId() != id &&
+!it.second->isReadOnly())
+{
+// Found another editable.
+_lastEditableSession = false;
+break;
+}
 }
 }
 
-// Last editable session going away
-_lastEditableSession = lastEditableSession;
-
 // Last view going away, can destroy.
 _markToDestroy = (_sessions.size() <= 1);
+return _lastEditableSession;
 }
 
 void DocumentBroker::setModified(const bool value)
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 16008f4..4909e34 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -217,18 +217,16 @@ public:
const std::shared_ptr& session);
 void handleTileCombinedRequest(TileCombined& tileCombined,
const std::shared_ptr& 
session);
-
 void cancelTileRequests(const std::shared_ptr& session);
-
 void handleTileResponse(const std::vector& payload);
 void handleTileCombinedResponse(const std::vector& payload);
 
-// Called before destroying any session
-// This method calculates and sets important states of
-// session being destroyed.
-void 

[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/PrisonerSession.cpp loolwsd/TileCache.cpp

2016-10-02 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp  |3 ---
 loolwsd/PrisonerSession.cpp |   18 +-
 loolwsd/TileCache.cpp   |   12 ++--
 3 files changed, 11 insertions(+), 22 deletions(-)

New commits:
commit 2907d802a55ec5f4e83650adba9bbb7e7f134e1a
Author: Ashod Nakashian 
Date:   Sun Oct 2 15:30:59 2016 -0400

loolwsd: cleanup and logs

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index aeafaa3..d6aba21 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -499,9 +499,6 @@ void DocumentBroker::invalidateTiles(const std::string& 
tiles)
 
 // Remove from cache.
 _tileCache->invalidateTiles(tiles);
-
-//TODO: Re-issue the tiles again to avoid races.
-
 }
 
 void DocumentBroker::handleTileRequest(TileDesc& tile,
diff --git a/loolwsd/PrisonerSession.cpp b/loolwsd/PrisonerSession.cpp
index c2ea47f..cff555e 100644
--- a/loolwsd/PrisonerSession.cpp
+++ b/loolwsd/PrisonerSession.cpp
@@ -56,16 +56,6 @@ bool PrisonerSession::_handleInput(const char *buffer, int 
length)
 
 LOOLWSD::dumpOutgoingTrace(_docBroker->getJailId(), getId(), firstLine);
 
-if (LOOLProtocol::tokenIndicatesUserInteraction(tokens[0]))
-{
-// Keep track of timestamps of incoming client messages that indicate 
user activity.
-updateLastActivityTime();
-}
-
-// 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
 auto peer = _peer.lock();
 if (!peer)
 {
@@ -139,9 +129,7 @@ bool PrisonerSession::_handleInput(const char *buffer, int 
length)
 return false;
 }
 
-// Save as completed, inform the other (Kind::ToClient)
-// PrisonerSession about it.
-
+// Save-as completed, inform the ClientSession.
 const std::string filePrefix("file:///");
 if (url.find(filePrefix) == 0)
 {
@@ -253,6 +241,10 @@ bool PrisonerSession::_handleInput(const char *buffer, int 
length)
 _docBroker->tileCache().saveRendering(font, "font", buffer + 
firstLine.size() + 1, length - firstLine.size() - 1);
 }
 }
+else
+{
+Log::info("Ignoring notification on password protected document: " + 
firstLine);
+}
 
 // Detect json messages, since we must send those as text even though they 
are multiline.
 // If not, the UI will read the first line of a binary payload, assuming 
that's the only
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index ca8a82a..ddceca8 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -331,15 +331,11 @@ void TileCache::invalidateTiles(const std::string& tiles)
 {
 invalidateTiles(-1, 0, 0, INT_MAX, INT_MAX);
 }
-else if (tokens.count() != 6)
-{
-Log::error("Unexpected invalidatetiles request: " + tiles);
-return;
-}
 else
 {
 int part, x, y, width, height;
-if (getTokenInteger(tokens[1], "part", part) &&
+if (tokens.count() == 6 &&
+getTokenInteger(tokens[1], "part", part) &&
 getTokenInteger(tokens[2], "x", x) &&
 getTokenInteger(tokens[3], "y", y) &&
 getTokenInteger(tokens[4], "width", width) &&
@@ -347,6 +343,10 @@ void TileCache::invalidateTiles(const std::string& tiles)
 {
 invalidateTiles(part, x, y, width, height);
 }
+else
+{
+Log::error("Unexpected invalidatetiles request: " + tiles);
+}
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/Makefile.am

2016-09-30 Thread Miklos Vajna
 loolwsd/DocumentBroker.cpp |4 +++-
 loolwsd/Makefile.am|3 +++
 2 files changed, 6 insertions(+), 1 deletion(-)

New commits:
commit 827d5ed9c825c3636d32071de2611029436e1f87
Author: Miklos Vajna 
Date:   Fri Sep 30 09:29:08 2016 +0200

DocumentBroker: it's enough to build that temporary string once

Change-Id: I253874fefdb2dfe9bb22a8b3bef641499a49dcc9

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index ba2dd04..aeafaa3 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -450,9 +450,11 @@ void DocumentBroker::alertAllUsersOfDocument(const 
std::string& cmd, const std::
 {
 std::lock_guard lock(_mutex);
 
+std::stringstream ss;
+ss << "error: cmd=" << cmd << " kind=" << kind;
 for (auto& it: _sessions)
 {
-it.second->sendTextFrame("error: cmd=" + cmd + " kind=" + kind);
+it.second->sendTextFrame(ss.str());
 }
 }
 
diff --git a/loolwsd/Makefile.am b/loolwsd/Makefile.am
index b9c935c..fa6c3a0 100644
--- a/loolwsd/Makefile.am
+++ b/loolwsd/Makefile.am
@@ -170,6 +170,9 @@ clean-cache cache-clean:
 # Intentionally don't use "*" below... Avoid risk of accidentally running rm 
-rf /*
test -n "@LOOLWSD_CACHEDIR@" && rm -rf "@LOOLWSD_CACHEDIR@"/[0-9a-f]
 
+clang-tidy:
+   for i in *.cpp; do echo $$i; clang-tidy -header-filter=^$(PWD).* $$i || 
break; done
+
 # After building loolforkit, set its capabilities as required. Do it
 # already after a plain 'make' to allow for testing without
 # installing. When building for packaging, no need for this, as the
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/LibreOfficeKit.hpp loolwsd/LOOLKit.cpp loolwsd/LOOLSession.cpp loolwsd/MessageQueue.hpp loolwsd/TileCache.cpp loolwsd/TraceFile.hpp

2016-09-28 Thread Miklos Vajna
 loolwsd/DocumentBroker.cpp |4 
 loolwsd/LOOLKit.cpp|2 ++
 loolwsd/LOOLSession.cpp|1 +
 loolwsd/LibreOfficeKit.hpp |6 --
 loolwsd/MessageQueue.hpp   |3 ++-
 loolwsd/TileCache.cpp  |4 +++-
 loolwsd/TraceFile.hpp  |7 +--
 loolwsd/Unit.cpp   |3 ++-
 8 files changed, 23 insertions(+), 7 deletions(-)

New commits:
commit 31867f669d0bc3c8b1e517cbdf512133c387073f
Author: Miklos Vajna 
Date:   Wed Sep 28 10:20:24 2016 +0200

Fix remaining uninitialized members

The missing init of mutexes is probably theoretical, the TraceFile and
the Unit ones were real errors, I think.

Change-Id: If19c23a9c93d34059998346af8d45c26a34043a6

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index f8266a7..d1dd3ac 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -112,6 +112,8 @@ DocumentBroker::DocumentBroker() :
 _cursorHeight(0),
 _isLoaded(false),
 _isModified(false),
+_mutex(),
+_saveMutex(),
 _tileVersion(0)
 {
 Log::info("Empty DocumentBroker (marked to destroy) created.");
@@ -135,6 +137,8 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 _cursorHeight(0),
 _isLoaded(false),
 _isModified(false),
+_mutex(),
+_saveMutex(),
 _tileVersion(0)
 {
 assert(!_docKey.empty());
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index e926056..da06fb8 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -258,6 +258,7 @@ public:
 _sessionId(session->getId()),
 _session(std::move(session)),
 _ws(std::move(ws)),
+_threadMutex(),
 _joined(false)
 {
 Log::info("Connection ctor in child for " + _sessionId);
@@ -406,6 +407,7 @@ public:
 _isDocPasswordProtected(false),
 _docPasswordType(PasswordType::ToView),
 _stop(false),
+_mutex(),
 _isLoading(0),
 _clientViews(0)
 {
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index 1af3ddb..3b2c0d3 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -60,6 +60,7 @@ LOOLSession::LOOLSession(const std::string& id, const Kind 
kind,
 _isActive(true),
 _lastActivityTime(std::chrono::steady_clock::now()),
 _isCloseFrame(false),
+_mutex(),
 _docPassword(""),
 _haveDocPassword(false),
 _isDocPasswordProtected(false)
diff --git a/loolwsd/LibreOfficeKit.hpp b/loolwsd/LibreOfficeKit.hpp
index c7319e7..7f0c14f 100644
--- a/loolwsd/LibreOfficeKit.hpp
+++ b/loolwsd/LibreOfficeKit.hpp
@@ -29,7 +29,8 @@ private:
 public:
 /// A lok::Document is typically created by the 
lok::Office::documentLoad() method.
 inline Document(LibreOfficeKitDocument* pDoc) :
-_pDoc(pDoc)
+_pDoc(pDoc),
+_mutex()
 {
 Log::trace("lok::Document ctor.");
 }
@@ -492,7 +493,8 @@ private:
 public:
 /// A lok::Office is typically created by the lok_cpp_init() function.
 inline Office(LibreOfficeKit* pThis) :
-_pOffice(pThis)
+_pOffice(pThis),
+_mutex()
 {
 Log::trace("lok::Office ctor.");
 assert(_pOffice);
diff --git a/loolwsd/MessageQueue.hpp b/loolwsd/MessageQueue.hpp
index 1127454..3cf21f6 100644
--- a/loolwsd/MessageQueue.hpp
+++ b/loolwsd/MessageQueue.hpp
@@ -27,7 +27,8 @@ public:
 
 typedef std::vector Payload;
 
-MessageQueue()
+MessageQueue() :
+_mutex()
 {
 }
 
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 1f9694c..91b95cd 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -47,7 +47,9 @@ TileCache::TileCache(const std::string& docURL,
  const Timestamp& modifiedTime,
  const std::string& cacheDir) :
 _docURL(docURL),
-_cacheDir(cacheDir)
+_cacheDir(cacheDir),
+_cacheMutex(),
+_tilesBeingRenderedMutex()
 {
 Log::info() << "TileCache ctor for uri [" << _docURL
 << "] modifiedTime=" << (modifiedTime.raw()/100)
diff --git a/loolwsd/TraceFile.hpp b/loolwsd/TraceFile.hpp
index 8c32d47..80c6bd7 100644
--- a/loolwsd/TraceFile.hpp
+++ b/loolwsd/TraceFile.hpp
@@ -31,7 +31,9 @@ public:
 };
 
 TraceFileRecord() :
-Dir(Direction::Invalid)
+Dir(Direction::Invalid),
+TimestampNs(0),
+Pid(0)
 {
 }
 
@@ -54,7 +56,8 @@ public:
 _compress(compress),
 _filter(true),
 _stream(path, compress ? std::ios::binary : std::ios::out),
-_deflater(_stream, Poco::DeflatingStreamBuf::STREAM_GZIP)
+_deflater(_stream, Poco::DeflatingStreamBuf::STREAM_GZIP),
+_mutex()
 {
 for (const auto& f : filters)
 {
diff --git a/loolwsd/Unit.cpp b/loolwsd/Unit.cpp
index c566a08..6c050cf 100644
--- a/loolwsd/Unit.cpp
+++ b/loolwsd/Unit.cpp
@@ -110,7 +110,8 @@ UnitBase::UnitBase()
   _setRetValue(false),
   

[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/MessageQueue.cpp loolwsd/TileCache.cpp

2016-09-25 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   19 +--
 loolwsd/MessageQueue.cpp   |   17 +++--
 loolwsd/TileCache.cpp  |1 +
 3 files changed, 25 insertions(+), 12 deletions(-)

New commits:
commit e9a7f8c6c6431245cb13bf74d858fcac23c0c7e7
Author: Ashod Nakashian 
Date:   Sun Sep 25 16:04:27 2016 -0400

loolwsd: split tilecombined in the TileQueue

Delaying the splitting maximizes the chances
that we will deduplicate and combine them
in the queue optimally.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 989e056..f8266a7 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -526,6 +526,7 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 Log::trace() << "TileCombined request for " << tileCombined.serialize() << 
Log::end;
 
 // Satisfy as many tiles from the cache.
+std::vector tiles;
 for (auto& tile : tileCombined.getTiles())
 {
 std::unique_ptr cachedTile = 
_tileCache->lookupTile(tile);
@@ -559,14 +560,20 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 // Not cached, needs rendering.
 tile.setVersion(++_tileVersion);
 tileCache().subscribeToTileRendering(tile, session);
-
-// Forward to child to render.
-Log::debug() << "Sending render request for tile (" << 
tile.getPart() << ',' << tile.getTilePosX() << ',' << tile.getTilePosY() << 
")." << Log::end;
-const auto req = tile.serialize("tile");
-Log::debug() << "Tile request: " << req << Log::end;
-_childProcess->getWebSocket()->sendFrame(req.data(), req.size());
+tiles.push_back(tile);
 }
 }
+
+if (!tiles.empty())
+{
+auto newTileCombined = TileCombined::create(tiles);
+newTileCombined.setVersion(++_tileVersion);
+
+// Forward to child to render.
+const auto req = newTileCombined.serialize("tilecombine");
+Log::debug() << "Sending residual tilecombine: " << req << Log::end;
+_childProcess->getWebSocket()->sendFrame(req.data(), req.size());
+}
 }
 
 void DocumentBroker::cancelTileRequests(const std::shared_ptr& 
session)
diff --git a/loolwsd/MessageQueue.cpp b/loolwsd/MessageQueue.cpp
index da1bfba..e845800 100644
--- a/loolwsd/MessageQueue.cpp
+++ b/loolwsd/MessageQueue.cpp
@@ -106,17 +106,22 @@ void TileQueue::put_impl(const Payload& value)
 Log::trace() << "After canceltiles have " << _queue.size() << " in 
queue." << Log::end;
 return;
 }
-
-// TODO because we are doing tile combining ourselves in the get_impl(),
-// we could split the "tilecombine" messages into separate tiles here;
-// could lead to some improvements in case we are getting subsequent
-// tilecombines with overlapping, but not completely same areas.
+else if (msg.compare(0, 10, "tilecombine") == 0)
+{
+// Breakup tilecombine and deduplicate.
+const auto tileCombined = TileCombined::parse(msg);
+for (auto& tile : tileCombined.getTiles())
+{
+const auto newMsg = tile.serialize("tile");
+_queue.push_back(Payload(newMsg.data(), newMsg.data() + 
newMsg.size()));
+}
+}
 
 if (!_queue.empty())
 {
 // TODO probably we could do the same with the invalidation callbacks
 // (later one wins).
-if (msg.compare(0, 4, "tile") == 0 || msg.compare(0, 10, 
"tilecombine") == 0)
+if (msg.compare(0, 4, "tile") == 0)
 {
 const auto newMsg = msg.substr(0, msg.find(" ver"));
 
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index ce74945..232ca2b 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -433,6 +433,7 @@ void TileCache::subscribeToTileRendering(const TileDesc& 
tile, const std::shared
 {
 Log::debug("Redundant request to subscribe on tile " + name);
 tileBeingRendered->setVersion(tile.getVersion());
+return;
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/test loolwsd/TileCache.cpp loolwsd/TileCache.hpp

2016-09-25 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp  |   20 +---
 loolwsd/TileCache.cpp   |   15 ++-
 loolwsd/TileCache.hpp   |2 +-
 loolwsd/test/TileCacheTests.cpp |2 +-
 4 files changed, 17 insertions(+), 22 deletions(-)

New commits:
commit f6a9de1b2d9646ace933cad17b5a9661da06997e
Author: Ashod Nakashian 
Date:   Sun Sep 25 11:33:37 2016 -0400

Revert "loolwsd: TileCache is told to save or not before...

This reverts commit 01718c5c68bad8d324dfcc1b93d3c49055c90873.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index c241594..989e056 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -587,15 +587,14 @@ void DocumentBroker::handleTileResponse(const 
std::vector& payload)
 try
 {
 auto tile = TileDesc::parse(firstLine);
-
-
+const auto buffer = payload.data();
 const auto length = payload.size();
+
 if (firstLine.size() < static_cast(length) - 1)
 {
-const auto buffer = payload.data();
-tileCache().notifySubscribers(
+tileCache().saveTileAndNotify(
 tile, buffer + firstLine.size() + 1,
-length - firstLine.size() - 1, true);
+length - firstLine.size() - 1);
 }
 else
 {
@@ -620,22 +619,21 @@ void DocumentBroker::handleTileCombinedResponse(const 
std::vector& payload
 try
 {
 auto tileCombined = TileCombined::parse(firstLine);
-
-
+const auto buffer = payload.data();
 const auto length = payload.size();
+auto offset = firstLine.size() + 1;
+
 if (firstLine.size() < static_cast(length) - 1)
 {
-const auto buffer = payload.data();
-auto offset = firstLine.size() + 1;
 for (const auto& tile : tileCombined.getTiles())
 {
-tileCache().notifySubscribers(tile, buffer + offset, 
tile.getImgSize(), true);
+tileCache().saveTileAndNotify(tile, buffer + offset, 
tile.getImgSize());
 offset += tile.getImgSize();
 }
 }
 else
 {
-Log::debug() << "Render request declined for " << firstLine << 
Log::end;
+Log::error() << "Render request failed for " << firstLine << 
Log::end;
 std::unique_lock 
tileBeingRenderedLock(tileCache().getTilesBeingRenderedLock());
 for (const auto& tile : tileCombined.getTiles())
 {
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 6924e30..ce74945 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -142,7 +142,7 @@ std::unique_ptr TileCache::lookupTile(const 
TileDesc& tile)
 return nullptr;
 }
 
-void TileCache::notifySubscribers(const TileDesc& tile, const char *data, 
const size_t size, const bool save)
+void TileCache::saveTileAndNotify(const TileDesc& tile, const char *data, 
const size_t size)
 {
 std::unique_lock lock(_tilesBeingRenderedMutex);
 
@@ -151,14 +151,11 @@ void TileCache::notifySubscribers(const TileDesc& tile, 
const char *data, const
 // Save to disk.
 const auto cachedName = (tileBeingRendered ? 
tileBeingRendered->getCacheName()
: cacheFileName(tile));
-if (save)
-{
-const auto fileName = _cacheDir + "/" + cachedName;
-Log::trace() << "Saving cache tile: " << fileName << Log::end;
-std::fstream outStream(fileName, std::ios::out);
-outStream.write(data, size);
-outStream.close();
-}
+const auto fileName = _cacheDir + "/" + cachedName;
+Log::trace() << "Saving cache tile: " << fileName << Log::end;
+std::fstream outStream(fileName, std::ios::out);
+outStream.write(data, size);
+outStream.close();
 
 // Notify subscribers, if any.
 if (tileBeingRendered)
diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp
index 206603b..fc0210b 100644
--- a/loolwsd/TileCache.hpp
+++ b/loolwsd/TileCache.hpp
@@ -47,7 +47,7 @@ public:
 
 std::unique_ptr lookupTile(const TileDesc& tile);
 
-void notifySubscribers(const TileDesc& tile, const char *data, const 
size_t size, const bool save);
+void saveTileAndNotify(const TileDesc& tile, const char *data, const 
size_t size);
 
 std::string getTextFile(const std::string& fileName);
 
diff --git a/loolwsd/test/TileCacheTests.cpp b/loolwsd/test/TileCacheTests.cpp
index 9081675..f2d7f3d 100644
--- a/loolwsd/test/TileCacheTests.cpp
+++ b/loolwsd/test/TileCacheTests.cpp
@@ -167,7 +167,7 @@ void TileCacheTests::testSimple()
 // Cache Tile
 const auto size = 1024;
 const auto data = genRandomData(size);
-

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

2016-09-25 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   31 ++-
 loolwsd/DocumentBroker.hpp |2 --
 2 files changed, 6 insertions(+), 27 deletions(-)

New commits:
commit 9d883bfc71e66a534f3a03205c9a5054c21b4a03
Author: Ashod Nakashian 
Date:   Sun Sep 25 11:33:31 2016 -0400

Revert "bccu#2018 - Missing tiles when finished typing"

This reverts commit 342125b8ead18ac79dd644063e58496afd5d7d38.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index f55f3ed..c241594 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -112,8 +112,7 @@ DocumentBroker::DocumentBroker() :
 _cursorHeight(0),
 _isLoaded(false),
 _isModified(false),
-_tileVersion(0),
-_invalidatedTileVersion(0)
+_tileVersion(0)
 {
 Log::info("Empty DocumentBroker (marked to destroy) created.");
 }
@@ -136,8 +135,7 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 _cursorHeight(0),
 _isLoaded(false),
 _isModified(false),
-_tileVersion(0),
-_invalidatedTileVersion(0)
+_tileVersion(0)
 {
 assert(!_docKey.empty());
 assert(!_childRoot.empty());
@@ -472,9 +470,8 @@ void DocumentBroker::invalidateTiles(const std::string& 
tiles)
 // Remove from cache.
 _tileCache->invalidateTiles(tiles);
 
-// Any older tile than this (inclusive) is not to be trusted.
-_invalidatedTileVersion = _tileVersion;
-Log::trace("Last invalidated tile version: " + 
std::to_string(_invalidatedTileVersion));
+//TODO: Re-issue the tiles again to avoid races.
+
 }
 
 void DocumentBroker::handleTileRequest(TileDesc& tile,
@@ -591,14 +588,6 @@ void DocumentBroker::handleTileResponse(const 
std::vector& payload)
 {
 auto tile = TileDesc::parse(firstLine);
 
-bool cache = true;
-if (_invalidatedTileVersion > 0 && tile.getVersion() <= 
_invalidatedTileVersion)
-{
-// Drop from the cache, but forward to clients nontheless.
-Log::info() << "Dropping potentially invalidated tile (cutoff "
-<< _invalidatedTileVersion << "): " << firstLine << 
Log::end;
-cache = false;
-}
 
 const auto length = payload.size();
 if (firstLine.size() < static_cast(length) - 1)
@@ -606,7 +595,7 @@ void DocumentBroker::handleTileResponse(const 
std::vector& payload)
 const auto buffer = payload.data();
 tileCache().notifySubscribers(
 tile, buffer + firstLine.size() + 1,
-length - firstLine.size() - 1, cache);
+length - firstLine.size() - 1, true);
 }
 else
 {
@@ -632,14 +621,6 @@ void DocumentBroker::handleTileCombinedResponse(const 
std::vector& payload
 {
 auto tileCombined = TileCombined::parse(firstLine);
 
-bool cache = true;
-if (_invalidatedTileVersion > 0 && tileCombined.getVersion() <= 
_invalidatedTileVersion)
-{
-// Drop from the cache, but forward to clients nontheless.
-Log::info() << "Dropping potentially invalidated tile (cutoff "
-<< _invalidatedTileVersion << "): " << firstLine << 
Log::end;
-cache = false;
-}
 
 const auto length = payload.size();
 if (firstLine.size() < static_cast(length) - 1)
@@ -648,7 +629,7 @@ void DocumentBroker::handleTileCombinedResponse(const 
std::vector& payload
 auto offset = firstLine.size() + 1;
 for (const auto& tile : tileCombined.getTiles())
 {
-tileCache().notifySubscribers(tile, buffer + offset, 
tile.getImgSize(), cache);
+tileCache().notifySubscribers(tile, buffer + offset, 
tile.getImgSize(), true);
 offset += tile.getImgSize();
 }
 }
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 29330c8..a547a32 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -267,8 +267,6 @@ private:
 /// Versioning is used to prevent races between
 /// painting and invalidation.
 std::atomic _tileVersion;
-/// The last version number when invalidation happened.
-std::atomic _invalidatedTileVersion;
 
 static constexpr auto IdleSaveDurationMs = 30 * 1000;
 static constexpr auto AutoSaveDurationMs = 300 * 1000;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-09-22 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   31 +--
 loolwsd/DocumentBroker.hpp |2 ++
 2 files changed, 27 insertions(+), 6 deletions(-)

New commits:
commit 342125b8ead18ac79dd644063e58496afd5d7d38
Author: Ashod Nakashian 
Date:   Thu Sep 22 17:48:37 2016 -0400

bccu#2018 - Missing tiles when finished typing

aka: don't save invalidated tiles into cache

Tiles that are rendered when invalidation is recieved are outdated.

What we do is remember the last tile version when we get an invalidation.
This tile version, and any preceding it, is out of date and should not
get saved in the tile cache.

This fixes a race between rendering and invalidation, which happens
in the following scenario.

1. Tile requested for rendering.
2. User inputs key.
3. While tile is rendering, the tile is invalidated in Core
   (the shared lock between rendering and processing input doesn't
   include parsing tile request or preparing the payload back).
4. Once the tile rendering is done, but before it's encoded and sent back,
   the invalidation is received on the callback.
5. Tile cache is cleared of that tile.
6. The outdated tile is received on its way to the client, saved in cache.
7. Client requests the tile anew upon getting the invalidation.
8. The tile is served from the cache, which is outdated, therefore
   missing the last key input form the user.

The fix is in #3 to remember the version number of the tile being
rendered. Then in #6 we forward the tile to the client, but we
do not store it in cache. In #8 the tile request results in a new
rendering, since the cache will not have the tile. Only this last
rendering of the tile is saved in cache for future requests.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index c241594..f55f3ed 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -112,7 +112,8 @@ DocumentBroker::DocumentBroker() :
 _cursorHeight(0),
 _isLoaded(false),
 _isModified(false),
-_tileVersion(0)
+_tileVersion(0),
+_invalidatedTileVersion(0)
 {
 Log::info("Empty DocumentBroker (marked to destroy) created.");
 }
@@ -135,7 +136,8 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 _cursorHeight(0),
 _isLoaded(false),
 _isModified(false),
-_tileVersion(0)
+_tileVersion(0),
+_invalidatedTileVersion(0)
 {
 assert(!_docKey.empty());
 assert(!_childRoot.empty());
@@ -470,8 +472,9 @@ void DocumentBroker::invalidateTiles(const std::string& 
tiles)
 // Remove from cache.
 _tileCache->invalidateTiles(tiles);
 
-//TODO: Re-issue the tiles again to avoid races.
-
+// Any older tile than this (inclusive) is not to be trusted.
+_invalidatedTileVersion = _tileVersion;
+Log::trace("Last invalidated tile version: " + 
std::to_string(_invalidatedTileVersion));
 }
 
 void DocumentBroker::handleTileRequest(TileDesc& tile,
@@ -588,6 +591,14 @@ void DocumentBroker::handleTileResponse(const 
std::vector& payload)
 {
 auto tile = TileDesc::parse(firstLine);
 
+bool cache = true;
+if (_invalidatedTileVersion > 0 && tile.getVersion() <= 
_invalidatedTileVersion)
+{
+// Drop from the cache, but forward to clients nontheless.
+Log::info() << "Dropping potentially invalidated tile (cutoff "
+<< _invalidatedTileVersion << "): " << firstLine << 
Log::end;
+cache = false;
+}
 
 const auto length = payload.size();
 if (firstLine.size() < static_cast(length) - 1)
@@ -595,7 +606,7 @@ void DocumentBroker::handleTileResponse(const 
std::vector& payload)
 const auto buffer = payload.data();
 tileCache().notifySubscribers(
 tile, buffer + firstLine.size() + 1,
-length - firstLine.size() - 1, true);
+length - firstLine.size() - 1, cache);
 }
 else
 {
@@ -621,6 +632,14 @@ void DocumentBroker::handleTileCombinedResponse(const 
std::vector& payload
 {
 auto tileCombined = TileCombined::parse(firstLine);
 
+bool cache = true;
+if (_invalidatedTileVersion > 0 && tileCombined.getVersion() <= 
_invalidatedTileVersion)
+{
+// Drop from the cache, but forward to clients nontheless.
+Log::info() << "Dropping potentially invalidated tile (cutoff "
+<< _invalidatedTileVersion << "): " << firstLine << 
Log::end;
+cache = false;
+}
 
 const auto length = payload.size();
 if (firstLine.size() < 

[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/test loolwsd/TileCache.cpp loolwsd/TileCache.hpp

2016-09-22 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp  |   20 +++-
 loolwsd/TileCache.cpp   |   15 +--
 loolwsd/TileCache.hpp   |2 +-
 loolwsd/test/TileCacheTests.cpp |2 +-
 4 files changed, 22 insertions(+), 17 deletions(-)

New commits:
commit 01718c5c68bad8d324dfcc1b93d3c49055c90873
Author: Ashod Nakashian 
Date:   Thu Sep 22 17:47:12 2016 -0400

loolwsd: TileCache is told to save or not before notifying subscribers

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 989e056..c241594 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -587,14 +587,15 @@ void DocumentBroker::handleTileResponse(const 
std::vector& payload)
 try
 {
 auto tile = TileDesc::parse(firstLine);
-const auto buffer = payload.data();
-const auto length = payload.size();
 
+
+const auto length = payload.size();
 if (firstLine.size() < static_cast(length) - 1)
 {
-tileCache().saveTileAndNotify(
+const auto buffer = payload.data();
+tileCache().notifySubscribers(
 tile, buffer + firstLine.size() + 1,
-length - firstLine.size() - 1);
+length - firstLine.size() - 1, true);
 }
 else
 {
@@ -619,21 +620,22 @@ void DocumentBroker::handleTileCombinedResponse(const 
std::vector& payload
 try
 {
 auto tileCombined = TileCombined::parse(firstLine);
-const auto buffer = payload.data();
-const auto length = payload.size();
-auto offset = firstLine.size() + 1;
 
+
+const auto length = payload.size();
 if (firstLine.size() < static_cast(length) - 1)
 {
+const auto buffer = payload.data();
+auto offset = firstLine.size() + 1;
 for (const auto& tile : tileCombined.getTiles())
 {
-tileCache().saveTileAndNotify(tile, buffer + offset, 
tile.getImgSize());
+tileCache().notifySubscribers(tile, buffer + offset, 
tile.getImgSize(), true);
 offset += tile.getImgSize();
 }
 }
 else
 {
-Log::error() << "Render request failed for " << firstLine << 
Log::end;
+Log::debug() << "Render request declined for " << firstLine << 
Log::end;
 std::unique_lock 
tileBeingRenderedLock(tileCache().getTilesBeingRenderedLock());
 for (const auto& tile : tileCombined.getTiles())
 {
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index d13400e..acaf18b 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -143,7 +143,7 @@ std::unique_ptr TileCache::lookupTile(const 
TileDesc& tile)
 return nullptr;
 }
 
-void TileCache::saveTileAndNotify(const TileDesc& tile, const char *data, 
const size_t size)
+void TileCache::notifySubscribers(const TileDesc& tile, const char *data, 
const size_t size, const bool save)
 {
 std::unique_lock lock(_tilesBeingRenderedMutex);
 
@@ -152,11 +152,14 @@ void TileCache::saveTileAndNotify(const TileDesc& tile, 
const char *data, const
 // Save to disk.
 const auto cachedName = (tileBeingRendered ? 
tileBeingRendered->getCacheName()
: cacheFileName(tile));
-const auto fileName = _cacheDir + "/" + cachedName;
-Log::trace() << "Saving cache tile: " << fileName << Log::end;
-std::fstream outStream(fileName, std::ios::out);
-outStream.write(data, size);
-outStream.close();
+if (save)
+{
+const auto fileName = _cacheDir + "/" + cachedName;
+Log::trace() << "Saving cache tile: " << fileName << Log::end;
+std::fstream outStream(fileName, std::ios::out);
+outStream.write(data, size);
+outStream.close();
+}
 
 // Notify subscribers, if any.
 if (tileBeingRendered)
diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp
index fc0210b..206603b 100644
--- a/loolwsd/TileCache.hpp
+++ b/loolwsd/TileCache.hpp
@@ -47,7 +47,7 @@ public:
 
 std::unique_ptr lookupTile(const TileDesc& tile);
 
-void saveTileAndNotify(const TileDesc& tile, const char *data, const 
size_t size);
+void notifySubscribers(const TileDesc& tile, const char *data, const 
size_t size, const bool save);
 
 std::string getTextFile(const std::string& fileName);
 
diff --git a/loolwsd/test/TileCacheTests.cpp b/loolwsd/test/TileCacheTests.cpp
index f2d7f3d..9081675 100644
--- a/loolwsd/test/TileCacheTests.cpp
+++ b/loolwsd/test/TileCacheTests.cpp
@@ -167,7 +167,7 @@ void TileCacheTests::testSimple()
 // Cache Tile
 const auto size = 1024;
 const auto data = 

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

2016-09-22 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   19 +++
 1 file changed, 7 insertions(+), 12 deletions(-)

New commits:
commit c3ed8f708ccbbe1daa4b5d59ccd474a082bd516f
Author: Ashod Nakashian 
Date:   Wed Sep 21 18:31:13 2016 -0400

loolwsd: always request new tile rendering

This is fine since there is deduplication logic
in the queue before rendering, so it's safer
to pass client requests along and rather than not.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 289842c..9f630bf 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -558,18 +558,13 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 {
 // Not cached, needs rendering.
 tile.setVersion(++_tileVersion);
-const auto ver = tileCache().subscribeToTileRendering(tile, 
session);
-if (ver <= 0)
-{
-// Already rendering. Skip.
-continue;
-}
-else
-{
-const auto req = tile.serialize("tile");
-Log::debug() << "Tile request: " << req << Log::end;
-_childProcess->getWebSocket()->sendFrame(req.data(), 
req.size());
-}
+tileCache().subscribeToTileRendering(tile, session);
+
+// Forward to child to render.
+Log::debug() << "Sending render request for tile (" << 
tile.getPart() << ',' << tile.getTilePosX() << ',' << tile.getTilePosY() << 
")." << Log::end;
+const auto req = tile.serialize("tile");
+Log::debug() << "Tile request: " << req << Log::end;
+_childProcess->getWebSocket()->sendFrame(req.data(), req.size());
 }
 }
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-09-20 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   12 +---
 loolwsd/TileCache.cpp  |2 +-
 2 files changed, 6 insertions(+), 8 deletions(-)

New commits:
commit ae4a9f7110f6d6677b3f3ef5d545f8021222d5da
Author: Ashod Nakashian 
Date:   Tue Sep 20 22:26:19 2016 -0400

loolwsd: always request newer tile version

And accept any version newer than expected.

Since we have proper de-duplication of tiles
requesting newer versions reduces changes of
races between client and the renderer.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 55ecbfa..289842c 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -510,14 +510,12 @@ void DocumentBroker::handleTileRequest(TileDesc& tile,
 return;
 }
 
-if (tileCache().subscribeToTileRendering(tile, session) > 0)
-{
-Log::debug() << "Sending render request for tile (" << tile.getPart() 
<< ',' << tile.getTilePosX() << ',' << tile.getTilePosY() << ")." << Log::end;
+tileCache().subscribeToTileRendering(tile, session);
 
-// Forward to child to render.
-const std::string request = "tile " + tile.serialize();
-_childProcess->getWebSocket()->sendFrame(request.data(), 
request.size());
-}
+// Forward to child to render.
+Log::debug() << "Sending render request for tile (" << tile.getPart() << 
',' << tile.getTilePosX() << ',' << tile.getTilePosY() << ")." << Log::end;
+const std::string request = "tile " + tile.serialize();
+_childProcess->getWebSocket()->sendFrame(request.data(), request.size());
 }
 
 void DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index eb8e8d8..416543e 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -195,7 +195,7 @@ void TileCache::saveTileAndNotify(const TileDesc& tile, 
const char *data, const
 }
 
 // Remove subscriptions.
-if (tileBeingRendered->getVersion() == tile.getVersion())
+if (tileBeingRendered->getVersion() <= tile.getVersion())
 {
 Log::debug() << "STATISTICS: tile " << tile.getVersion() << " 
internal roundtrip "
  << tileBeingRendered->getElapsedTimeMs() << " ms." << 
Log::end;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/DocumentBroker.hpp loolwsd/PrisonerSession.cpp

2016-09-20 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp  |   11 +++
 loolwsd/DocumentBroker.hpp  |1 +
 loolwsd/PrisonerSession.cpp |2 +-
 3 files changed, 13 insertions(+), 1 deletion(-)

New commits:
commit 9640fd1e78475b00554b8f8972f8433128d95a1c
Author: Ashod Nakashian 
Date:   Tue Sep 20 22:19:52 2016 -0400

loolwsd: handle invalidatetiles in DocumentBroker

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index a30b371..55ecbfa 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -463,6 +463,17 @@ bool DocumentBroker::handleInput(const std::vector& 
payload)
 return true;
 }
 
+void DocumentBroker::invalidateTiles(const std::string& tiles)
+{
+std::unique_lock lock(_mutex);
+
+// Remove from cache.
+_tileCache->invalidateTiles(tiles);
+
+//TODO: Re-issue the tiles again to avoid races.
+
+}
+
 void DocumentBroker::handleTileRequest(TileDesc& tile,
const std::shared_ptr& 
session)
 {
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 7e7bc97..a547a32 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -210,6 +210,7 @@ public:
 _cursorHeight = h;
 }
 
+void invalidateTiles(const std::string& tiles);
 void handleTileRequest(TileDesc& tile,
const std::shared_ptr& session);
 void handleTileCombinedRequest(TileCombined& tileCombined,
diff --git a/loolwsd/PrisonerSession.cpp b/loolwsd/PrisonerSession.cpp
index 3844974..c2ea47f 100644
--- a/loolwsd/PrisonerSession.cpp
+++ b/loolwsd/PrisonerSession.cpp
@@ -216,7 +216,7 @@ bool PrisonerSession::_handleInput(const char *buffer, int 
length)
 else if (tokens[0] == "invalidatetiles:")
 {
 assert(firstLine.size() == 
static_cast(length));
-_docBroker->tileCache().invalidateTiles(firstLine);
+_docBroker->invalidateTiles(firstLine);
 }
 else if (tokens[0] == "invalidatecursor:")
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/TileCache.cpp loolwsd/TileCache.hpp

2016-09-20 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |7 ++-
 loolwsd/TileCache.cpp  |   30 +++---
 loolwsd/TileCache.hpp  |2 +-
 3 files changed, 30 insertions(+), 9 deletions(-)

New commits:
commit 6bf643183e4a93dcb85546f146c364b9f0621a83
Author: Ashod Nakashian 
Date:   Mon Sep 19 22:16:45 2016 -0400

loolwsd: cancel subscriber tiles only

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index a54483c..a30b371 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -569,7 +569,12 @@ void DocumentBroker::cancelTileRequests(const 
std::shared_ptr& se
 {
 std::unique_lock lock(_mutex);
 
-tileCache().cancelTiles(session);
+const auto canceltiles = tileCache().cancelTiles(session);
+if (!canceltiles.empty())
+{
+Log::debug() << "Forwarding canceltiles request: " << canceltiles << 
Log::end;
+_childProcess->getWebSocket()->sendFrame(canceltiles.data(), 
canceltiles.size());
+}
 }
 
 void DocumentBroker::handleTileResponse(const std::vector& payload)
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 1ad4907..a5f7c0f 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -475,26 +475,42 @@ int TileCache::subscribeToTileRendering(const TileDesc& 
tile, const std::shared_
 }
 }
 
-void TileCache::cancelTiles(const std::shared_ptr )
+std::string TileCache::cancelTiles(const std::shared_ptr 
)
 {
 std::unique_lock lock(_tilesBeingRenderedMutex);
 
 const auto sub = subscriber.get();
 
 Log::trace("Cancelling tiles for " + subscriber->getName());
+std::ostringstream oss;
 
 for (auto it = _tilesBeingRendered.begin(); it != 
_tilesBeingRendered.end(); )
 {
 auto& subscribers = it->second->_subscribers;
 Log::trace("Tile " + it->first + " has " + 
std::to_string(subscribers.size()) + " subscribers.");
-subscribers.erase(std::remove_if(subscribers.begin(), 
subscribers.end(),
- [sub](std::weak_ptr& 
ptr){ return ptr.lock().get() == sub; }),
-  subscribers.end());
-Log::trace(" Tile " + it->first + " has " + 
std::to_string(subscribers.size()) + " subscribers.");
 
-// Remove if there are no more subscribers on this tile.
-it = (subscribers.empty() ? _tilesBeingRendered.erase(it) : ++it);
+const auto itRem = std::find_if(subscribers.begin(), subscribers.end(),
+[sub](std::weak_ptr& 
ptr){ return ptr.lock().get() == sub; });
+if (itRem != subscribers.end())
+{
+Log::trace("Tile " + it->first + " has " + 
std::to_string(subscribers.size()) + " subscribers. Removing one.");
+subscribers.erase(itRem, itRem + 1);
+if (subscribers.empty())
+{
+// No other subscriber, remove it from the render queue.
+oss << it->second->getVersion() << ',';
+it = _tilesBeingRendered.erase(it);
+}
+}
+
+if (!subscribers.empty())
+{
+++it;
+}
 }
+
+const auto canceltiles = oss.str();
+return (canceltiles.empty() ? canceltiles : "canceltiles " + canceltiles);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp
index 2801e22..6d206fc 100644
--- a/loolwsd/TileCache.hpp
+++ b/loolwsd/TileCache.hpp
@@ -43,7 +43,7 @@ public:
 int subscribeToTileRendering(const TileDesc& tile, const 
std::shared_ptr );
 
 /// Cancels all tile requests by the given subscriber.
-void cancelTiles(const std::shared_ptr );
+std::string cancelTiles(const std::shared_ptr );
 
 std::unique_ptr lookupTile(const TileDesc& tile);
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/test loolwsd/TileCache.cpp loolwsd/TileCache.hpp

2016-09-19 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp  |8 ++--
 loolwsd/TileCache.cpp   |   14 +-
 loolwsd/TileCache.hpp   |2 +-
 loolwsd/test/TileCacheTests.cpp |2 +-
 4 files changed, 9 insertions(+), 17 deletions(-)

New commits:
commit ec4b4898859f2849ba7888b04dc688f804cb6975
Author: Ashod Nakashian 
Date:   Mon Sep 19 20:21:18 2016 -0400

loolwsd: remove unused priority flag from saveTileAndNotify

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 78cc9e7..5ef3f60 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -609,13 +609,9 @@ void DocumentBroker::handleTileResponse(const 
std::vector& payload)
 
 if (firstLine.size() < static_cast(length) - 1)
 {
-// If the tile right under the cursor, give it priority.
-const bool priority = tile.intersectsWithRect(
-_cursorPosX, _cursorPosY,
-_cursorWidth, _cursorHeight);
 tileCache().saveTileAndNotify(
 tile, buffer + firstLine.size() + 1,
-length - firstLine.size() - 1, priority);
+length - firstLine.size() - 1);
 }
 else
 {
@@ -648,7 +644,7 @@ void DocumentBroker::handleTileCombinedResponse(const 
std::vector& payload
 {
 for (const auto& tile : tileCombined.getTiles())
 {
-tileCache().saveTileAndNotify(tile, buffer + offset, 
tile.getImgSize(), false);
+tileCache().saveTileAndNotify(tile, buffer + offset, 
tile.getImgSize());
 offset += tile.getImgSize();
 }
 }
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 9e3bca7..c7dfd6e 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -140,19 +140,11 @@ std::unique_ptr TileCache::lookupTile(const 
TileDesc& tile)
 return nullptr;
 }
 
-void TileCache::saveTileAndNotify(const TileDesc& tile, const char *data, 
const size_t size, const bool /* priority */)
+void TileCache::saveTileAndNotify(const TileDesc& tile, const char *data, 
const size_t size)
 {
 std::unique_lock lock(_tilesBeingRenderedMutex);
 
 std::shared_ptr tileBeingRendered = 
findTileBeingRendered(tile);
-#if 0
-if (!priority && tileBeingRendered && tileBeingRendered->getVersion() != 
tile.getVersion())
-{
-Log::trace() << "Skipping unexpected tile ver: " << tile.getVersion()
- << ", waiting for ver " << 
tileBeingRendered->getVersion() << Log::end;
-return;
-}
-#endif
 
 // Save to disk.
 const auto cachedName = (tileBeingRendered ? 
tileBeingRendered->getCacheName()
@@ -197,6 +189,10 @@ void TileCache::saveTileAndNotify(const TileDesc& tile, 
const char *data, const
 }
 }
 }
+else
+{
+Log::debug("No subscribers for: " + cachedName);
+}
 
 // Remove subscriptions.
 if (tileBeingRendered->getVersion() == tile.getVersion())
diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp
index bbe5aa0..08b14e0 100644
--- a/loolwsd/TileCache.hpp
+++ b/loolwsd/TileCache.hpp
@@ -44,7 +44,7 @@ public:
 
 std::unique_ptr lookupTile(const TileDesc& tile);
 
-void saveTileAndNotify(const TileDesc& tile, const char *data, const 
size_t size, const bool priority);
+void saveTileAndNotify(const TileDesc& tile, const char *data, const 
size_t size);
 
 std::string getTextFile(const std::string& fileName);
 
diff --git a/loolwsd/test/TileCacheTests.cpp b/loolwsd/test/TileCacheTests.cpp
index a4d3527..b9f8900 100644
--- a/loolwsd/test/TileCacheTests.cpp
+++ b/loolwsd/test/TileCacheTests.cpp
@@ -159,7 +159,7 @@ void TileCacheTests::testSimple()
 // Cache Tile
 const auto size = 1024;
 const auto data = genRandomData(size);
-tc.saveTileAndNotify(tile, data.data(), size, true);
+tc.saveTileAndNotify(tile, data.data(), size);
 
 // Find Tile
 file = tc.lookupTile(tile);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-09-19 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   24 ++--
 1 file changed, 2 insertions(+), 22 deletions(-)

New commits:
commit 1255cc11d894685362249d48063f000e75adc0d3
Author: Ashod Nakashian 
Date:   Mon Sep 19 20:29:40 2016 -0400

loolwsd: version each tile and simplify tilecombine request handling

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 709c2a0..1e58e76 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -545,11 +545,9 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 {
 std::unique_lock lock(_mutex);
 
-tileCombined.setVersion(++_tileVersion);
 Log::trace() << "TileCombined request for " << tileCombined.serialize() << 
Log::end;
 
 // Satisfy as many tiles from the cache.
-std::vector tiles;
 for (auto& tile : tileCombined.getTiles())
 {
 std::unique_ptr cachedTile = 
_tileCache->lookupTile(tile);
@@ -577,12 +575,11 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 cachedTile->close();
 
 session->sendBinaryFrame(output.data(), output.size());
-continue;
 }
 else
 {
 // Not cached, needs rendering.
-tile.setVersion(_tileVersion);
+tile.setVersion(++_tileVersion);
 const auto ver = tileCache().subscribeToTileRendering(tile, 
session);
 if (ver <= 0)
 {
@@ -590,29 +587,12 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 continue;
 }
 else
-if (tile.intersectsWithRect(_cursorPosX, _cursorPosY,
-_cursorWidth, _cursorHeight))
 {
-// If this tile is right under the cursor, give it priority.
 const auto req = tile.serialize("tile");
-Log::debug() << "Priority tile request: " << req << Log::end;
+Log::debug() << "Tile request: " << req << Log::end;
 _childProcess->getWebSocket()->sendFrame(req.data(), 
req.size());
-
-// No need to process with the group anymore.
-continue;
 }
 }
-
-tiles.push_back(tile);
-}
-
-for (auto& tile : tiles)
-{
-const auto tileMsg = tile.serialize("tile ");
-Log::debug() << "TileCombined residual request for " << tileMsg << 
Log::end;
-
-// Forward to child to render.
-_childProcess->getWebSocket()->sendFrame(tileMsg.data(), 
tileMsg.size());
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-09-19 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   29 +
 1 file changed, 5 insertions(+), 24 deletions(-)

New commits:
commit 7a8248875dcf6627e302b918c105438673ed0112
Author: Ashod Nakashian 
Date:   Fri Sep 2 07:29:59 2016 -0400

loolwsd: don't combine tiles by row to allow for better culling

Reviewed-on: https://gerrit.libreoffice.org/28615
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 
(cherry picked from commit 99d0ee2ac111e7199626f6c17fb7ce723dac9126)

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index cd4639f..709c2a0 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -549,8 +549,7 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 Log::trace() << "TileCombined request for " << tileCombined.serialize() << 
Log::end;
 
 // Satisfy as many tiles from the cache.
-// The rest, group by rows.
-std::map rows;
+std::vector tiles;
 for (auto& tile : tileCombined.getTiles())
 {
 std::unique_ptr cachedTile = 
_tileCache->lookupTile(tile);
@@ -604,34 +603,16 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 }
 }
 
-const auto tilePosY = tile.getTilePosY();
-auto it = rows.lower_bound(tilePosY);
-if (it != rows.end())
-{
-it->second.emplace_back(tile);
-}
-else
-{
-rows.emplace_hint(it, tilePosY, std::vector({ tile }));
-}
+tiles.push_back(tile);
 }
 
-if (rows.empty())
+for (auto& tile : tiles)
 {
-// Done.
-return;
-}
-
-auto& tiles = tileCombined.getTiles();
-for (auto& row : rows)
-{
-tiles = row.second;
-const auto tileMsg = tileCombined.serialize();
+const auto tileMsg = tile.serialize("tile ");
 Log::debug() << "TileCombined residual request for " << tileMsg << 
Log::end;
 
 // Forward to child to render.
-const std::string request = "tilecombine " + tileMsg;
-_childProcess->getWebSocket()->sendFrame(request.data(), 
request.size());
+_childProcess->getWebSocket()->sendFrame(tileMsg.data(), 
tileMsg.size());
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-09-19 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

New commits:
commit b0f20ea35f604494df28ad6b2e2b377b60185f52
Author: Ashod Nakashian 
Date:   Mon Sep 19 19:18:07 2016 -0400

loolwsd: proper tracing of outgoing tile messages

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 182a72c..cd4639f 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -472,19 +472,24 @@ size_t DocumentBroker::removeSession(const std::string& 
id)
 
 bool DocumentBroker::handleInput(const std::vector& payload)
 {
-Log::trace("DocumentBroker got child message: [" + 
LOOLProtocol::getAbbreviatedMessage(payload) + "].");
+const auto msg = LOOLProtocol::getAbbreviatedMessage(payload);
+Log::trace("DocumentBroker got child message: [" + msg + "].");
 
-const auto command = LOOLProtocol::getFirstToken(payload);
-LOOLWSD::dumpOutgoingTrace(getJailId(), "0", command);
+LOOLWSD::dumpOutgoingTrace(getJailId(), "0", msg);
 
-if (command == "tile:")
+if (msg.find("tile:") == 0)
 {
 handleTileResponse(payload);
 }
-else if (command == "tilecombine:")
+else if (msg.find("tilecombine:") == 0)
 {
handleTileCombinedResponse(payload);
 }
+else
+{
+Log::error("Unexpected message: [" + msg + "].");
+return false;
+}
 
 return true;
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-09-16 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |2 +-
 loolwsd/TileCache.cpp  |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

New commits:
commit ffa146a8700aee5ab9dc0d9b5192a11f96eeecf9
Author: Ashod Nakashian 
Date:   Tue Sep 13 18:40:23 2016 -0400

loolwsd: log tile version in stats

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index ff3fc1b..3c6c3fb 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -574,7 +574,7 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 
 assert(cachedTile->is_open());
 cachedTile->seekg(0, std::ios_base::end);
-size_t pos = output.size();
+const auto pos = output.size();
 std::streamsize size = cachedTile->tellg();
 output.resize(pos + size);
 cachedTile->seekg(0, std::ios_base::beg);
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 0f6936a..b3cf0ea 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -188,7 +188,7 @@ void TileCache::saveTileAndNotify(const TileDesc& tile, 
const char *data, const
 // Remove subscriptions.
 if (tileBeingRendered->getVersion() == tile.getVersion())
 {
-Log::debug() << "STATISTICS: tile internal roundtrip "
+Log::debug() << "STATISTICS: tile " << tile.getVersion() << " 
internal roundtrip "
  << tileBeingRendered->getElapsedTimeMs() << " ms." << 
Log::end;
 _tilesBeingRendered.erase(cachedName);
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-09-15 Thread Jan Holesovsky
 loolwsd/DocumentBroker.cpp |   21 +
 loolwsd/DocumentBroker.hpp |3 +++
 loolwsd/LOOLWSD.cpp|   11 ++-
 3 files changed, 34 insertions(+), 1 deletion(-)

New commits:
commit 27bed804d5c33ed5c49fc648ccc9b1bb2a3c54a7
Author: Jan Holesovsky 
Date:   Thu Sep 15 12:41:57 2016 +0200

bccu#2005: Make sure we don't create 2 jails for the same document.

When 2 users opened the document at the very same time, it happened that new
jails / instances were created for the document twice.

As a solution, insert a dummy (marked to destroy) document into the map of
DocumentBrokers, which will lead into synchronization between the two
instances.

[I suppose the synchronization did not work previously either, as emplace()
does not seem to modify the value when the key is already in the map.]

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 043218f..ff3fc1b 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -97,6 +97,27 @@ std::string DocumentBroker::getDocKey(const Poco::URI& uri)
 return docKey;
 }
 
+DocumentBroker::DocumentBroker() :
+_uriPublic(),
+_docKey(),
+_childRoot(),
+_cacheRoot(),
+_childProcess(),
+_lastSaveTime(std::chrono::steady_clock::now()),
+_markToDestroy(true),
+_lastEditableSession(true),
+_cursorPosX(0),
+_cursorPosY(0),
+_cursorWidth(0),
+_cursorHeight(0),
+_isLoaded(false),
+_isModified(false),
+_isEditLockHeld(false),
+_tileVersion(0)
+{
+Log::info("Empty DocumentBroker (marked to destroy) created.");
+}
+
 DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
const std::string& docKey,
const std::string& childRoot,
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index fd28ed8..301f896 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -136,6 +136,9 @@ public:
 static
 std::string getDocKey(const Poco::URI& uri);
 
+/// Dummy document broker that is marked to destroy.
+DocumentBroker();
+
 DocumentBroker(const Poco::URI& uriPublic,
const std::string& docKey,
const std::string& childRoot,
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index c2c7068..91746f8 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -565,6 +565,15 @@ private:
 docBroker = it->second;
 assert(docBroker);
 }
+else
+{
+// Store a dummy (marked to destroy) document broker until we
+// have the real one, so that the other requests block
+Log::debug("Inserting a dummy DocumentBroker for docKey [" + 
docKey + "] temporarily.");
+
+std::shared_ptr tempBroker = 
std::make_shared();
+docBrokers.emplace(docKey, tempBroker);
+}
 }
 
 if (docBroker)
@@ -645,7 +654,7 @@ private:
 if (newDoc)
 {
 std::unique_lock lock(docBrokersMutex);
-docBrokers.emplace(docKey, docBroker);
+docBrokers[docKey] = docBroker;
 }
 
 // Check if readonly session is required
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-09-14 Thread Michael Meeks
 loolwsd/DocumentBroker.cpp |   29 -
 1 file changed, 24 insertions(+), 5 deletions(-)

New commits:
commit 787ee1d2d2719f4fed161dd66eb7d3e21c512bd3
Author: Michael Meeks 
Date:   Wed Sep 14 22:15:43 2016 +0100

Revert "loolwsd: don't combine tiles by row to allow for better culling"

This breaks combine-tiles very significantly, viewing images
in documents with this appears to show each tile scaling and
rendering individually.

This reverts commit 99d0ee2ac111e7199626f6c17fb7ce723dac9126.

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index fe73d63..043218f 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -532,7 +532,8 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 Log::trace() << "TileCombined request for " << tileCombined.serialize() << 
Log::end;
 
 // Satisfy as many tiles from the cache.
-std::vector tiles;
+// The rest, group by rows.
+std::map rows;
 for (auto& tile : tileCombined.getTiles())
 {
 std::unique_ptr cachedTile = 
_tileCache->lookupTile(tile);
@@ -586,16 +587,34 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 }
 }
 
-tiles.push_back(tile);
+const auto tilePosY = tile.getTilePosY();
+auto it = rows.lower_bound(tilePosY);
+if (it != rows.end())
+{
+it->second.emplace_back(tile);
+}
+else
+{
+rows.emplace_hint(it, tilePosY, std::vector({ tile }));
+}
 }
 
-for (auto& tile : tiles)
+if (rows.empty())
 {
-const auto tileMsg = tile.serialize("tile ");
+// Done.
+return;
+}
+
+auto& tiles = tileCombined.getTiles();
+for (auto& row : rows)
+{
+tiles = row.second;
+const auto tileMsg = tileCombined.serialize();
 Log::debug() << "TileCombined residual request for " << tileMsg << 
Log::end;
 
 // Forward to child to render.
-_childProcess->getWebSocket()->sendFrame(tileMsg.data(), 
tileMsg.size());
+const std::string request = "tilecombine " + tileMsg;
+_childProcess->getWebSocket()->sendFrame(request.data(), 
request.size());
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-09-02 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   29 +
 1 file changed, 5 insertions(+), 24 deletions(-)

New commits:
commit 99d0ee2ac111e7199626f6c17fb7ce723dac9126
Author: Ashod Nakashian 
Date:   Fri Sep 2 07:29:59 2016 -0400

loolwsd: don't combine tiles by row to allow for better culling

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 043218f..fe73d63 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -532,8 +532,7 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 Log::trace() << "TileCombined request for " << tileCombined.serialize() << 
Log::end;
 
 // Satisfy as many tiles from the cache.
-// The rest, group by rows.
-std::map rows;
+std::vector tiles;
 for (auto& tile : tileCombined.getTiles())
 {
 std::unique_ptr cachedTile = 
_tileCache->lookupTile(tile);
@@ -587,34 +586,16 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 }
 }
 
-const auto tilePosY = tile.getTilePosY();
-auto it = rows.lower_bound(tilePosY);
-if (it != rows.end())
-{
-it->second.emplace_back(tile);
-}
-else
-{
-rows.emplace_hint(it, tilePosY, std::vector({ tile }));
-}
+tiles.push_back(tile);
 }
 
-if (rows.empty())
+for (auto& tile : tiles)
 {
-// Done.
-return;
-}
-
-auto& tiles = tileCombined.getTiles();
-for (auto& row : rows)
-{
-tiles = row.second;
-const auto tileMsg = tileCombined.serialize();
+const auto tileMsg = tile.serialize("tile ");
 Log::debug() << "TileCombined residual request for " << tileMsg << 
Log::end;
 
 // Forward to child to render.
-const std::string request = "tilecombine " + tileMsg;
-_childProcess->getWebSocket()->sendFrame(request.data(), 
request.size());
+_childProcess->getWebSocket()->sendFrame(tileMsg.data(), 
tileMsg.size());
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-08-31 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp  |4 ++--
 loolwsd/test/TileCacheTests.cpp |   17 -
 loolwsd/test/httpwstest.cpp |1 +
 3 files changed, 19 insertions(+), 3 deletions(-)

New commits:
commit 534ab15d2fa3fa49740d0fb595232b7d90b39220
Author: Ashod Nakashian 
Date:   Wed Aug 31 23:41:09 2016 -0400

loolwsd: more aggressive test for unresponsive clients

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index afa8460..2ae259f 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -491,7 +491,7 @@ void DocumentBroker::handleTileRequest(TileDesc& tile,
 #if ENABLE_DEBUG
 const std::string response = tile.serialize("tile:") + " 
renderid=cached\n";
 #else
-const std::string response = tile.serialize("tile:") + "\n";
+const std::string response = tile.serialize("tile:") + '\n';
 #endif
 
 std::vector output;
@@ -501,7 +501,7 @@ void DocumentBroker::handleTileRequest(TileDesc& tile,
 
 assert(cachedTile->is_open());
 cachedTile->seekg(0, std::ios_base::end);
-size_t pos = output.size();
+const auto pos = output.size();
 std::streamsize size = cachedTile->tellg();
 output.resize(pos + size);
 cachedTile->seekg(0, std::ios_base::beg);
diff --git a/loolwsd/test/TileCacheTests.cpp b/loolwsd/test/TileCacheTests.cpp
index 5a2749d..f3d9564 100644
--- a/loolwsd/test/TileCacheTests.cpp
+++ b/loolwsd/test/TileCacheTests.cpp
@@ -234,8 +234,23 @@ void TileCacheTests::testUnresponsiveClient()
 // Pathologically request tiles and fail to read (say slow connection).
 // Meanwhile, verify that others can get all tiles fine.
 // TODO: Track memory consumption to verify we don't buffer too much.
-for (auto x = 0; x < 5; ++x)
+
+std::ostringstream oss;
+for (auto i = 0; i < 1000; ++i)
+{
+oss << Util::encodeId(Util::rng::getNext(), 6);
+}
+
+const auto documentContents = oss.str();
+for (auto x = 0; x < 8; ++x)
 {
+// Invalidate to force re-rendering.
+sendTextFrame(socket2, "uno .uno:SelectAll");
+sendTextFrame(socket2, "uno .uno:Delete");
+assertResponseLine(socket2, "invalidatetiles:", "client2 ");
+sendTextFrame(socket2, "paste mimetype=text/html\n" + 
documentContents);
+assertResponseLine(socket2, "invalidatetiles:", "client2 ");
+
 // Ask for tiles and don't read!
 sendTextFrame(socket1, "tilecombine part=0 width=256 height=256 
tileposx=0,3840,7680,11520,0,3840,7680,11520 
tileposy=0,0,0,0,3840,3840,3840,3840 tilewidth=3840 tileheight=3840");
 
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index 1dae4c3..f28c5d1 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -689,6 +689,7 @@ void HTTPWSTest::testLargePaste()
 {
 oss << Util::encodeId(Util::rng::getNext(), 6);
 }
+
 const auto documentContents = oss.str();
 std::cerr << "Pasting " << documentContents.size() << " characters 
into document." << std::endl;
 sendTextFrame(socket, "paste mimetype=text/html\n" + documentContents);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-08-31 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

New commits:
commit ce2309edd814e17be8c148e235d39df3d337ea8d
Author: Ashod Nakashian 
Date:   Wed Aug 31 20:23:56 2016 -0400

loolwsd: log errors while getting file info

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index a2f1d12..1e82696 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -124,21 +124,24 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 
 const StorageBase::FileInfo DocumentBroker::validate(const Poco::URI& uri)
 {
-Log::info("Validating: " + uri.toString());
+const auto uriString = uri.toString();
+Log::info("Validating: " + uriString);
 try
 {
 auto storage = StorageBase::create("", "", uri);
 auto fileinfo = storage->getFileInfo(uri);
-Log::info("After checkfileinfo: " + fileinfo._filename);
+Log::info("After checkfileinfo: " + uriString + " -> " + 
fileinfo._filename);
 if (!fileinfo.isValid())
 {
+Log::error("Invalid file info for uri " + uriString);
 throw BadRequestException("Invalid URI or access denied.");
 }
 
 return fileinfo;
 }
-catch (const std::exception&)
+catch (const std::exception& ex)
 {
+Log::error("Exception while getting file info for uri " + uriString + 
": " + ex.what());
 throw BadRequestException("Invalid URI or access denied.");
 }
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-08-31 Thread Jan Holesovsky
 loolwsd/DocumentBroker.cpp |2 +-
 loolwsd/Storage.cpp|2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

New commits:
commit 2090f121b61c34a2285430f495aee88c24ebc2e4
Author: Jan Holesovsky 
Date:   Wed Aug 31 17:05:10 2016 +0200

Don't check for nullptr after dereferencing.

StorageBase::create() is supposed to throw when there are trouble.

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index e583279..a2f1d12 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -130,7 +130,7 @@ const StorageBase::FileInfo DocumentBroker::validate(const 
Poco::URI& uri)
 auto storage = StorageBase::create("", "", uri);
 auto fileinfo = storage->getFileInfo(uri);
 Log::info("After checkfileinfo: " + fileinfo._filename);
-if (storage == nullptr || !fileinfo.isValid())
+if (!fileinfo.isValid())
 {
 throw BadRequestException("Invalid URI or access denied.");
 }
diff --git a/loolwsd/Storage.cpp b/loolwsd/Storage.cpp
index 7deba6a..e066f6f 100644
--- a/loolwsd/Storage.cpp
+++ b/loolwsd/Storage.cpp
@@ -138,6 +138,8 @@ std::unique_ptr StorageBase::create(const 
std::string& jailRoot, co
 if (UnitWSD::get().createStorage(jailRoot, jailPath, uri, storage))
 {
 Log::info("Storage load hooked.");
+if (storage)
+return storage;
 }
 else if (uri.isRelative() || uri.getScheme() == "file")
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-08-29 Thread Pranav Kant
 loolwsd/DocumentBroker.cpp |8 ++--
 loolwsd/DocumentBroker.hpp |2 +-
 loolwsd/LOOLWSD.cpp|4 ++--
 loolwsd/Storage.cpp|   10 +++---
 loolwsd/Storage.hpp|2 ++
 5 files changed, 18 insertions(+), 8 deletions(-)

New commits:
commit f8ebb54af0948dbd4b9cb7bdceb44d90b190f4f9
Author: Pranav Kant 
Date:   Mon Aug 29 19:11:37 2016 +0530

loolwsd: Receive WOPI userid, username

Change-Id: I0bd5e5a155b8f8486fbeffb1c1413d5e9c177fc3

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index e3f1954..d119f9c 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -122,16 +122,20 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 Log::info("DocumentBroker [" + _uriPublic.toString() + "] created. DocKey: 
[" + _docKey + "]");
 }
 
-void DocumentBroker::validate(const Poco::URI& uri)
+const StorageBase::FileInfo DocumentBroker::validate(const Poco::URI& uri)
 {
 Log::info("Validating: " + uri.toString());
 try
 {
 auto storage = StorageBase::create("", "", uri);
-if (storage == nullptr || !storage->getFileInfo(uri).isValid())
+auto fileinfo = storage->getFileInfo(uri);
+Log::info("After checkfileinfo: " + fileinfo._filename);
+if (storage == nullptr || !fileinfo.isValid())
 {
 throw BadRequestException("Invalid URI or access denied.");
 }
+
+return fileinfo;
 }
 catch (const std::exception&)
 {
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 1324005..e404e82 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -148,7 +148,7 @@ public:
 << " sessions left." << Log::end;
 }
 
-void validate(const Poco::URI& uri);
+const StorageBase::FileInfo validate(const Poco::URI& uri);
 
 /// Loads a document from the public URI into the jail.
 bool load(const std::string& jailId);
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 9a38e9a..21e867b 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -641,8 +641,8 @@ private:
 }
 
 // Validate the URI and Storage before moving on.
-docBroker->validate(uriPublic);
-Log::debug("Validated [" + uriPublic.toString() + "].");
+const auto fileinfo = docBroker->validate(uriPublic);
+Log::debug("Validated [" + uriPublic.toString() + "] requested with 
userid [" + fileinfo._userId + "] and username [" + fileinfo._userName + "]");
 
 if (newDoc)
 {
diff --git a/loolwsd/Storage.cpp b/loolwsd/Storage.cpp
index f44482e..7deba6a 100644
--- a/loolwsd/Storage.cpp
+++ b/loolwsd/Storage.cpp
@@ -175,7 +175,7 @@ StorageBase::FileInfo LocalStorage::getFileInfo(const 
Poco::URI& uri)
 const auto file = Poco::File(path);
 const auto lastModified = file.getLastModified();
 const auto size = file.getSize();
-return FileInfo({filename, lastModified, size});
+return FileInfo({filename, lastModified, size, "localhost", "Local Host"});
 }
 
 std::string LocalStorage::loadStorageFileToLocal()
@@ -276,6 +276,8 @@ StorageBase::FileInfo WopiStorage::getFileInfo(const 
Poco::URI& uri)
 // Parse the response.
 std::string filename;
 size_t size = 0;
+std::string userId;
+std::string userName;
 std::string resMsg;
 Poco::StreamCopier::copyToString(rs, resMsg);
 Log::debug("WOPI::CheckFileInfo returned: " + resMsg);
@@ -288,10 +290,12 @@ StorageBase::FileInfo WopiStorage::getFileInfo(const 
Poco::URI& uri)
 const auto& object = result.extract();
 filename = object->get("BaseFileName").toString();
 size = std::stoul (object->get("Size").toString(), nullptr, 0);
+userId = object->get("UserId").toString();
+userName = object->get("UserFriendlyName").toString();
 }
 
 // WOPI doesn't support file last modified time.
-return FileInfo({filename, Poco::Timestamp(), size});
+return FileInfo({filename, Poco::Timestamp(), size, userId, userName});
 }
 
 /// uri format: http://server/<...>/wopi*/files//content
@@ -387,7 +391,7 @@ StorageBase::FileInfo WebDAVStorage::getFileInfo(const 
Poco::URI& uri)
 Log::debug("Getting info for webdav uri [" + uri.toString() + "].");
 (void)uri;
 assert(false && "Not Implemented!");
-return FileInfo({"bazinga", Poco::Timestamp(), 0});
+return FileInfo({"bazinga", Poco::Timestamp(), 0, "admin", "admin"});
 }
 
 std::string WebDAVStorage::loadStorageFileToLocal()
diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp
index d4db4e4..4f7e120 100644
--- a/loolwsd/Storage.hpp
+++ b/loolwsd/Storage.hpp
@@ -39,6 +39,8 @@ public:
 std::string _filename;
 Poco::Timestamp _modifiedTime;
 size_t _size;
+std::string _userId;
+std::string _userName;
 };
 
 /// localStorePath the absolute root path of the chroot.

[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/TileCache.cpp loolwsd/TileCache.hpp

2016-08-21 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |7 ---
 loolwsd/TileCache.cpp  |   12 +++-
 loolwsd/TileCache.hpp  |2 +-
 3 files changed, 12 insertions(+), 9 deletions(-)

New commits:
commit 3af0d69d22deabcd1970f5aa5b59a6e993d8a273
Author: Ashod Nakashian 
Date:   Thu Aug 18 10:28:55 2016 -0400

loolwsd: isTileBeingRenderedIfSoSubscribe -> subscribeToTileRendering

Simpler yet descriptive function name and better logging.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index a0d59ca..e3f1954 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -504,7 +504,7 @@ void DocumentBroker::handleTileRequest(TileDesc& tile,
 return;
 }
 
-if (tileCache().isTileBeingRenderedIfSoSubscribe(tile, session) > 0)
+if (tileCache().subscribeToTileRendering(tile, session) > 0)
 {
 Log::debug() << "Sending render request for tile (" << tile.getPart() 
<< ',' << tile.getTilePosX() << ',' << tile.getTilePosY() << ")." << Log::end;
 
@@ -530,7 +530,7 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 std::unique_ptr cachedTile = 
_tileCache->lookupTile(tile);
 if (cachedTile)
 {
-//TODO: Combine.
+//TODO: Combine the response to reduce latency.
 #if ENABLE_DEBUG
 const std::string response = tile.serialize("tile:") + " 
renderid=cached\n";
 #else
@@ -556,8 +556,9 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 }
 else
 {
+// Not cached, needs rendering.
 tile.setVersion(_tileVersion);
-const auto ver = 
tileCache().isTileBeingRenderedIfSoSubscribe(tile, session);
+const auto ver = tileCache().subscribeToTileRendering(tile, 
session);
 if (ver <= 0)
 {
 // Already rendering. Skip.
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 5dd987e..9b76a15 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -410,7 +410,7 @@ void TileCache::saveLastModified(const Timestamp& timestamp)
 }
 
 // FIXME: to be further simplified when we centralize tile messages.
-int TileCache::isTileBeingRenderedIfSoSubscribe(const TileDesc& tile, const 
std::shared_ptr )
+int TileCache::subscribeToTileRendering(const TileDesc& tile, const 
std::shared_ptr )
 {
 std::unique_lock lock(_tilesBeingRenderedMutex);
 
@@ -418,8 +418,10 @@ int TileCache::isTileBeingRenderedIfSoSubscribe(const 
TileDesc& tile, const std:
 
 if (tileBeingRendered)
 {
-Log::debug() << "Tile (" << tile.getPart() << ',' << 
tile.getTilePosX() << ','
- << tile.getTilePosY() << ") is already being rendered, 
subscribing." << Log::end;
+Log::debug() << "Subscribing to tile (" << tile.getPart() << ',' << 
tile.getTilePosX() << ','
+ << tile.getTilePosY() << ") which has "
+ << tileBeingRendered->_subscribers.size()
+ << " subscribers already. Adding one more." << Log::end;
 assert(subscriber->getKind() == LOOLSession::Kind::ToClient);
 
 for (const auto  : tileBeingRendered->_subscribers)
@@ -443,8 +445,8 @@ int TileCache::isTileBeingRenderedIfSoSubscribe(const 
TileDesc& tile, const std:
 }
 else
 {
-Log::debug() << "Tile (" << tile.getPart() << ',' << 
tile.getTilePosX() << ','
- << tile.getTilePosY() << ") needs rendering, subscribing 
for ver: "
+Log::debug() << "Subscribing to tile (" << tile.getPart() << ',' << 
tile.getTilePosX() << ','
+ << tile.getTilePosY() << ") which has no subscribers. 
Subscribing for ver: "
  << tile.getVersion() << "." << Log::end;
 
 const std::string cachedName = cacheFileName(tile);
diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp
index b1194bb..bbe5aa0 100644
--- a/loolwsd/TileCache.hpp
+++ b/loolwsd/TileCache.hpp
@@ -40,7 +40,7 @@ public:
 
 /// Subscribes if no subscription exists and returns the version number.
 /// Otherwise returns 0 to signify a subscription exists.
-int isTileBeingRenderedIfSoSubscribe(const TileDesc& tile, const 
std::shared_ptr );
+int subscribeToTileRendering(const TileDesc& tile, const 
std::shared_ptr );
 
 std::unique_ptr lookupTile(const TileDesc& tile);
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/LOOLWSD.hpp loolwsd/PrisonerSession.cpp loolwsd/TraceFile.hpp

2016-08-07 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp  |2 ++
 loolwsd/LOOLWSD.hpp |9 +
 loolwsd/PrisonerSession.cpp |2 ++
 loolwsd/TraceFile.hpp   |   11 +++
 4 files changed, 24 insertions(+)

New commits:
commit 177802154da969a5d48469e934226830cfdf755e
Author: Ashod Nakashian 
Date:   Sun Jul 31 07:54:47 2016 -0400

loolwsd: trace notifications and response messages

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 7b4640b..f998ab4 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -454,6 +454,8 @@ bool DocumentBroker::handleInput(const std::vector& 
payload)
 Log::trace("DocumentBroker got child message: [" + 
LOOLProtocol::getAbbreviatedMessage(payload) + "].");
 
 const auto command = LOOLProtocol::getFirstToken(payload);
+LOOLWSD::dumpOutgoingTrace(command);
+
 if (command == "tile:")
 {
 handleTileResponse(payload);
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 0b9f6bc..72f3ffe 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -70,6 +70,15 @@ public:
 }
 }
 
+static
+void dumpOutgoingTrace(const std::string& data)
+{
+if (TraceDumper)
+{
+TraceDumper->writeOutgoing(data);
+}
+}
+
 protected:
 void initialize(Poco::Util::Application& self) override;
 void uninitialize() override;
diff --git a/loolwsd/PrisonerSession.cpp b/loolwsd/PrisonerSession.cpp
index 5da9780..2114f5c 100644
--- a/loolwsd/PrisonerSession.cpp
+++ b/loolwsd/PrisonerSession.cpp
@@ -54,6 +54,8 @@ bool PrisonerSession::_handleInput(const char *buffer, int 
length)
 StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | 
StringTokenizer::TOK_TRIM);
 Log::trace(getName() + ": handling [" + firstLine + "].");
 
+LOOLWSD::dumpOutgoingTrace(firstLine);
+
 if (LOOLProtocol::tokenIndicatesUserInteraction(tokens[0]))
 {
 // Keep track of timestamps of incoming client messages that indicate 
user activity.
diff --git a/loolwsd/TraceFile.hpp b/loolwsd/TraceFile.hpp
index 9b2d3b9..476b409 100644
--- a/loolwsd/TraceFile.hpp
+++ b/loolwsd/TraceFile.hpp
@@ -36,6 +36,17 @@ public:
 _stream.write("\n", 1);
 }
 
+void writeOutgoing(const std::string& data)
+{
+std::unique_lock lock(_mutex);
+const Poco::Int64 usec = Poco::Timestamp().epochMicroseconds() - 
_epochStart;
+_stream.write("<", 1);
+_stream << usec;
+_stream.write("<", 1);
+_stream.write(data.c_str(), data.size());
+_stream.write("\n", 1);
+}
+
 private:
 const Poco::Int64 _epochStart;
 std::fstream _stream;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-08-01 Thread Michael Meeks
 loolwsd/DocumentBroker.cpp |5 -
 loolwsd/LOOLKit.cpp|   13 -
 loolwsd/LOOLWSD.cpp|2 +-
 loolwsd/LOOLWSD.hpp|1 +
 4 files changed, 14 insertions(+), 7 deletions(-)

New commits:
commit 9a0c5d8571bdece8c2a717f6fc4c3fc28b7465fa
Author: Michael Meeks 
Date:   Mon Aug 1 09:05:37 2016 +0100

Continue nocaps work to improve valgrindability.

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 052ef0c..7b4640b 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -164,10 +164,13 @@ bool DocumentBroker::load(const std::string& jailId)
 
 // user/doc/jailId
 const auto jailPath = Poco::Path(JAILED_DOCUMENT_ROOT, jailId);
-const std::string jailRoot = getJailRoot();
+std::string jailRoot = getJailRoot();
 
 Log::info("jailPath: " + jailPath.toString() + ", jailRoot: " + jailRoot);
 
+if (LOOLWSD::NoCapsForKit)
+jailRoot = jailPath.toString() + "/" + getJailRoot();
+
 auto storage = StorageBase::create(jailRoot, jailPath.toString(), 
_uriPublic);
 if (storage)
 {
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index e3b5ec1..9b72946 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -1029,20 +1029,22 @@ void lokit_main(const std::string& childRoot,
 Util::setTerminationSignals();
 Util::setFatalSignals();
 
+std::string userdir_url;
 std::string instdir_path;
 
 Path jailPath;
 bool bRunInsideJail = !noCapabilities;
 try
 {
+jailPath = Path::forDirectory(childRoot + "/" + jailId);
+Log::info("Jail path: " + jailPath.toString());
+File(jailPath).createDirectories();
+
 if (bRunInsideJail)
 {
+userdir_url = "file:///user";
 instdir_path = "/" + loSubPath + "/program";
 
-jailPath = Path::forDirectory(childRoot + "/" + jailId);
-Log::info("Jail path: " + jailPath.toString());
-File(jailPath).createDirectories();
-
 // Create a symlink inside the jailPath so that the absolute 
pathname loTemplate, when
 // interpreted inside a chroot at jailPath, points to loSubPath 
(relative to the chroot).
 symlinkPathToJail(jailPath, loTemplate, loSubPath);
@@ -1131,13 +1133,14 @@ void lokit_main(const std::string& childRoot,
 else // noCapabilities set
 {
 Log::info("Using template " + loTemplate + " as install subpath - 
skipping jail setup");
+userdir_url = "file:///" + jailPath.toString() + "/user";
 instdir_path = "/" + loTemplate + "/program";
 }
 
 std::shared_ptr loKit;
 {
 const char *instdir = instdir_path.c_str();
-const char *userdir = "file:///user";
+const char *userdir = userdir_url.c_str();
 auto kit = UnitKit::get().lok_init(instdir, userdir);
 if (!kit)
 {
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 6654f1f..8ba1fee 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -161,7 +161,6 @@ int MasterPortNumber = DEFAULT_MASTER_PORT_NUMBER;
 /// New LOK child processes ready to host documents.
 //TODO: Move to a more sensible namespace.
 static bool DisplayVersion = false;
-static bool NoCapsForKit = false;
 static std::vector newChildren;
 static std::mutex newChildrenMutex;
 static std::condition_variable newChildrenCV;
@@ -1251,6 +1250,7 @@ std::string lcl_getLaunchURI()
 
 std::atomic LOOLWSD::NextSessionId;
 int LOOLWSD::ForKitWritePipe = -1;
+bool LOOLWSD::NoCapsForKit = false;
 std::string LOOLWSD::Cache = LOOLWSD_CACHEDIR;
 std::string LOOLWSD::SysTemplate;
 std::string LOOLWSD::LoTemplate;
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index ae4eca1..74fba62 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -35,6 +35,7 @@ public:
 // so just keep these as statics.
 static std::atomic NextSessionId;
 static unsigned int NumPreSpawnedChildren;
+static bool NoCapsForKit;
 static int ForKitWritePipe;
 static std::string Cache;
 static std::string SysTemplate;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-07-18 Thread Miklos Vajna
 loolwsd/DocumentBroker.cpp |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 24624762dff23957c2b82e0416e0ab9f43b1ca71
Author: Miklos Vajna 
Date:   Mon Jul 18 10:25:05 2016 +0200

DocumentBroker: use std::move() instead of manual reset()/release()

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index d0c21f2..052ef0c 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -105,7 +105,7 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 _docKey(docKey),
 _childRoot(childRoot),
 _cacheRoot(getCachePath(uriPublic.toString())),
-_childProcess(childProcess),
+_childProcess(std::move(childProcess)),
 _lastSaveTime(std::chrono::steady_clock::now()),
 _markToDestroy(false),
 _lastEditableSession(false),
@@ -181,7 +181,7 @@ bool DocumentBroker::load(const std::string& jailId)
 _lastFileModifiedTime = 
Poco::File(storage->getLocalRootPath()).getLastModified();
 _tileCache.reset(new TileCache(_uriPublic.toString(), 
_lastFileModifiedTime, _cacheRoot));
 
-_storage.reset(storage.release());
+_storage = std::move(storage);
 return true;
 }
 
@@ -482,7 +482,7 @@ void DocumentBroker::handleTileRequest(TileDesc& tile,
 #endif
 
 std::vector output;
-output.reserve(4 * tile.getWidth() * tile.getHeight());
+output.reserve(static_cast(4) * tile.getWidth() * 
tile.getHeight());
 output.resize(response.size());
 std::memcpy(output.data(), response.data(), response.size());
 
@@ -533,7 +533,7 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 #endif
 
 std::vector output;
-output.reserve(4 * tile.getWidth() * tile.getHeight());
+output.reserve(static_cast(4) * tile.getWidth() * 
tile.getHeight());
 output.resize(response.size());
 std::memcpy(output.data(), response.data(), response.size());
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-05-30 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   43 ---
 1 file changed, 28 insertions(+), 15 deletions(-)

New commits:
commit 763eee7040f7a04a0a08e9597307f75b6ebce2a5
Author: Ashod Nakashian 
Date:   Sun May 29 17:40:27 2016 -0400

loolwsd: batch tiles by row

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index fe4d715..ed6cc55 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -469,11 +469,10 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 Log::trace() << "TileCombined request for " << tileCombined.serialize() << 
Log::end;
 
 // Satisfy as many tiles from the cache.
-auto& tiles = tileCombined.getTiles();
-int i = tiles.size();
-while (--i >= 0)
+// The rest, group by rows.
+std::map rows;
+for (auto& tile : tileCombined.getTiles())
 {
-auto& tile = tiles[i];
 std::unique_ptr cachedTile = 
_tileCache->lookupTile(tile);
 if (cachedTile)
 {
@@ -499,9 +498,7 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 cachedTile->close();
 
 session->sendBinaryFrame(output.data(), output.size());
-
-// Remove.
-tiles.erase(tiles.begin() + i);
+continue;
 }
 else
 {
@@ -510,7 +507,7 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 if (ver <= 0)
 {
 // Already rendering. Skip.
-tiles.erase(tiles.begin() + i);
+continue;
 }
 else
 if (_cursorPosX >= tile.getTilePosX() && _cursorPosX <= 
tile.getTilePosX() + tile.getTileWidth() &&
@@ -522,23 +519,39 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 _childProcess->getWebSocket()->sendFrame(req.data(), 
req.size());
 
 // No need to process with the group anymore.
-tiles.erase(tiles.begin() + i);
+continue;
 }
 }
+
+const auto tilePosY = tile.getTilePosY();
+auto it = rows.lower_bound(tilePosY);
+if (it != rows.end())
+{
+it->second.emplace_back(tile);
+}
+else
+{
+rows.emplace_hint(it, tilePosY, std::vector({ tile }));
+}
 }
 
-if (tiles.empty())
+if (rows.empty())
 {
 // Done.
 return;
 }
 
-const auto tileMsg = tileCombined.serialize();
-Log::debug() << "TileCombined residual request for " << tileMsg << 
Log::end;
+auto& tiles = tileCombined.getTiles();
+for (auto& row : rows)
+{
+tiles = row.second;
+const auto tileMsg = tileCombined.serialize();
+Log::debug() << "TileCombined residual request for " << tileMsg << 
Log::end;
 
-// Forward to child to render.
-const std::string request = "tilecombine " + tileMsg;
-_childProcess->getWebSocket()->sendFrame(request.data(), request.size());
+// Forward to child to render.
+const std::string request = "tilecombine " + tileMsg;
+_childProcess->getWebSocket()->sendFrame(request.data(), 
request.size());
+}
 }
 
 void DocumentBroker::handleTileResponse(const std::vector& payload)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/DocumentBroker.hpp loolwsd/PrisonerSession.cpp loolwsd/test loolwsd/TileCache.cpp loolwsd/TileCache.hpp

2016-05-22 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp  |   27 +++
 loolwsd/DocumentBroker.hpp  |9 +
 loolwsd/PrisonerSession.cpp |   17 +
 loolwsd/TileCache.cpp   |9 ++---
 loolwsd/TileCache.hpp   |2 +-
 loolwsd/test/TileCacheTests.cpp |2 +-
 6 files changed, 57 insertions(+), 9 deletions(-)

New commits:
commit 157386e3bc6a42b03393105e85da4a8fae074d1b
Author: Ashod Nakashian 
Date:   Sun May 22 16:47:22 2016 -0400

loolwsd: process tiles under the cursor with priority

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 10600da..fe4d715 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -108,6 +108,8 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 _childProcess(childProcess),
 _lastSaveTime(std::chrono::steady_clock::now()),
 _markToDestroy(false),
+_cursorPosX(0),
+_cursorPosY(0),
 _isLoaded(false),
 _isModified(false),
 _tileVersion(0)
@@ -507,7 +509,19 @@ void 
DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
 const auto ver = 
tileCache().isTileBeingRenderedIfSoSubscribe(tile, session);
 if (ver <= 0)
 {
-// Skip.
+// Already rendering. Skip.
+tiles.erase(tiles.begin() + i);
+}
+else
+if (_cursorPosX >= tile.getTilePosX() && _cursorPosX <= 
tile.getTilePosX() + tile.getTileWidth() &&
+_cursorPosY >= tile.getTilePosY() && _cursorPosY <= 
tile.getTilePosY() + tile.getTileHeight())
+{
+// If this tile is right under the cursor, give it priority.
+const auto req = tile.serialize("tile");
+Log::debug() << "Priority tile request: " << req << Log::end;
+_childProcess->getWebSocket()->sendFrame(req.data(), 
req.size());
+
+// No need to process with the group anymore.
 tiles.erase(tiles.begin() + i);
 }
 }
@@ -536,9 +550,14 @@ void DocumentBroker::handleTileResponse(const 
std::vector& payload)
 const auto buffer = payload.data();
 const auto length = payload.size();
 
-if(firstLine.size() < static_cast(length) - 1)
+if (firstLine.size() < static_cast(length) - 1)
 {
-tileCache().saveTileAndNotify(tile, buffer + firstLine.size() + 1, 
length - firstLine.size() - 1);
+// If the tile right under the cursor, give it priority.
+const auto priority = (_cursorPosX >= tile.getTilePosX() &&
+   _cursorPosX <= tile.getTilePosX() + 
tile.getTileWidth() &&
+   _cursorPosY >= tile.getTilePosY() &&
+   _cursorPosY <= tile.getTilePosY() + 
tile.getTileHeight());
+tileCache().saveTileAndNotify(tile, buffer + firstLine.size() + 1, 
length - firstLine.size() - 1, priority);
 }
 else
 {
@@ -571,7 +590,7 @@ void DocumentBroker::handleTileCombinedResponse(const 
std::vector& payload
 {
 for (const auto& tile : tileCombined.getTiles())
 {
-tileCache().saveTileAndNotify(tile, buffer + offset, 
tile.getImgSize());
+tileCache().saveTileAndNotify(tile, buffer + offset, 
tile.getImgSize(), false);
 offset += tile.getImgSize();
 }
 }
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 3c2a342..7832ff4 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -202,6 +202,13 @@ public:
 /// Removes a session by ID. Returns the new number of sessions.
 size_t removeSession(const std::string& id);
 
+/// Invalidate the cursor position.
+void invalidateCursor(const int x, const int y)
+{
+_cursorPosX = x;
+_cursorPosY = y;
+}
+
 void handleTileRequest(TileDesc& tile,
const std::shared_ptr& session);
 void handleTileCombinedRequest(TileCombined& tileCombined,
@@ -239,6 +246,8 @@ private:
 std::unique_ptr _storage;
 std::unique_ptr _tileCache;
 std::atomic _markToDestroy;
+int _cursorPosX;
+int _cursorPosY;
 bool _isLoaded;
 bool _isModified;
 mutable std::mutex _mutex;
diff --git a/loolwsd/PrisonerSession.cpp b/loolwsd/PrisonerSession.cpp
index 9933e6c..9dd096d 100644
--- a/loolwsd/PrisonerSession.cpp
+++ b/loolwsd/PrisonerSession.cpp
@@ -204,6 +204,23 @@ bool PrisonerSession::_handleInput(const char *buffer, int 
length)
 assert(firstLine.size() == 
static_cast(length));

[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/test loolwsd/TileCache.cpp loolwsd/TileCache.hpp

2016-05-22 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp  |6 --
 loolwsd/TileCache.cpp   |   95 +---
 loolwsd/TileCache.hpp   |4 -
 loolwsd/test/TileCacheTests.cpp |2 
 4 files changed, 54 insertions(+), 53 deletions(-)

New commits:
commit 6e54fd05f91547d7abda8336fcda248688be71ff
Author: Ashod Nakashian 
Date:   Sun May 22 15:20:24 2016 -0400

loolwsd: merge saveTile and notifyAndRemoveSubscribers

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index c555298..10600da 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -538,8 +538,7 @@ void DocumentBroker::handleTileResponse(const 
std::vector& payload)
 
 if(firstLine.size() < static_cast(length) - 1)
 {
-tileCache().saveTile(tile, buffer + firstLine.size() + 1, length - 
firstLine.size() - 1);
-tileCache().notifyAndRemoveSubscribers(tile);
+tileCache().saveTileAndNotify(tile, buffer + firstLine.size() + 1, 
length - firstLine.size() - 1);
 }
 else
 {
@@ -572,8 +571,7 @@ void DocumentBroker::handleTileCombinedResponse(const 
std::vector& payload
 {
 for (const auto& tile : tileCombined.getTiles())
 {
-tileCache().saveTile(tile, buffer + offset, tile.getImgSize());
-tileCache().notifyAndRemoveSubscribers(tile);
+tileCache().saveTileAndNotify(tile, buffer + offset, 
tile.getImgSize());
 offset += tile.getImgSize();
 }
 }
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 48721d2..c006bc1 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -75,12 +75,14 @@ TileCache::~TileCache()
 struct TileCache::TileBeingRendered
 {
 std::vector _subscribers;
-TileBeingRendered(const int version)
+TileBeingRendered(const std::string& cachedName, const int version)
  : _startTime(std::chrono::steady_clock::now()),
+   _cachedName(cachedName),
_ver(version)
 {
 }
 
+const std::string& getCacheName() const { return _cachedName; }
 int getVersion() const { return _ver; }
 
 std::chrono::steady_clock::time_point getStartTime() const { return 
_startTime; }
@@ -91,6 +93,7 @@ struct TileCache::TileBeingRendered
 
 private:
 std::chrono::steady_clock::time_point _startTime;
+std::string _cachedName;
 int _ver;
 };
 
@@ -132,15 +135,52 @@ std::unique_ptr TileCache::lookupTile(const 
TileDesc& tile)
 return nullptr;
 }
 
-void TileCache::saveTile(const TileDesc& tile, const char *data, size_t size)
+void TileCache::saveTileAndNotify(const TileDesc& tile, const char *data, 
size_t size)
 {
-const std::string fileName = _cacheDir + "/" + cacheFileName(tile);
+std::unique_lock lock(_tilesBeingRenderedMutex);
 
-Log::trace() << "Saving cache tile: " << fileName << Log::end;
+std::shared_ptr tileBeingRendered = 
findTileBeingRendered(tile);
+if (tileBeingRendered && tileBeingRendered->getVersion() != 
tile.getVersion())
+{
+Log::trace() << "Skipping unexpected tile ver: " << tile.getVersion()
+ << ", waiting for ver " << 
tileBeingRendered->getVersion() << Log::end;
+return;
+}
 
+// Save to disk.
+const auto cachedName = (tileBeingRendered ? 
tileBeingRendered->getCacheName()
+   : cacheFileName(tile));
+const auto fileName = _cacheDir + "/" + cachedName;
+Log::trace() << "Saving cache tile: " << fileName << Log::end;
 std::fstream outStream(fileName, std::ios::out);
 outStream.write(data, size);
 outStream.close();
+
+// Notify subscribers, if any.
+if (tileBeingRendered)
+{
+if (!tileBeingRendered->_subscribers.empty())
+{
+const std::string message = tile.serialize("tile");
+Log::debug("Sending tile message to subscribers: " + message);
+
+for (const auto& i: tileBeingRendered->_subscribers)
+{
+auto subscriber = i.lock();
+if (subscriber)
+{
+//FIXME: This is inefficient; should just send directly to 
each client (although that is risky as well!
+// Re-emit the tile command in the other thread(s) to 
re-check and hit
+// the cache. Construct the message from scratch to 
contain only the
+// mandatory parts of the message.
+subscriber->sendToInputQueue(message);
+}
+}
+}
+
+// Remove subscriptions.
+_tilesBeingRendered.erase(cachedName);
+}
 

[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/DocumentBroker.hpp loolwsd/TileCache.cpp loolwsd/TileCache.hpp

2016-05-22 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   49 +
 loolwsd/DocumentBroker.hpp |6 -
 loolwsd/TileCache.cpp  |   49 -
 loolwsd/TileCache.hpp  |4 ++-
 4 files changed, 76 insertions(+), 32 deletions(-)

New commits:
commit e5aaac7631511df2d303e9627ff896b5e91bc186
Author: Ashod Nakashian 
Date:   Sun May 22 14:31:18 2016 -0400

loolwsd: Tile versioning and fix to race conditions

Tile invalidation and painting can race with one another.

A race when the user types two characters in quick succession:
1. After the first key press, the tile is invalidated.
2. The client request the tile on receiving the invalidate.
3. TileCache doesn't find it, and adds subscription.
 A. Sometime before rendering, the second key press is received.
 B. This invalidates the very same tile.
 C. The client request the same tile.
 D. TileCache finds a subscription and ignores the new one.
4. The tile is rendered and sent back.
5. Subscription is found and the tile is forwarded to clients.
6. Subcription is removed as the request is fullfilled.
 E. The second tile is rendered and sent back.
 F. TileCache finds no subscription and the tile is dropped.

End result: Only the first character appears on the screen.

Versioning fixes the above situation by making sure that in
step 5 the subscription will show to belong to a different
(and newer version) and so the tile will be ignored.
Instead, at F the TileCache will find both subscription
and a matching version and the lastest version will always
be sent back to the client.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 62dfe60..c555298 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -109,7 +109,8 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 _lastSaveTime(std::chrono::steady_clock::now()),
 _markToDestroy(false),
 _isLoaded(false),
-_isModified(false)
+_isModified(false),
+_tileVersion(0)
 {
 assert(!_docKey.empty());
 assert(!_childRoot.empty());
@@ -411,22 +412,22 @@ bool DocumentBroker::handleInput(const std::vector& 
payload)
 return true;
 }
 
-void DocumentBroker::handleTileRequest(const TileDesc& tile,
+void DocumentBroker::handleTileRequest(TileDesc& tile,
const std::shared_ptr& 
session)
 {
-const auto tileMsg = tile.serialize();
-Log::trace() << "Tile request for " << tileMsg << Log::end;
-
 std::unique_lock lock(_mutex);
 
-std::unique_ptr cachedTile = _tileCache->lookupTile(tile);
+tile.setVersion(++_tileVersion);
+const auto tileMsg = tile.serialize();
+Log::trace() << "Tile request for " << tile.serialize() << Log::end;
 
+std::unique_ptr cachedTile = _tileCache->lookupTile(tile);
 if (cachedTile)
 {
 #if ENABLE_DEBUG
-const std::string response = "tile:" + tileMsg + " renderid=cached\n";
+const std::string response = tile.serialize("tile:") + " 
renderid=cached\n";
 #else
-const std::string response = "tile:" + tileMsg + "\n";
+const std::string response = tile.serialize("tile:") + "\n";
 #endif
 
 std::vector output;
@@ -447,29 +448,30 @@ void DocumentBroker::handleTileRequest(const TileDesc& 
tile,
 return;
 }
 
-if (tileCache().isTileBeingRenderedIfSoSubscribe(tile, session))
-return;
-
-Log::debug() << "Sending render request for tile (" << tile.getPart() << 
',' << tile.getTilePosX() << ',' << tile.getTilePosY() << ")." << Log::end;
+if (tileCache().isTileBeingRenderedIfSoSubscribe(tile, session) > 0)
+{
+Log::debug() << "Sending render request for tile (" << tile.getPart() 
<< ',' << tile.getTilePosX() << ',' << tile.getTilePosY() << ")." << Log::end;
 
-// Forward to child to render.
-const std::string request = "tile " + tileMsg;
-_childProcess->getWebSocket()->sendFrame(request.data(), request.size());
+// Forward to child to render.
+const std::string request = "tile " + tile.serialize();
+_childProcess->getWebSocket()->sendFrame(request.data(), 
request.size());
+}
 }
 
 void DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
const 
std::shared_ptr& session)
 {
-Log::trace() << "TileCombined request for " << tileCombined.serialize() << 
Log::end;
-
 std::unique_lock lock(_mutex);
 
+tileCombined.setVersion(++_tileVersion);
+Log::trace() << "TileCombined request for " << tileCombined.serialize() << 
Log::end;
+
 // Satisfy 

[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/test loolwsd/Unit.hpp

2016-05-20 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp   |6 
 loolwsd/Unit.hpp |4 ++
 loolwsd/test/UnitPrefork.cpp |   61 +--
 3 files changed, 46 insertions(+), 25 deletions(-)

New commits:
commit 958f6ffcbdbeae39b78acfb7592096851388fb52
Author: Ashod Nakashian 
Date:   Fri May 20 22:31:53 2016 -0400

loolwsd: fix UnitPrefork deadlock/corruption

Reading from the socket in the test is not
thread-safe, and was causing all sorts of
problems.

The new code adds a test API and reads the
incoming data through it and not directly
from the socket. In addition, the read is
synchronized.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 3bb2bcc..de4d984 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -20,6 +20,7 @@
 #include "LOOLProtocol.hpp"
 #include "ClientSession.hpp"
 #include "PrisonerSession.hpp"
+#include "Unit.hpp"
 
 using namespace LOOLProtocol;
 
@@ -28,6 +29,11 @@ void ChildProcess::socketProcessor()
 IoUtil::SocketProcessor(_ws,
 [this](const std::vector& payload)
 {
+if (UnitWSD::get().filterChildMessage(payload))
+{
+return true;
+}
+
 auto docBroker = this->_docBroker.lock();
 if (docBroker)
 {
diff --git a/loolwsd/Unit.hpp b/loolwsd/Unit.hpp
index dcdd36c..9cebfaa 100644
--- a/loolwsd/Unit.hpp
+++ b/loolwsd/Unit.hpp
@@ -134,6 +134,10 @@ public:
  Poco::Net::HTTPServerResponse& /* response */)
 { return false; }
 
+/// Child sent a message
+virtual bool filterChildMessage(const std::vector& /* payload */)
+{ return false; }
+
 //  TileCache hooks 
 /// Called before the lookupTile call returns. Should always be called to 
fire events.
 virtual void lookupTile(int part, int width, int height, int tilePosX, int 
tilePosY,
diff --git a/loolwsd/test/UnitPrefork.cpp b/loolwsd/test/UnitPrefork.cpp
index c265831..f9437bb 100644
--- a/loolwsd/test/UnitPrefork.cpp
+++ b/loolwsd/test/UnitPrefork.cpp
@@ -14,6 +14,9 @@
 #include 
 #include 
 
+#include 
+#include 
+
 #include "Common.hpp"
 #include "IoUtil.hpp"
 #include "LOOLProtocol.hpp"
@@ -32,11 +35,17 @@ class UnitPrefork : public UnitWSD
 int _numStarted;
 std::string _failure;
 Poco::Timestamp _startTime;
+size_t _totalPSS;
+size_t _totalDirty;
+std::mutex _mutex;
+std::condition_variable _cv;
 std::vector< std::shared_ptr > _childSockets;
 
 public:
 UnitPrefork()
-: _numStarted(0)
+: _numStarted(0),
+  _totalPSS(0),
+  _totalDirty(0)
 {
 setHasKitHooks();
 }
@@ -52,29 +61,9 @@ public:
 numPrefork = NumToPrefork;
 }
 
-void getMemory(const std::shared_ptr ,
-   size_t , size_t )
+virtual bool filterChildMessage(const std::vector& payload)
 {
-/// Fetch memory usage data from the last process ...
-socket->sendFrame("unit-memdump: \n", sizeof("unit-memdump: \n")-1);
-
-static const Poco::Timespan waitTime(COMMAND_TIMEOUT_MS * 1000);
-if (!socket->poll(waitTime, Poco::Net::Socket::SELECT_READ))
-{
-_failure = "Timed out waiting for child to respond to unit-memdump 
command.";
-return;
-}
-
-int flags;
-char buffer[4096];
-const int length = IoUtil::receiveFrame(*socket, buffer, sizeof 
(buffer), flags);
-if (length <= 0 || ((flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) 
== Poco::Net::WebSocket::FRAME_OP_CLOSE))
-{
-_failure = "Failed to read child response to unit-memdump 
command.";
-return;
-}
-
-const std::string memory = LOOLProtocol::getFirstLine(buffer, length);
+const std::string memory = LOOLProtocol::getFirstLine(payload);
 if (!memory.compare(0,6,"Error:"))
 {
 _failure = memory;
@@ -84,9 +73,31 @@ public:
 Log::info("Got memory stats [" + memory + "].");
 Poco::StringTokenizer tokens(memory, " ");
 assert(tokens.count() == 2);
-totalPSS += atoi(tokens[0].c_str());
-totalDirty += atoi(tokens[1].c_str());
+_totalPSS += atoi(tokens[0].c_str());
+_totalDirty += atoi(tokens[1].c_str());
 }
+
+// Don't signal before wait.
+std::unique_lock lock(_mutex);
+_cv.notify_one();
+return true;
+}
+
+void getMemory(const std::shared_ptr ,
+   size_t , size_t )
+{
+std::unique_lock lock(_mutex);
+
+/// Fetch 

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

2016-05-16 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |3 ++-
 loolwsd/DocumentBroker.hpp |5 +++--
 loolwsd/LOOLWSD.cpp|6 +++---
 3 files changed, 8 insertions(+), 6 deletions(-)

New commits:
commit 7c76e4b6bcdd7da3e6985a77445c1db668c11734
Author: Ashod Nakashian 
Date:   Mon May 16 07:46:27 2016 -0400

loolwsd: MasterProcessSession splitting: using ClientSession

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index e3735f9..19eaa5b 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -18,6 +18,7 @@
 #include "Storage.hpp"
 #include "TileCache.hpp"
 #include "LOOLProtocol.hpp"
+#include "ClientSession.hpp"
 #include "PrisonerSession.hpp"
 
 using namespace LOOLProtocol;
@@ -314,7 +315,7 @@ void DocumentBroker::takeEditLock(const std::string& id)
 }
 }
 
-size_t DocumentBroker::addSession(std::shared_ptr& 
session)
+size_t DocumentBroker::addSession(std::shared_ptr& session)
 {
 const auto id = session->getId();
 const std::string aMessage = "session " + id + " " + _docKey + "\n";
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 20b9761..a41778d 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -117,6 +117,7 @@ private:
 };
 
 class PrisonerSession;
+class ClientSession;
 
 /// DocumentBroker is responsible for setting up a document
 /// in jail and brokering loading it from Storage
@@ -193,7 +194,7 @@ public:
 void takeEditLock(const std::string& id);
 
 /// Add a new session. Returns the new number of sessions.
-size_t addSession(std::shared_ptr& session);
+size_t addSession(std::shared_ptr& session);
 /// Connect a prison session to its client peer.
 bool connectPeers(std::shared_ptr& session);
 /// Removes a session by ID. Returns the new number of sessions.
@@ -229,7 +230,7 @@ private:
 std::string _filename;
 std::chrono::steady_clock::time_point _lastSaveTime;
 Poco::Timestamp _lastFileModifiedTime;
-std::map _sessions;
+std::map _sessions;
 std::unique_ptr _storage;
 std::unique_ptr _tileCache;
 std::atomic _markToDestroy;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 358c152..f6a6fe6 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -384,7 +384,7 @@ private:
 
 // Load the document.
 std::shared_ptr ws;
-auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws, docBroker, nullptr);
+auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws, docBroker, nullptr);
 
 // Request the child to connect to us and add this session.
 auto sessionsCount = docBroker->addSession(session);
@@ -610,13 +610,13 @@ private:
 
 // Above this point exceptions are safe and will auto-cleanup.
 // Below this, we need to cleanup internal references.
-std::shared_ptr session;
+std::shared_ptr session;
 try
 {
 // For ToClient sessions, we store incoming messages in a queue 
and have a separate
 // thread to pump them. This is to empty the queue when we get a 
"canceltiles" message.
 auto queue = std::make_shared();
-session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws, docBroker, queue);
+session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws, docBroker, queue);
 
 // Request the child to connect to us and add this session.
 auto sessionsCount = docBroker->addSession(session);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/DocumentBroker.hpp loolwsd/MasterProcessSession.cpp loolwsd/test loolwsd/TileCache.cpp loolwsd/TileCache.hpp

2016-05-15 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp   |   87 +++
 loolwsd/DocumentBroker.hpp   |3 -
 loolwsd/MasterProcessSession.cpp |   39 +++--
 loolwsd/TileCache.cpp|   62 ---
 loolwsd/TileCache.hpp|   14 +++---
 loolwsd/test/TileCacheTests.cpp  |9 ++--
 6 files changed, 73 insertions(+), 141 deletions(-)

New commits:
commit d18bca992c2774c2c7b41ae0999a7d5d30a8822c
Author: Ashod Nakashian 
Date:   Sun May 15 18:47:08 2016 -0400

loolwsd: use TileDesc instead of explicit values

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index fe09607..35af2c3 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -399,32 +399,15 @@ bool DocumentBroker::handleInput(const std::vector& 
payload)
 return true;
 }
 
-void DocumentBroker::handleTileRequest(int part, int width, int height, int 
tilePosX,
-   int tilePosY, int tileWidth, int 
tileHeight, int id,
+void DocumentBroker::handleTileRequest(const TileDesc& tile,
const 
std::shared_ptr& session)
 {
-Log::trace() << "Tile request for part: " << part << ", width: " << width 
<< ", height: " << height
- << ", tilePosX: " << tilePosX << ", tilePosY: " << tilePosY 
<< ", tileWidth: " << tileWidth
- << ", tileHeight: " << tileHeight << ", id: " << id << 
Log::end;
-
-std::ostringstream oss;
-oss << " part=" << part
-<< " width=" << width
-<< " height=" << height
-<< " tileposx=" << tilePosX
-<< " tileposy=" << tilePosY
-<< " tilewidth=" << tileWidth
-<< " tileheight=" << tileHeight;
-if (id >= 0)
-{
-oss << " id=" << id;
-}
-
-const std::string tileMsg = oss.str();
+const auto tileMsg = tile.serialize();
+Log::trace() << "Tile request for " << tileMsg << Log::end;
 
 std::unique_lock lock(_mutex);
 
-std::unique_ptr cachedTile = _tileCache->lookupTile(part, 
width, height, tilePosX, tilePosY, tileWidth, tileHeight);
+std::unique_ptr cachedTile = _tileCache->lookupTile(tile);
 
 if (cachedTile)
 {
@@ -435,7 +418,7 @@ void DocumentBroker::handleTileRequest(int part, int width, 
int height, int tile
 #endif
 
 std::vector output;
-output.reserve(4 * width * height);
+output.reserve(4 * tile.getWidth() * tile.getHeight());
 output.resize(response.size());
 std::memcpy(output.data(), response.data(), response.size());
 
@@ -452,12 +435,10 @@ void DocumentBroker::handleTileRequest(int part, int 
width, int height, int tile
 return;
 }
 
-if (tileCache().isTileBeingRenderedIfSoSubscribe(
-part, width, height, tilePosX, tilePosY, tileWidth,
-tileHeight, session))
+if (tileCache().isTileBeingRenderedIfSoSubscribe(tile, session))
 return;
 
-Log::debug() << "Sending render request for tile (" << part << ',' << 
tilePosX << ',' << tilePosY << ")." << Log::end;
+Log::debug() << "Sending render request for tile (" << tile.getPart() << 
',' << tile.getTilePosX() << ',' << tile.getTilePosY() << ")." << Log::end;
 
 // Forward to child to render.
 const std::string request = "tile " + tileMsg;
@@ -467,45 +448,29 @@ void DocumentBroker::handleTileRequest(int part, int 
width, int height, int tile
 void DocumentBroker::handleTileResponse(const std::vector& payload)
 {
 const std::string firstLine = getFirstLine(payload);
-Poco::StringTokenizer tokens(firstLine, " ", 
Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
-
-int part, width, height, tilePosX, tilePosY, tileWidth, tileHeight;
-if (tokens.count() < 8 ||
-!getTokenInteger(tokens[1], "part", part) ||
-!getTokenInteger(tokens[2], "width", width) ||
-!getTokenInteger(tokens[3], "height", height) ||
-!getTokenInteger(tokens[4], "tileposx", tilePosX) ||
-!getTokenInteger(tokens[5], "tileposy", tilePosY) ||
-!getTokenInteger(tokens[6], "tilewidth", tileWidth) ||
-!getTokenInteger(tokens[7], "tileheight", tileHeight))
-{
-//FIXME: Return error.
-//sendTextFrame("error: cmd=tile kind=syntax");
-Log::error("Invalid tile request [" + firstLine + "].");
-return;
-}
-
-size_t index = 8;
-int id = -1;
-if (tokens.count() > index && tokens[index].find("id") == 0)
+try
 {
-getTokenInteger(tokens[index], "id", id);
-++index;
-}
-
-const auto buffer = payload.data();
-const auto length = payload.size();
+auto tile = TileDesc::parse(firstLine);

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

2016-05-15 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   10 ++
 loolwsd/LOOLKit.cpp|   32 
 2 files changed, 14 insertions(+), 28 deletions(-)

New commits:
commit 249b5350a411ff7d30bf17185ad16fb2e60b477b
Author: Ashod Nakashian 
Date:   Sun May 15 10:18:11 2016 -0400

loolwsd: removed editlock kludge in tile processing

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index cf7d479..fe09607 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -420,9 +420,6 @@ void DocumentBroker::handleTileRequest(int part, int width, 
int height, int tile
 oss << " id=" << id;
 }
 
-// Piggyback editlock information to kit process.
-// We do not allow requests without editlock to change document parts
-oss << " editlock=" << (session->isEditLocked() ? "1" : "0");
 const std::string tileMsg = oss.str();
 
 std::unique_lock lock(_mutex);
@@ -481,7 +478,12 @@ void DocumentBroker::handleTileResponse(const 
std::vector& payload)
 !getTokenInteger(tokens[5], "tileposy", tilePosY) ||
 !getTokenInteger(tokens[6], "tilewidth", tileWidth) ||
 !getTokenInteger(tokens[7], "tileheight", tileHeight))
-assert(false);
+{
+//FIXME: Return error.
+//sendTextFrame("error: cmd=tile kind=syntax");
+Log::error("Invalid tile request [" + firstLine + "].");
+return;
+}
 
 size_t index = 8;
 int id = -1;
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 183768b..fb6b314 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -576,11 +576,10 @@ public:
 
 void renderTile(StringTokenizer& tokens, const 
std::shared_ptr& ws)
 {
+const auto tileMsg = Poco::cat(std::string(" "), tokens.begin() + 1, 
tokens.end());
 int part, width, height, tilePosX, tilePosY, tileWidth, tileHeight;
 
-// There would be another param, editlock=, as the last parameter.
-// For presentations, it would be followed by id=
-if (tokens.count() < 9 ||
+if (tokens.count() < 8 ||
 !getTokenInteger(tokens[1], "part", part) ||
 !getTokenInteger(tokens[2], "width", width) ||
 !getTokenInteger(tokens[3], "height", height) ||
@@ -591,7 +590,7 @@ public:
 {
 //FIXME: Return error.
 //sendTextFrame("error: cmd=tile kind=syntax");
-Log::error() << "Invalid tile request" << Log::end;
+Log::error("Invalid tile request [" + tileMsg + "].");
 return;
 }
 
@@ -605,12 +604,11 @@ public:
 {
 //FIXME: Return error.
 //sendTextFrame("error: cmd=tile kind=invalid");
-Log::error() << "Invalid tile request" << Log::end;
+Log::error("Invalid tile request [" + tileMsg + "].");
 return;
 }
 
 size_t index = 8;
-int editLock = -1;
 int id = -1;
 if (tokens.count() > index && tokens[index].find("id") == 0)
 {
@@ -618,20 +616,6 @@ public:
 ++index;
 }
 
-if (tokens.count() > index && tokens[index].find("editlock") == 0)
-{
-getTokenInteger(tokens[index], "editlock", editLock);
-++index;
-}
-
-// For time being, editlock information in tile requests is mandatory
-// till we have a better solution to handle multi-part documents
-if (editLock == -1)
-{
-Log::error("No editlock information found.");
-return;
-}
-
 std::unique_lock 
lock(ChildProcessSession::getLock());
 
 if (_loKitDocument == nullptr)
@@ -645,12 +629,11 @@ public:
 //_loKitDocument->pClass->setView(_loKitDocument, _viewId);
 
 // Send back the request with all optional parameters given in the 
request.
-std::string response = "tile: " + Poco::cat(std::string(" "), 
tokens.begin() + 1, tokens.end() - 1);
-
 #if ENABLE_DEBUG
-response += " renderid=" + Util::UniqueId();
+const std::string response = "tile: " + tileMsg + " renderid=" + 
Util::UniqueId() + "\n";
+#else
+const std::string response = "tile: " + tileMsg + "\n";
 #endif
-response += "\n";
 
 std::vector output;
 output.reserve(response.size() + (4 * width * height));
@@ -683,6 +666,7 @@ public:
 ws->sendFrame(nextmessage.data(), nextmessage.size());
 }
 
+Log::trace("Sending render-tile response for: " + response);
 ws->sendFrame(output.data(), length, WebSocket::FRAME_BINARY);
 }
 
___
Libreoffice-commits mailing list

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

2016-05-10 Thread Pranav Kant
 loolwsd/DocumentBroker.cpp   |   28 
 loolwsd/MasterProcessSession.cpp |   21 -
 loolwsd/MasterProcessSession.hpp |8 +---
 3 files changed, 49 insertions(+), 8 deletions(-)

New commits:
commit 55a85ddb33854ef18f950ba63a656eb5e15b04ed
Author: Pranav Kant 
Date:   Tue May 10 19:07:42 2016 +0530

bccu#1776: Fake double click after auto-saving

... just so that if we have the cursor before auto-saving, we
have it after save too (calc).

Change-Id: I3e6b1e41006c8fd9105d370b62ead4f45e50848c

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 9a4db8a..31be2ce 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -54,6 +54,16 @@ std::string getCachePath(const std::string& uri)
 Poco::DigestEngine::digestToHex(digestEngine.digest()).insert(3, 
"/").insert(2, "/").insert(1, "/"));
 }
 
+/// Return mouse commands
+std::string getMouseCommand(std::string type, long posX, long posY, int count)
+{
+return std::string("mouse type=" + type +
+   " x=" + std::to_string(posX) +
+   " y=" + std::to_string(posY) +
+   " count=" + std::to_string(count) +
+   " buttons=1 modifier=0");
+}
+
 }
 
 Poco::URI DocumentBroker::sanitizeURI(const std::string& uri)
@@ -284,13 +294,23 @@ bool DocumentBroker::sendUnoSave()
 // Invalidate the timestamp to force persisting.
 _lastFileModifiedTime.fromEpochTime(0);
 
+// Store the cursor position before saving, if visible
+long posX = -1;
+long posY = -1;
+if (sessionIt.second->isCursorVisible())
+{
+sessionIt.second->getCursorPos(posX, posY);
+}
+
 queue->put("uno .uno:Save");
 
-// Set calc cell mode back to edit mode
-// if we were in edit before save
-if (sessionIt.second->isCursorVisible())
+// Restore the cursor position, if visible, by a fake double 
click
+if (posX != -1 && posY != -1)
 {
-queue->put("uno .uno:SetInputMode");
+queue->put(getMouseCommand("buttondown", posX, posY, 1));
+queue->put(getMouseCommand("buttonup", posX, posY, 1));
+queue->put(getMouseCommand("buttondown", posX, posY, 2));
+queue->put(getMouseCommand("buttonup", posX, posY, 2));
 }
 
 return true;
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 3d5ee3c..87be145 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -175,9 +175,16 @@ bool MasterProcessSession::_handleInput(const char 
*buffer, int length)
 }
 }
 }
+else if (tokens.count() == 5 && tokens[0] == "invalidatecursor:")
+{
+peer->setCursorPos(std::stoi(tokens[1]), std::stoi(tokens[2]));
+}
 else if (tokens.count() == 2 && tokens[0] == "cursorvisible:")
 {
-peer->setCursorVisible(tokens[1] == "true");
+if (tokens[1] == "false")
+{
+peer->setCursorPos(-1, -1);
+}
 }
 }
 
@@ -654,4 +661,16 @@ bool MasterProcessSession::shutdownPeer(Poco::UInt16 
statusCode, const std::stri
 return peer != nullptr;
 }
 
+void MasterProcessSession::setCursorPos(long posX, long posY)
+{
+_cursorPosX = posX;
+_cursorPosY = posY;
+}
+
+void MasterProcessSession::getCursorPos(long& posX, long& posY)
+{
+posX = _cursorPosX;
+posY = _cursorPosY;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/MasterProcessSession.hpp b/loolwsd/MasterProcessSession.hpp
index 2472eb5..d2227e7 100644
--- a/loolwsd/MasterProcessSession.hpp
+++ b/loolwsd/MasterProcessSession.hpp
@@ -50,8 +50,9 @@ class MasterProcessSession final : public LOOLSession, public 
std::enable_shared
 void setEditLock(const bool value);
 void markEditLock(const bool value) { _bEditLock = value; }
 bool isEditLocked() const { return _bEditLock; }
-void setCursorVisible(const bool value) { _isCursorVisible = value; }
-bool isCursorVisible() { return _isCursorVisible; }
+void setCursorPos(const long posX, const long posY);
+void getCursorPos(long& posX, long& posY);
+bool isCursorVisible() { return _cursorPosX != -1 && _cursorPosY != -1; }
 
 bool shutdownPeer(Poco::UInt16 statusCode, const std::string& message);
 
@@ -88,7 +89,8 @@ public:
 
 int _curPart;
 int _loadPart;
-bool _isCursorVisible;
+long _cursorPosX;
+long _cursorPosY;
 /// Kind::ToClient instances store URLs of completed 

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

2016-05-09 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   10 --
 loolwsd/LOOLWSD.cpp|1 -
 2 files changed, 8 insertions(+), 3 deletions(-)

New commits:
commit e2f5f4514065385ffa8d24efa51f41217d140319
Author: Ashod Nakashian 
Date:   Mon May 9 21:18:58 2016 -0400

loolwsd: remove mark-to-destory when we no longer have a sole client

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 764c6ab..9a4db8a 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -223,7 +223,7 @@ bool DocumentBroker::autoSave(const bool force, const 
size_t waitTimeoutMs)
 
 // Remeber the last save time, since this is the predicate.
 const auto lastSaveTime = _lastSaveTime;
-Log::trace("Autosaving [" + _docKey + "].");
+Log::trace("Checking to autosave [" + _docKey + "].");
 
 bool sent = false;
 if (force)
@@ -292,6 +292,7 @@ bool DocumentBroker::sendUnoSave()
 {
 queue->put("uno .uno:SetInputMode");
 }
+
 return true;
 }
 }
@@ -322,11 +323,11 @@ void DocumentBroker::takeEditLock(const std::string& id)
 size_t DocumentBroker::addSession(std::shared_ptr& 
session)
 {
 const auto id = session->getId();
+const std::string aMessage = "session " + id + " " + _docKey + "\n";
 
 std::lock_guard lock(_mutex);
 
 // Request a new session from the child kit.
-const std::string aMessage = "session " + id + " " + _docKey + "\n";
 Log::debug("DocBroker to Child: " + aMessage.substr(0, aMessage.length() - 
1));
 _childProcess->getWebSocket()->sendFrame(aMessage.data(), aMessage.size());
 
@@ -341,6 +342,11 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session
 Log::debug("Giving editing lock to the first session [" + id + "].");
 _sessions.begin()->second->markEditLock(true);
 }
+else
+{
+assert(_sessions.size() > 1);
+_markToDestroy = false;
+}
 
 return _sessions.size();
 }
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 6aee539..787cb7a 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -539,7 +539,6 @@ private:
 docBroker = it->second;
 assert(docBroker);
 }
-docBrokersLock.unlock();
 }
 
 if (docBroker)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-05-09 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   22 +-
 1 file changed, 9 insertions(+), 13 deletions(-)

New commits:
commit ca22a79034cbf996f788303633297c9c11096143
Author: Ashod Nakashian 
Date:   Mon May 9 21:15:09 2016 -0400

loolwsd: simplify detection of file modification

To avoid persisting the same document many times over
we check the jailed file timestamp. This logic
doesn't need to be more complex than simply invalidating
the last timestamp upon issuing .uno:Save and setting
it to the file's actual timestamp upon persisting.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 7b1af96..764c6ab 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -177,23 +177,16 @@ bool DocumentBroker::save()
 
 const auto uri = _uriPublic.toString();
 
-// If we aren't potentially destroying just yet, and the file has been
-// modified within the past 10 seconds, skip saving.
-//
-// FIXME this is because currently the ChildProcessSession broadcasts the
-// unocommandresult, so we get called several times here, and have no real
-// possibility to distinguish who was the 1st caller.
-// The refactor to un-thread the ChildProcessSession, and move the
-// broadcasting up in the hierarchy (so that we can 'sniff' the
-// unocommandresult for .uno:Save at the place where it appears just once)
-// is planned post-release.
+// If we aren't potentially destroying just yet, and the file
+// timestamp hasn't changed, skip saving.
 const auto newFileModifiedTime = 
Poco::File(_storage->getLocalRootPath()).getLastModified();
-const auto elapsed = newFileModifiedTime - _lastFileModifiedTime;
-if (!canDestroy() && std::abs(elapsed) < 10 * 1000)
+if (!isMarkedToDestroy() && newFileModifiedTime == _lastFileModifiedTime)
 {
 // Nothing to do.
 Log::debug() << "Skipping unnecessary saving to URI [" << uri
- << "]. File last modified " << elapsed << " ms ago." << 
Log::end;
+ << "]. File last modified "
+ << _lastFileModifiedTime.elapsed() / 100
+ << " seconds ago." << Log::end;
 return true;
 }
 
@@ -288,6 +281,9 @@ bool DocumentBroker::sendUnoSave()
 auto queue = sessionIt.second->getQueue();
 if (queue)
 {
+// Invalidate the timestamp to force persisting.
+_lastFileModifiedTime.fromEpochTime(0);
+
 queue->put("uno .uno:Save");
 
 // Set calc cell mode back to edit mode
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-05-09 Thread Pranav Kant
 loolwsd/DocumentBroker.cpp   |7 +++
 loolwsd/MasterProcessSession.cpp |4 
 loolwsd/MasterProcessSession.hpp |3 +++
 3 files changed, 14 insertions(+)

New commits:
commit 5500b090167b46a9b02b465c0cce75abacde37f8
Author: Pranav Kant 
Date:   Mon May 9 21:50:43 2016 +0530

bccu#1776: Restore input mode if we are in one before saving

Change-Id: I46d57dce69777fdfe6afb95f9534b170972fe390

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index b51f872..7b1af96 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -289,6 +289,13 @@ bool DocumentBroker::sendUnoSave()
 if (queue)
 {
 queue->put("uno .uno:Save");
+
+// Set calc cell mode back to edit mode
+// if we were in edit before save
+if (sessionIt.second->isCursorVisible())
+{
+queue->put("uno .uno:SetInputMode");
+}
 return true;
 }
 }
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 6d24b1a..3d5ee3c 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -175,6 +175,10 @@ bool MasterProcessSession::_handleInput(const char 
*buffer, int length)
 }
 }
 }
+else if (tokens.count() == 2 && tokens[0] == "cursorvisible:")
+{
+peer->setCursorVisible(tokens[1] == "true");
+}
 }
 
 if (peer && !_isDocPasswordProtected)
diff --git a/loolwsd/MasterProcessSession.hpp b/loolwsd/MasterProcessSession.hpp
index 19a4788..2472eb5 100644
--- a/loolwsd/MasterProcessSession.hpp
+++ b/loolwsd/MasterProcessSession.hpp
@@ -50,6 +50,8 @@ class MasterProcessSession final : public LOOLSession, public 
std::enable_shared
 void setEditLock(const bool value);
 void markEditLock(const bool value) { _bEditLock = value; }
 bool isEditLocked() const { return _bEditLock; }
+void setCursorVisible(const bool value) { _isCursorVisible = value; }
+bool isCursorVisible() { return _isCursorVisible; }
 
 bool shutdownPeer(Poco::UInt16 statusCode, const std::string& message);
 
@@ -86,6 +88,7 @@ public:
 
 int _curPart;
 int _loadPart;
+bool _isCursorVisible;
 /// Kind::ToClient instances store URLs of completed 'save as' documents.
 MessageQueue _saveAsQueue;
 std::shared_ptr _docBroker;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-05-08 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   16 ++--
 loolwsd/LOOLWSD.cpp|5 +
 2 files changed, 11 insertions(+), 10 deletions(-)

New commits:
commit b06a07f6bc7149ffd497af5634e835f604d97d5f
Author: Ashod Nakashian 
Date:   Mon May 9 01:11:09 2016 -0400

loolwsd: auto-save checks modified state and logs decision

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index f0e6173..b51f872 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -219,19 +219,23 @@ bool DocumentBroker::save()
 
 bool DocumentBroker::autoSave(const bool force, const size_t waitTimeoutMs)
 {
-Log::trace("Autosaving [" + _docKey + "].");
-
 std::unique_lock lock(_mutex);
-if (_sessions.empty() || _storage == nullptr || !_isLoaded)
+if (_sessions.empty() || _storage == nullptr || !_isLoaded ||
+(!_isModified && !force))
 {
 // Nothing to do.
 Log::trace("Nothing to autosave [" + _docKey + "].");
 return true;
 }
 
+// Remeber the last save time, since this is the predicate.
+const auto lastSaveTime = _lastSaveTime;
+Log::trace("Autosaving [" + _docKey + "].");
+
 bool sent = false;
 if (force)
 {
+Log::trace("Sending forced save command for [" + _docKey + "].");
 sent = sendUnoSave();
 }
 else if (_isModified)
@@ -251,17 +255,17 @@ bool DocumentBroker::autoSave(const bool force, const 
size_t waitTimeoutMs)
 if (inactivityTimeMs >= IdleSaveDurationMs ||
 timeSinceLastSaveMs >= AutoSaveDurationMs)
 {
+Log::trace("Sending timed save command for [" + _docKey + "].");
 sent = sendUnoSave();
 }
 }
 
 if (sent && waitTimeoutMs > 0)
 {
-// Remeber the last save time, since this is the predicate.
-const auto lastSaveTime = _lastSaveTime;
-
+Log::trace("Waiting for save event for [" + _docKey + "].");
 if (_saveCV.wait_for(lock, std::chrono::milliseconds(waitTimeoutMs)) 
== std::cv_status::no_timeout)
 {
+Log::debug("Successfully persisted document [" + _docKey + "].");
 return true;
 }
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 25a3801..48b8d05 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1641,10 +1641,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 std::unique_lock 
docBrokersLock(docBrokersMutex);
 for (auto& brokerIt : docBrokers)
 {
-if (brokerIt.second->isModified())
-{
-brokerIt.second->autoSave(false, 0);
-}
+brokerIt.second->autoSave(false, 0);
 }
 }
 catch (const std::exception& exc)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-05-08 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

New commits:
commit 8f5f0ffdb1642f56a42e0075beb7429e754c7be0
Author: Ashod Nakashian 
Date:   Mon May 9 01:02:42 2016 -0400

loolwsd: don't persist documents again within 10 seconds

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index adde590..f0e6173 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -177,7 +177,7 @@ bool DocumentBroker::save()
 
 const auto uri = _uriPublic.toString();
 
-// If we aren't potentially destroying just yet, and the file hasn't been
+// If we aren't potentially destroying just yet, and the file has been
 // modified within the past 10 seconds, skip saving.
 //
 // FIXME this is because currently the ChildProcessSession broadcasts the
@@ -189,7 +189,7 @@ bool DocumentBroker::save()
 // is planned post-release.
 const auto newFileModifiedTime = 
Poco::File(_storage->getLocalRootPath()).getLastModified();
 const auto elapsed = newFileModifiedTime - _lastFileModifiedTime;
-if (!canDestroy() && std::abs(elapsed) > 10 * 1000 * 1000)
+if (!canDestroy() && std::abs(elapsed) < 10 * 1000)
 {
 // Nothing to do.
 Log::debug() << "Skipping unnecessary saving to URI [" << uri
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-05-08 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   16 
 loolwsd/LOOLWSD.cpp|   12 
 2 files changed, 16 insertions(+), 12 deletions(-)

New commits:
commit 702dd48f1f7f671d918fbadcf98fb4ae4743dbbe
Author: Ashod Nakashian 
Date:   Sun May 8 10:07:17 2016 -0400

loolwsd: safer document saving

Relying on the filesystem to tell us when the document
was last modified (to decide whether to upload to storage or not,)
proved unreliable.

Now we always upload to storage if there is only one client.
This both minimizes the risk and also avoids the file timestamp
check as a workaround to the problem of re-uploading documents
as many time as there were clients. Since with one client we
can only upload no more than once per save, which is reasonable.

Furthermore, when a client disconnects we auto-save automatically
as a matter of precaution. However, when there are other clients
still connected, we don't wait for the save to complete, rather
we let that job to the very last one.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 4c8591a..adde590 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -177,7 +177,9 @@ bool DocumentBroker::save()
 
 const auto uri = _uriPublic.toString();
 
-// If the file hasn't been modified within the past 10 seconds, skip 
saving.
+// If we aren't potentially destroying just yet, and the file hasn't been
+// modified within the past 10 seconds, skip saving.
+//
 // FIXME this is because currently the ChildProcessSession broadcasts the
 // unocommandresult, so we get called several times here, and have no real
 // possibility to distinguish who was the 1st caller.
@@ -187,10 +189,11 @@ bool DocumentBroker::save()
 // is planned post-release.
 const auto newFileModifiedTime = 
Poco::File(_storage->getLocalRootPath()).getLastModified();
 const auto elapsed = newFileModifiedTime - _lastFileModifiedTime;
-if (std::abs(elapsed) > 10 * 1000 * 1000)
+if (!canDestroy() && std::abs(elapsed) > 10 * 1000 * 1000)
 {
 // Nothing to do.
-Log::debug("Skipping unnecessary saving to URI [" + uri + "].");
+Log::debug() << "Skipping unnecessary saving to URI [" << uri
+ << "]. File last modified " << elapsed << " ms ago." << 
Log::end;
 return true;
 }
 
@@ -502,11 +505,8 @@ bool DocumentBroker::canDestroy()
 {
 std::unique_lock lock(_mutex);
 
-if (_sessions.size() == 1)
-{
-// Last view going away, can destroy.
-_markToDestroy = true;
-}
+// Last view going away, can destroy.
+_markToDestroy = (_sessions.size() <= 1);
 
 return _markToDestroy;
 }
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 37c71a9..25a3801 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -648,15 +648,19 @@ private:
 []() { session->closeFrame(); },
 []() { return TerminationFlag || 
!queueHandlerThread.isRunning(); });
 
-const bool canDestroy = docBroker->canDestroy();
-if (canDestroy && !session->_bLoadError)
+if (!session->_bLoadError)
 {
-Log::info("Shutdown of the last session, saving the document 
before tearing down.");
+// If we are the last, we must wait for the save to complete.
+const bool canDestroy = docBroker->canDestroy();
+if (canDestroy)
+{
+Log::info("Shutdown of the last session, saving the 
document before tearing down.");
+}
 
 // Use auto-save to save only when there are modifications 
since last save.
 // We also need to wait until the save notification reaches us
 // and Storage persists the document.
-if (!docBroker->autoSave(true, COMMAND_TIMEOUT_MS))
+if (!docBroker->autoSave(canDestroy, COMMAND_TIMEOUT_MS))
 {
 Log::error("Auto-save before closing failed.");
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-05-08 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |3 ++-
 loolwsd/IoUtil.cpp |2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

New commits:
commit 6f39c0f282a0fc405bc1ebc66cbbdce2b2255912
Author: Ashod Nakashian 
Date:   Sat May 7 09:45:57 2016 -0400

loolwsd: state the child PID which has no DocumentBroker

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index d6e686a..4c8591a 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -32,7 +32,8 @@ void ChildProcess::socketProcessor()
 return docBroker->handleInput(payload);
 }
 
-Log::warn("No DocumentBroker to handle child message: [" + 
LOOLProtocol::getAbbreviatedMessage(payload) + "].");
+Log::warn() << "Child " << this->_pid << " has no DocumentBroker 
to handle message: ["
+<< LOOLProtocol::getAbbreviatedMessage(payload) << 
"]." << Log::end;
 return true;
 },
 []() { },
diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp
index da69754..abe1b71 100644
--- a/loolwsd/IoUtil.cpp
+++ b/loolwsd/IoUtil.cpp
@@ -75,7 +75,7 @@ void SocketProcessor(const std::shared_ptr& ws,
 Log::info("SocketProcessor starting.");
 
 // Timeout given is in microseconds.
-const Poco::Timespan waitTime(POLL_TIMEOUT_MS * 1000);
+static const Poco::Timespan waitTime(POLL_TIMEOUT_MS * 1000);
 try
 {
 ws->setReceiveTimeout(0);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/LOOLKit.cpp loolwsd/TileCache.cpp loolwsd/TileCache.hpp

2016-05-05 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   10 +-
 loolwsd/LOOLKit.cpp|1 +
 loolwsd/TileCache.cpp  |   24 +++-
 loolwsd/TileCache.hpp  |2 +-
 4 files changed, 26 insertions(+), 11 deletions(-)

New commits:
commit 1643938a8e2e3f0c28280abb848bb072649607a3
Author: Ashod Nakashian 
Date:   Thu May 5 10:19:13 2016 -0400

loolwsd: support the tile id param when broadcasting tiles to subscribers

Obviously this is dangerous, since the id is not part of the
subscription key (the filename) so different clients could
have different ids on the same part, but in practice I
expect this not to happen. Though that clearly depends on
how clients use the id.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 9785b94..d6e686a 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -473,13 +473,21 @@ void DocumentBroker::handleTileResponse(const 
std::vector& payload)
 !getTokenInteger(tokens[7], "tileheight", tileHeight))
 assert(false);
 
+size_t index = 8;
+int id = -1;
+if (tokens.count() > index && tokens[index].find("id") == 0)
+{
+getTokenInteger(tokens[index], "id", id);
+++index;
+}
+
 const auto buffer = payload.data();
 const auto length = payload.size();
 
 if(firstLine.size() < static_cast(length) - 1)
 {
 tileCache().saveTile(part, width, height, tilePosX, tilePosY, 
tileWidth, tileHeight, buffer + firstLine.size() + 1, length - firstLine.size() 
- 1);
-tileCache().notifyAndRemoveSubscribers(part, width, height, tilePosX, 
tilePosY, tileWidth, tileHeight);
+tileCache().notifyAndRemoveSubscribers(part, width, height, tilePosX, 
tilePosY, tileWidth, tileHeight, id);
 }
 else
 {
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 4a65094..cebb4c9 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -632,6 +632,7 @@ public:
 //if (_multiView)
 //_loKitDocument->pClass->setView(_loKitDocument, _viewId);
 
+// Send back the request with all optional parameters given in the 
request.
 std::string response = "tile: " + Poco::cat(std::string(" "), 
tokens.begin() + 1, tokens.end() - 1);
 
 #if ENABLE_DEBUG
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 3242344..961e7bd 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -330,7 +330,7 @@ void TileCache::saveLastModified(const Timestamp& timestamp)
 modTimeFile.close();
 }
 
-void TileCache::notifyAndRemoveSubscribers(int part, int width, int height, 
int tilePosX, int tilePosY, int tileWidth, int tileHeight)
+void TileCache::notifyAndRemoveSubscribers(int part, int width, int height, 
int tilePosX, int tilePosY, int tileWidth, int tileHeight, int id)
 {
 std::unique_lock lock(_tilesBeingRenderedMutex);
 
@@ -338,14 +338,20 @@ void TileCache::notifyAndRemoveSubscribers(int part, int 
width, int height, int
 if (!tileBeingRendered)
 return;
 
-const std::string message("tile "
-  " part=" + std::to_string(part) +
-  " width=" + std::to_string(width) +
-  " height=" + std::to_string(height) +
-  " tileposx=" + std::to_string(tilePosX) +
-  " tileposy=" + std::to_string(tilePosY) +
-  " tilewidth=" + std::to_string(tileWidth) +
-  " tileheight=" + std::to_string(tileHeight));
+std::ostringstream oss;
+oss << "tile part=" << part
+<< " width=" << width
+<< " height=" << height
+<< " tileposx=" << tilePosX
+<< " tileposy=" << tilePosY
+<< " tilewidth=" << tileWidth
+<< " tileheight=" << tileHeight;
+if (id >= 0)
+{
+oss << " id=" << id;
+}
+
+const std::string message = oss.str();
 Log::debug("Sending tile message to subscribers: " + message);
 
 for (const auto& i: tileBeingRendered->_subscribers)
diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp
index 6df3b39..270d679 100644
--- a/loolwsd/TileCache.hpp
+++ b/loolwsd/TileCache.hpp
@@ -45,7 +45,7 @@ public:
 
 void saveTile(int part, int width, int height, int tilePosX, int tilePosY, 
int tileWidth, int tileHeight, const char *data, size_t size);
 
-void notifyAndRemoveSubscribers(int part, int width, int height, int 
tilePosX, int tilePosY, int tileWidth, int tileHeight);
+void notifyAndRemoveSubscribers(int part, int width, int height, int 
tilePosX, int tilePosY, int tileWidth, int tileHeight, int id);
 
 std::string getTextFile(const 

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

2016-05-05 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp   |7 +++
 loolwsd/LOOLKit.cpp  |   20 +---
 loolwsd/MasterProcessSession.cpp |3 ++-
 3 files changed, 22 insertions(+), 8 deletions(-)

New commits:
commit 346a063d0a0001c2a54e4c8f2f8310784c0028ba
Author: Ashod Nakashian 
Date:   Thu May 5 10:18:31 2016 -0400

loolwsd: fix regression to handling tile command

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 048e6a1..9785b94 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -413,8 +413,7 @@ void DocumentBroker::handleTileRequest(int part, int width, 
int height, int tile
 // Piggyback editlock information to kit process.
 // We do not allow requests without editlock to change document parts
 oss << " editlock=" << (session->isEditLocked() ? "1" : "0");
-
-std::string tileMsg = oss.str();
+const std::string tileMsg = oss.str();
 
 std::unique_lock lock(_mutex);
 
@@ -423,9 +422,9 @@ void DocumentBroker::handleTileRequest(int part, int width, 
int height, int tile
 if (cachedTile)
 {
 #if ENABLE_DEBUG
-std::string response = "tile:" + tileMsg + " renderid=cached\n";
+const std::string response = "tile:" + tileMsg + " renderid=cached\n";
 #else
-std::string response = "tile:" + tileMsg + "\n";
+const std::string response = "tile:" + tileMsg + "\n";
 #endif
 
 std::vector output;
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 318ae60..4a65094 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -576,7 +576,7 @@ public:
 
 void renderTile(StringTokenizer& tokens, const 
std::shared_ptr& ws)
 {
-int part, width, height, tilePosX, tilePosY, tileWidth, tileHeight, 
editLock;
+int part, width, height, tilePosX, tilePosY, tileWidth, tileHeight;
 
 if (tokens.count() < 9 ||
 !getTokenInteger(tokens[1], "part", part) ||
@@ -585,8 +585,7 @@ public:
 !getTokenInteger(tokens[4], "tileposx", tilePosX) ||
 !getTokenInteger(tokens[5], "tileposy", tilePosY) ||
 !getTokenInteger(tokens[6], "tilewidth", tileWidth) ||
-!getTokenInteger(tokens[7], "tileheight", tileHeight) ||
-!getTokenInteger(tokens[8], "editlock", editLock))
+!getTokenInteger(tokens[7], "tileheight", tileHeight))
 {
 //FIXME: Return error.
 //sendTextFrame("error: cmd=tile kind=syntax");
@@ -606,6 +605,21 @@ public:
 return;
 }
 
+int editLock = 0;
+size_t index = 8;
+if (tokens.count() > index && tokens[index].find("editlock") == 0)
+{
+getTokenInteger(tokens[index], "editlock", editLock);
+++index;
+}
+
+int id = -1;
+if (tokens.count() > index && tokens[index].find("id") == 0)
+{
+getTokenInteger(tokens[index], "id", id);
+++index;
+}
+
 std::unique_lock 
lock(ChildProcessSession::getLock());
 
 if (_loKitDocument == nullptr)
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 733b43b..6d24b1a 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -530,7 +530,7 @@ void MasterProcessSession::sendTile(const char * 
/*buffer*/, int /*length*/, Str
 
 void MasterProcessSession::sendCombinedTiles(const char* /*buffer*/, int 
/*length*/, StringTokenizer& tokens)
 {
-int part, pixelWidth, pixelHeight, tileWidth, tileHeight, id = -1;
+int part, pixelWidth, pixelHeight, tileWidth, tileHeight;
 std::string tilePositionsX, tilePositionsY;
 if (tokens.count() < 8 ||
 !getTokenInteger(tokens[1], "part", part) ||
@@ -561,6 +561,7 @@ void MasterProcessSession::sendCombinedTiles(const char* 
/*buffer*/, int /*lengt
 ++index;
 }
 
+int id = -1;
 if (tokens.count() > index && tokens[index].find("id") == 0)
 {
 getTokenInteger(tokens[index], "id", id);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-05-04 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp   |9 +++--
 loolwsd/DocumentBroker.hpp   |2 +-
 loolwsd/MasterProcessSession.cpp |   29 +++--
 3 files changed, 31 insertions(+), 9 deletions(-)

New commits:
commit 909c996a6d2b052a395621be6de06ecc4cbdfba9
Author: Ashod Nakashian 
Date:   Wed May 4 22:18:39 2016 -0400

bccu#1774: poor API never fails to frustrate

The tile and tilecombine messages apparently have optional
appendages at their rear ends. Not one, but two (at least).

While the first (timestamp) seems to be truely optional
(in the sense that leaving it out doesn't break anything,)
the same can't be said of the second (id).

For Impress slides this id is used to identify the slide
to which the tile belongs. Or rather the slide being
rendered, as it seems meaningful only for the slide
thumbnails.

Previously the complete arguments of tile were copied
verbatim from the input to the output (i.e. back to the
client) and so any extra payload was also echoed back.

But when id is missing (when expected) loleaflet not
only fails to show these tiles (understandably,) but
it also fails to show the scrollbar for said slide
thumbnails altogether!

With the new logic to move the tile communication to
the child socket instead of the clients, the arguments
are parsed and then serialized back in the response.
So all fields must be explicitly known in advance.

This change is necessary because tilecombine is broken
to tile commands and so both share common code. This
means that echoing back the request verbatim will
break loleaflet since tilecombine arguments (which
is a list) is not a valid response (which has the
format of tile). So the internal representation
has to be something neutral/common.

The fix is to parse the timestamp and id only when
provided and to echo back the id only in that case.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 040e7b0..612becd 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -390,12 +390,12 @@ bool DocumentBroker::handleInput(const std::vector& 
payload)
 }
 
 void DocumentBroker::handleTileRequest(int part, int width, int height, int 
tilePosX,
-   int tilePosY, int tileWidth, int 
tileHeight,
+   int tilePosY, int tileWidth, int 
tileHeight, int id,
const 
std::shared_ptr& session)
 {
 Log::trace() << "Tile request for part: " << part << ", width: " << width 
<< ", height: " << height
  << ", tilePosX: " << tilePosX << ", tilePosY: " << tilePosY 
<< ", tileWidth: " << tileWidth
- << ", tileHeight: " << tileHeight << Log::end;
+ << ", tileHeight: " << tileHeight << ", id: " << id << 
Log::end;
 
 std::ostringstream oss;
 oss << " part=" << part
@@ -405,6 +405,11 @@ void DocumentBroker::handleTileRequest(int part, int 
width, int height, int tile
 << " tileposy=" << tilePosY
 << " tilewidth=" << tileWidth
 << " tileheight=" << tileHeight;
+if (id >= 0)
+{
+oss << " id=" << id;
+}
+
 std::string tileMsg = oss.str();
 
 std::unique_lock lock(_mutex);
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index bf8df26..ca22419 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -198,7 +198,7 @@ public:
 size_t removeSession(const std::string& id);
 
 void handleTileRequest(int part, int width, int height, int tilePosX,
-   int tilePosY, int tileWidth, int tileHeight,
+   int tilePosY, int tileWidth, int tileHeight, int id,
const std::shared_ptr& 
session);
 
 void handleTileResponse(const std::vector& payload);
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 28c7ada..733b43b 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -491,7 +491,7 @@ void MasterProcessSession::sendFontRendering(const char 
*buffer, int length, Str
 
 void MasterProcessSession::sendTile(const char * /*buffer*/, int /*length*/, 
StringTokenizer& tokens)
 {
-int part, width, height, tilePosX, tilePosY, tileWidth, tileHeight;
+int part, width, height, tilePosX, tilePosY, tileWidth, tileHeight, id = 
-1;
 if (tokens.count() < 8 ||
 !getTokenInteger(tokens[1], "part", part) ||
 !getTokenInteger(tokens[2], "width", width) ||
@@ -517,13 +517,20 @@ void 

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

2016-05-04 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   35 ++-
 1 file changed, 14 insertions(+), 21 deletions(-)

New commits:
commit fedb3f520a5841ac946a5283a4a8193f08c7bd18
Author: Ashod Nakashian 
Date:   Wed May 4 21:14:39 2016 -0400

loolwsd: factored out common tile message

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 9f5c0a3..e3b2b0e 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -397,26 +397,27 @@ void DocumentBroker::handleTileRequest(int part, int 
width, int height, int tile
  << ", tilePosX: " << tilePosX << ", tilePosY: " << tilePosY 
<< ", tileWidth: " << tileWidth
  << ", tileHeight: " << tileHeight << Log::end;
 
+std::ostringstream oss;
+oss << " part=" << part
+<< " width=" << width
+<< " height=" << height
+<< " tileposx=" << tilePosX
+<< " tileposy=" << tilePosY
+<< " tilewidth=" << tileWidth
+<< " tileheight=" << tileHeight;
+std::string tileMsg = oss.str();
+
 std::unique_lock lock(_mutex);
 
 std::unique_ptr cachedTile = tileCache().lookupTile(part, 
width, height, tilePosX, tilePosY, tileWidth, tileHeight);
 
 if (cachedTile)
 {
-std::ostringstream oss;
-oss << "tile: part=" << part
-<< " width=" << width
-<< " height=" << height
-<< " tileposx=" << tilePosX
-<< " tileposy=" << tilePosY
-<< " tilewidth=" << tileWidth
-<< " tileheight=" << tileHeight;
-
 #if ENABLE_DEBUG
-oss << " renderid=cached";
+std::string response = "tile:" + tileMsg + " renderid=cached\n";
+#else
+std::string response = "tile:" + tileMsg + "\n";
 #endif
-oss << "\n";
-const auto response = oss.str();
 
 std::vector output;
 output.reserve(4 * width * height);
@@ -442,15 +443,7 @@ void DocumentBroker::handleTileRequest(int part, int 
width, int height, int tile
 return;
 
 // Forward to child to render.
-std::ostringstream oss;
-oss << "tile part=" << part
-<< " width=" << width
-<< " height=" << height
-<< " tileposx=" << tilePosX
-<< " tileposy=" << tilePosY
-<< " tilewidth=" << tileWidth
-<< " tileheight=" << tileHeight;
-const std::string request = oss.str();
+const std::string request = "tile " + tileMsg;
 
 _childProcess->getWebSocket()->sendFrame(request.data(), request.size());
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-05-04 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |5 +++--
 loolwsd/TileCache.cpp  |4 +++-
 2 files changed, 6 insertions(+), 3 deletions(-)

New commits:
commit cd8d48e6bb78cb616e63da3bd37d0dfb39967ff3
Author: Ashod Nakashian 
Date:   Wed May 4 22:05:09 2016 -0400

loolwsd: tile logs

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index e3b2b0e..040e7b0 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -409,7 +409,7 @@ void DocumentBroker::handleTileRequest(int part, int width, 
int height, int tile
 
 std::unique_lock lock(_mutex);
 
-std::unique_ptr cachedTile = tileCache().lookupTile(part, 
width, height, tilePosX, tilePosY, tileWidth, tileHeight);
+std::unique_ptr cachedTile = _tileCache->lookupTile(part, 
width, height, tilePosX, tilePosY, tileWidth, tileHeight);
 
 if (cachedTile)
 {
@@ -442,9 +442,10 @@ void DocumentBroker::handleTileRequest(int part, int 
width, int height, int tile
 tileHeight, session))
 return;
 
+Log::debug() << "Sending render request for tile (" << part << ',' << 
tilePosX << ',' << tilePosY << ")." << Log::end;
+
 // Forward to child to render.
 const std::string request = "tile " + tileMsg;
-
 _childProcess->getWebSocket()->sendFrame(request.data(), request.size());
 }
 
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index bdf726e..3242344 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -377,7 +377,7 @@ bool TileCache::isTileBeingRenderedIfSoSubscribe(int part, 
int width, int height
 
 if (tileBeingRendered)
 {
-Log::debug("Tile is already being rendered, subscribing");
+Log::debug() << "Tile (" << part << ',' << tilePosX << ',' << tilePosY 
<< ") is already being rendered, subscribing." << Log::end;
 assert(subscriber->getKind() == LOOLSession::Kind::ToClient);
 
 for (const auto  : tileBeingRendered->_subscribers)
@@ -394,6 +394,8 @@ bool TileCache::isTileBeingRenderedIfSoSubscribe(int part, 
int width, int height
 }
 else
 {
+Log::debug() << "Tile (" << part << ',' << tilePosX << ',' << tilePosY 
<< ") needs rendering, subscribing." << Log::end;
+
 const std::string cachedName = cacheFileName(part, width, height, 
tilePosX, tilePosY, tileWidth, tileHeight);
 
 assert(_tilesBeingRendered.find(cachedName) == 
_tilesBeingRendered.end());
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-05-04 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |1 +
 loolwsd/DocumentBroker.hpp |   21 -
 loolwsd/LOOLWSD.cpp|1 +
 3 files changed, 22 insertions(+), 1 deletion(-)

New commits:
commit ff0d4a3a9119de9bd65ef03c7ae32ba54d532b14
Author: Ashod Nakashian 
Date:   Mon May 2 07:21:30 2016 -0400

Revert "Revert "loolwsd: establish communication with...

...child from DocumentBroker""

Restore the communication with child from DocumentBroker.

This reverts commit 20ab6e8ae70254557e5bff242dbb9d5861fa946c.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 5dbdf46..0cc1975 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -79,6 +79,7 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 {
 assert(!_docKey.empty());
 assert(!_childRoot.empty());
+
 Log::info("DocumentBroker [" + _uriPublic.toString() + "] created. DocKey: 
[" + _docKey + "]");
 }
 
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 965ced3..49b5d32 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -39,8 +40,10 @@ public:
 /// @param ws is the control WebSocket to the child.
 ChildProcess(const Poco::Process::PID pid, const 
std::shared_ptr& ws) :
 _pid(pid),
-_ws(ws)
+_ws(ws),
+_stop(false)
 {
+_thread = std::thread([this]() { this->socketProcessor(); });
 Log::info("ChildProcess ctor [" + std::to_string(_pid) + "].");
 }
 
@@ -57,8 +60,16 @@ public:
 }
 }
 
+void setDocumentBroker(const std::shared_ptr& docBroker)
+{
+_docBroker = docBroker;
+}
+
 void close(const bool rude)
 {
+_stop = true;
+IoUtil::shutdownWebSocket(_ws);
+_thread.join();
 _ws.reset();
 if (_pid != -1)
 {
@@ -95,8 +106,14 @@ public:
 }
 
 private:
+void socketProcessor();
+
+private:
 Poco::Process::PID _pid;
 std::shared_ptr _ws;
+std::weak_ptr _docBroker;
+std::thread _thread;
+std::atomic _stop;
 };
 
 /// DocumentBroker is responsible for setting up a document
@@ -184,6 +201,8 @@ public:
 bool canDestroy();
 bool isMarkedToDestroy() const { return _markToDestroy; }
 
+bool handleInput(const std::vector& payload);
+
 private:
 
 /// Sends the .uno:Save command to LoKit.
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index d4d8dcc..5af6964 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -558,6 +558,7 @@ private:
 // Set one we just created.
 Log::debug("New DocumentBroker for docKey [" + docKey + "].");
 docBroker = std::make_shared(uriPublic, docKey, 
LOOLWSD::ChildRoot, child);
+child->setDocumentBroker(docBroker);
 }
 
 // Validate the broker.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-05-02 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   17 ++---
 1 file changed, 6 insertions(+), 11 deletions(-)

New commits:
commit 431bab28248c8fbfc561c8e5aba530e6c97e8e2d
Author: Ashod Nakashian 
Date:   Mon May 2 22:58:53 2016 -0400

loolwsd: fix autosave regression

Autosave should only save when the user has been idle
for a certain time, or the periodic autosave time elapses.

The document is considered for autosave only when it's modified.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 0d88d75..5dbdf46 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -204,11 +204,11 @@ bool DocumentBroker::autoSave(const bool force, const 
size_t waitTimeoutMs)
 }
 
 bool sent = false;
-if (force || _isModified)
+if (force)
 {
 sent = sendUnoSave();
 }
-else
+else if (_isModified)
 {
 // Find the most recent activity.
 double inactivityTimeMs = std::numeric_limits::max();
@@ -221,16 +221,11 @@ bool DocumentBroker::autoSave(const bool force, const 
size_t waitTimeoutMs)
 const auto timeSinceLastSaveMs = getTimeSinceLastSaveMs();
 Log::trace("Time since last save is " + 
std::to_string((int)timeSinceLastSaveMs) + " ms.");
 
-// There has been some editing since we saved last?
-if (inactivityTimeMs < timeSinceLastSaveMs)
+// Either we've been idle long enough, or it's auto-save time.
+if (inactivityTimeMs >= IdleSaveDurationMs ||
+timeSinceLastSaveMs >= AutoSaveDurationMs)
 {
-// Either we've been idle long enough, or it's auto-save time.
-// Or we are asked to save anyway.
-if (inactivityTimeMs >= IdleSaveDurationMs ||
-timeSinceLastSaveMs >= AutoSaveDurationMs)
-{
-sent = sendUnoSave();
-}
+sent = sendUnoSave();
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/LOOLWSD.cpp loolwsd/TileCache.cpp loolwsd/Util.hpp

2016-05-02 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |2 +-
 loolwsd/LOOLWSD.cpp|2 +-
 loolwsd/TileCache.cpp  |4 ++--
 loolwsd/Util.hpp   |7 +++
 4 files changed, 11 insertions(+), 4 deletions(-)

New commits:
commit 6c57e9be4d9992ef1ab32b667e808c6143936ebf
Author: Ashod Nakashian 
Date:   Mon May 2 19:17:46 2016 -0400

loolwsd: helper to assert a lock is already taken

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 8f50e32..0d88d75 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -253,7 +253,7 @@ bool DocumentBroker::autoSave(const bool force, const 
size_t waitTimeoutMs)
 bool DocumentBroker::sendUnoSave()
 {
 Log::info("Autosave triggered for doc [" + _docKey + "].");
-assert(!_mutex.try_lock());
+Util::assertIsLocked(_mutex);
 
 // Save using session holding the edit-lock
 for (auto& sessionIt: _sessions)
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 5de9afc..6f9aee5 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -167,7 +167,7 @@ static int careerSpanSeconds = 0;
 
 static void forkChildren(const int number)
 {
-assert(!newChildrenMutex.try_lock()); // check it is held.
+Util::assertIsLocked(newChildrenMutex);
 
 if (number > 0)
 {
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 6d42158..856c684 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -89,7 +89,7 @@ std::shared_ptr 
TileCache::findTileBeingRendered(i
 {
 const std::string cachedName = cacheFileName(part, width, height, 
tilePosX, tilePosY, tileWidth, tileHeight);
 
-assert(!_tilesBeingRenderedMutex.try_lock());
+Util::assertIsLocked(_tilesBeingRenderedMutex);
 
 const auto tile = _tilesBeingRendered.find(cachedName);
 return (tile != _tilesBeingRendered.end() ? tile->second : nullptr);
@@ -99,7 +99,7 @@ void TileCache::forgetTileBeingRendered(int part, int width, 
int height, int til
 {
 const std::string cachedName = cacheFileName(part, width, height, 
tilePosX, tilePosY, tileWidth, tileHeight);
 
-assert(!_tilesBeingRenderedMutex.try_lock());
+Util::assertIsLocked(_tilesBeingRenderedMutex);
 
 assert(_tilesBeingRendered.find(cachedName) != _tilesBeingRendered.end());
 _tilesBeingRendered.erase(cachedName);
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index 00cf54c..28cdb94 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -56,6 +56,13 @@ namespace Util
   int bufferWidth, int bufferHeight,
   std::vector& output, 
LibreOfficeKitTileMode mode);
 
+/// Assert that a lock is already taken.
+template 
+void assertIsLocked(T& lock)
+{
+assert(!lock.try_lock());
+}
+
 /// Safely remove a file or directory.
 /// Supresses exception when the file is already removed.
 /// This can happen when there is a race (unavoidable) or when
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-05-02 Thread Jan Holesovsky
 loolwsd/DocumentBroker.cpp |   30 --
 loolwsd/DocumentBroker.hpp |   20 +---
 loolwsd/LOOLWSD.cpp|1 -
 3 files changed, 1 insertion(+), 50 deletions(-)

New commits:
commit 20ab6e8ae70254557e5bff242dbb9d5861fa946c
Author: Jan Holesovsky 
Date:   Mon May 2 11:49:03 2016 +0200

Revert "loolwsd: establish communication with child from DocumentBroker"

Unfortunately this causes a deadlock in the unit tests.

This reverts commit 10417c9447ec1d34a8a599daf28ac4339a37930a.

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 52e30f0..8f50e32 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -17,27 +17,6 @@
 #include "LOOLWSD.hpp"
 #include "Storage.hpp"
 #include "TileCache.hpp"
-#include "LOOLProtocol.hpp"
-
-using namespace LOOLProtocol;
-
-void ChildProcess::socketProcessor()
-{
-IoUtil::SocketProcessor(_ws,
-[this](const std::vector& payload)
-{
-auto docBroker = this->_docBroker.lock();
-if (docBroker)
-{
-return docBroker->handleInput(payload);
-}
-
-Log::warn("No DocumentBroker to handle child message: [" + 
LOOLProtocol::getAbbreviatedMessage(payload) + "].");
-return true;
-},
-[]() { },
-[this]() { return !!this->_stop; });
-}
 
 namespace
 {
@@ -100,7 +79,6 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 {
 assert(!_docKey.empty());
 assert(!_childRoot.empty());
-
 Log::info("DocumentBroker [" + _uriPublic.toString() + "] created. DocKey: 
[" + _docKey + "]");
 }
 
@@ -381,14 +359,6 @@ size_t DocumentBroker::removeSession(const std::string& id)
 return _sessions.size();
 }
 
-bool DocumentBroker::handleInput(const std::vector& payload)
-{
-Log::trace("DocumentBroker got child message: [" + 
LOOLProtocol::getAbbreviatedMessage(payload) + "].");
-
-//TODO: Handle message.
-return true;
-}
-
 bool DocumentBroker::canDestroy()
 {
 std::unique_lock lock(_mutex);
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index efdedc3..965ced3 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -17,7 +17,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include 
@@ -40,10 +39,8 @@ public:
 /// @param ws is the control WebSocket to the child.
 ChildProcess(const Poco::Process::PID pid, const 
std::shared_ptr& ws) :
 _pid(pid),
-_ws(ws),
-_stop(false)
+_ws(ws)
 {
-_thread = std::thread([this]() { this->socketProcessor(); });
 Log::info("ChildProcess ctor [" + std::to_string(_pid) + "].");
 }
 
@@ -60,15 +57,8 @@ public:
 }
 }
 
-void setDocumentBroker(const std::shared_ptr& docBroker)
-{
-_docBroker = docBroker;
-}
-
 void close(const bool rude)
 {
-_stop = true;
-_thread.join();
 _ws.reset();
 if (_pid != -1)
 {
@@ -105,14 +95,8 @@ public:
 }
 
 private:
-void socketProcessor();
-
-private:
 Poco::Process::PID _pid;
 std::shared_ptr _ws;
-std::weak_ptr _docBroker;
-std::thread _thread;
-std::atomic _stop;
 };
 
 /// DocumentBroker is responsible for setting up a document
@@ -200,8 +184,6 @@ public:
 bool canDestroy();
 bool isMarkedToDestroy() const { return _markToDestroy; }
 
-bool handleInput(const std::vector& payload);
-
 private:
 
 /// Sends the .uno:Save command to LoKit.
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 1266417..5de9afc 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -533,7 +533,6 @@ private:
 // Set one we just created.
 Log::debug("New DocumentBroker for docKey [" + docKey + "].");
 docBroker = std::make_shared(uriPublic, docKey, 
LOOLWSD::ChildRoot, child);
-child->setDocumentBroker(docBroker);
 }
 
 // Validate the broker.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-05-01 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   30 ++
 loolwsd/DocumentBroker.hpp |   20 +++-
 loolwsd/LOOLWSD.cpp|1 +
 3 files changed, 50 insertions(+), 1 deletion(-)

New commits:
commit 10417c9447ec1d34a8a599daf28ac4339a37930a
Author: Ashod Nakashian 
Date:   Sun May 1 20:39:36 2016 -0400

loolwsd: establish communication with child from DocumentBroker

The WebSocket that each child created with WSD is not used
except to request the child to load the document a client
requests. Beyond this point, it was not utilized for anything.

In fact, there are no handlers in WSD for messages coming
from the child; it is a one-way communication.

That is until now. With the move to unify communication
between WSD and each child, DocumentBroker can now
receive and handle messages from its ChildProcess.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 8f50e32..52e30f0 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -17,6 +17,27 @@
 #include "LOOLWSD.hpp"
 #include "Storage.hpp"
 #include "TileCache.hpp"
+#include "LOOLProtocol.hpp"
+
+using namespace LOOLProtocol;
+
+void ChildProcess::socketProcessor()
+{
+IoUtil::SocketProcessor(_ws,
+[this](const std::vector& payload)
+{
+auto docBroker = this->_docBroker.lock();
+if (docBroker)
+{
+return docBroker->handleInput(payload);
+}
+
+Log::warn("No DocumentBroker to handle child message: [" + 
LOOLProtocol::getAbbreviatedMessage(payload) + "].");
+return true;
+},
+[]() { },
+[this]() { return !!this->_stop; });
+}
 
 namespace
 {
@@ -79,6 +100,7 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 {
 assert(!_docKey.empty());
 assert(!_childRoot.empty());
+
 Log::info("DocumentBroker [" + _uriPublic.toString() + "] created. DocKey: 
[" + _docKey + "]");
 }
 
@@ -359,6 +381,14 @@ size_t DocumentBroker::removeSession(const std::string& id)
 return _sessions.size();
 }
 
+bool DocumentBroker::handleInput(const std::vector& payload)
+{
+Log::trace("DocumentBroker got child message: [" + 
LOOLProtocol::getAbbreviatedMessage(payload) + "].");
+
+//TODO: Handle message.
+return true;
+}
+
 bool DocumentBroker::canDestroy()
 {
 std::unique_lock lock(_mutex);
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 965ced3..efdedc3 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -39,8 +40,10 @@ public:
 /// @param ws is the control WebSocket to the child.
 ChildProcess(const Poco::Process::PID pid, const 
std::shared_ptr& ws) :
 _pid(pid),
-_ws(ws)
+_ws(ws),
+_stop(false)
 {
+_thread = std::thread([this]() { this->socketProcessor(); });
 Log::info("ChildProcess ctor [" + std::to_string(_pid) + "].");
 }
 
@@ -57,8 +60,15 @@ public:
 }
 }
 
+void setDocumentBroker(const std::shared_ptr& docBroker)
+{
+_docBroker = docBroker;
+}
+
 void close(const bool rude)
 {
+_stop = true;
+_thread.join();
 _ws.reset();
 if (_pid != -1)
 {
@@ -95,8 +105,14 @@ public:
 }
 
 private:
+void socketProcessor();
+
+private:
 Poco::Process::PID _pid;
 std::shared_ptr _ws;
+std::weak_ptr _docBroker;
+std::thread _thread;
+std::atomic _stop;
 };
 
 /// DocumentBroker is responsible for setting up a document
@@ -184,6 +200,8 @@ public:
 bool canDestroy();
 bool isMarkedToDestroy() const { return _markToDestroy; }
 
+bool handleInput(const std::vector& payload);
+
 private:
 
 /// Sends the .uno:Save command to LoKit.
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 5de9afc..1266417 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -533,6 +533,7 @@ private:
 // Set one we just created.
 Log::debug("New DocumentBroker for docKey [" + docKey + "].");
 docBroker = std::make_shared(uriPublic, docKey, 
LOOLWSD::ChildRoot, child);
+child->setDocumentBroker(docBroker);
 }
 
 // Validate the broker.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-30 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp   |8 +---
 loolwsd/DocumentBroker.hpp   |3 +++
 loolwsd/MasterProcessSession.cpp |2 ++
 3 files changed, 10 insertions(+), 3 deletions(-)

New commits:
commit bdfda58386b7bf8a92ad6e362e8d0687ee8e00ad
Author: Ashod Nakashian 
Date:   Fri Apr 29 23:07:09 2016 -0400

loolwsd: don't autosave when document not loaded

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index aa110cc..8f50e32 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -74,6 +74,7 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 _childProcess(childProcess),
 _lastSaveTime(std::chrono::steady_clock::now()),
 _markToDestroy(false),
+_isLoaded(false),
 _isModified(false)
 {
 assert(!_docKey.empty());
@@ -195,10 +196,11 @@ bool DocumentBroker::autoSave(const bool force, const 
size_t waitTimeoutMs)
 Log::trace("Autosaving [" + _docKey + "].");
 
 std::unique_lock lock(_mutex);
-if (_sessions.empty())
+if (_sessions.empty() || _storage == nullptr || !_isLoaded)
 {
-// Shouldn't happen.
-return false;
+// Nothing to do.
+Log::trace("Nothing to autosave [" + _docKey + "].");
+return true;
 }
 
 bool sent = false;
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 3a2e4d5..9bf290b 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -151,6 +151,8 @@ public:
 
 /// Loads a document from the public URI into the jail.
 bool load(const std::string& jailId);
+bool isLoaded() const { return _isLoaded; }
+void setLoaded() { _isLoaded = true; }
 
 /// Save the document to Storage if needs persisting.
 bool save();
@@ -226,6 +228,7 @@ private:
 std::unique_ptr _storage;
 std::unique_ptr _tileCache;
 std::atomic _markToDestroy;
+bool _isLoaded;
 bool _isModified;
 mutable std::mutex _mutex;
 std::condition_variable _saveCV;
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index c1fa22d..8d07645 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -200,6 +200,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, 
int length)
 }
 else if (tokens[0] == "status:")
 {
+_docBroker->setLoaded();
 _docBroker->tileCache().saveTextFile(std::string(buffer, 
length), "status.txt");
 
 // Forward the status response to the client.
@@ -411,6 +412,7 @@ bool MasterProcessSession::getStatus(const char *buffer, 
int length)
 Log::trace("Dispatching child to handle [getStatus].");
 dispatchChild();
 }
+
 forwardToPeer(buffer, length);
 return true;
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-28 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

New commits:
commit 2efaa6e06b212740abcb89ce26ad9ab8d585d204
Author: Ashod Nakashian 
Date:   Wed Apr 27 20:52:32 2016 -0400

loolwsd: save documents when timestamp is within 10 seconds

Due to filesystem timestamp precision and other factors
we assume a timestamp match within 10 seconds to mean
the document has been recently saved and store it.

A document has to have an older than 10 seconds
modified timestamp compared to our last timestamp
to be deemed unchanged in the interim and skipped
from storing again.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 69728cb..ac1ed91 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -152,8 +152,11 @@ bool DocumentBroker::save()
 std::unique_lock lock(_saveMutex);
 
 const auto uri = _uriPublic.toString();
+
+// If the file hasn't been modified within the past 10 seconds, skip 
saving.
 const auto newFileModifiedTime = 
Poco::File(_storage->getLocalRootPath()).getLastModified();
-if (newFileModifiedTime == _lastFileModifiedTime)
+const auto elapsed = newFileModifiedTime - _lastFileModifiedTime;
+if (std::abs(elapsed) > 10 * 1000 * 1000)
 {
 // Nothing to do.
 Log::debug("Skipping unnecessary saving to URI [" + uri + "].");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-26 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   26 +++---
 loolwsd/DocumentBroker.hpp |1 +
 2 files changed, 20 insertions(+), 7 deletions(-)

New commits:
commit d4aa547d3c185a7e2868652fa902549c280cfd2b
Author: Ashod Nakashian 
Date:   Mon Apr 25 20:44:24 2016 -0400

loolwsd: avoid persisting excessively

When multiple users have a document open,
save notficiations are broadcast to all.
Each session then tries to store the document
to the Storage when only the first should suffice.

A new file modified-time member tracks the file's
timestamp and only persists when it changes,
thereby avoid excessive stores.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index fc7d887..e7fb11f 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -127,17 +127,20 @@ bool DocumentBroker::load(const std::string& jailId)
 
 Log::info("jailPath: " + jailPath.toString() + ", jailRoot: " + jailRoot);
 
-auto storage = StorageBase::create("", "", _uriPublic);
+auto storage = StorageBase::create(jailRoot, jailPath.toString(), 
_uriPublic);
 if (storage)
 {
 const auto fileInfo = storage->getFileInfo(_uriPublic);
-_tileCache.reset(new TileCache(_uriPublic.toString(), 
fileInfo._modifiedTime, _cacheRoot));
 _filename = fileInfo._filename;
-_storage = StorageBase::create(jailRoot, jailPath.toString(), 
_uriPublic);
 
-const auto localPath = _storage->loadStorageFileToLocal();
+const auto localPath = storage->loadStorageFileToLocal();
 _uriJailed = Poco::URI(Poco::URI("file://"), localPath);
 
+// Use the local temp file's timestamp.
+_lastFileModifiedTime = 
Poco::File(storage->getLocalRootPath()).getLastModified();
+_tileCache.reset(new TileCache(_uriPublic.toString(), 
_lastFileModifiedTime, _cacheRoot));
+
+_storage.reset(storage.release());
 return true;
 }
 
@@ -149,18 +152,27 @@ bool DocumentBroker::save()
 std::unique_lock lock(_saveMutex);
 
 const auto uri = _uriPublic.toString();
+const auto newFileModifiedTime = 
Poco::File(_storage->getLocalRootPath()).getLastModified();
+if (newFileModifiedTime == _lastFileModifiedTime)
+{
+// Nothing to do.
+Log::debug("Skipping unnecessary saving to URI [" + uri + "].");
+return true;
+}
+
 Log::debug("Saving to URI [" + uri + "].");
 
 assert(_storage && _tileCache);
 if (_storage->saveLocalFileToStorage())
 {
 _isModified = false;
-_lastSaveTime = std::chrono::steady_clock::now();
 _tileCache->setUnsavedChanges(false);
+const auto fileInfo = _storage->getFileInfo(_uriPublic);
+_lastFileModifiedTime = newFileModifiedTime;
+_tileCache->saveLastModified(_lastFileModifiedTime);
+_lastSaveTime = std::chrono::steady_clock::now();
 Log::debug("Saved to URI [" + uri + "] and updated tile cache.");
 _saveCV.notify_all();
-const auto fileInfo = _storage->getFileInfo(_uriPublic);
-_tileCache->saveLastModified(fileInfo._modifiedTime);
 return true;
 }
 
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 0abf3f1..1ef6df0 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -213,6 +213,7 @@ private:
 std::string _jailId;
 std::string _filename;
 std::chrono::steady_clock::time_point _lastSaveTime;
+Poco::Timestamp _lastFileModifiedTime;
 std::map _sessions;
 std::unique_ptr _storage;
 std::unique_ptr _tileCache;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-24 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   17 +++
 loolwsd/DocumentBroker.hpp |2 
 loolwsd/LOOLWSD.cpp|  106 -
 3 files changed, 48 insertions(+), 77 deletions(-)

New commits:
commit 4f7b911066bd29d5901b2724b85aae77258b73eb
Author: Ashod Nakashian 
Date:   Sun Apr 24 22:09:13 2016 -0400

loolwsd: simplified the bridging between client and prisoner sessions

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 31de15e..fc7d887 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -292,6 +292,23 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session
 return _sessions.size();
 }
 
+bool DocumentBroker::connectPeers(std::shared_ptr& 
session)
+{
+const auto id = session->getId();
+
+std::lock_guard lock(_mutex);
+
+auto it = _sessions.find(id);
+if (it != _sessions.end())
+{
+it->second->setPeer(session);
+session->setPeer(it->second);
+return true;
+}
+
+return false;
+}
+
 size_t DocumentBroker::removeSession(const std::string& id)
 {
 std::lock_guard lock(_mutex);
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index dcf2d2a..5a5298f 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -194,6 +194,8 @@ public:
 
 /// Add a new session. Returns the new number of sessions.
 size_t addSession(std::shared_ptr& session);
+/// Connect a prison session to its client peer.
+bool connectPeers(std::shared_ptr& session);
 /// Removes a session by ID. Returns the new number of sessions.
 size_t removeSession(const std::string& id);
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 675444e..068f25c 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -271,51 +271,28 @@ public:
 class ClientRequestHandler: public HTTPRequestHandler
 {
 private:
-
-static bool waitBridgeCompleted(const 
std::shared_ptr& clientSession,
-const std::shared_ptr& 
docBroker)
+static void waitBridgeCompleted(const 
std::shared_ptr& session)
 {
-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 [" << session->getId() << 
"] to connect." << Log::end;
+AvailableChildSessionCV.wait_for(
+lock,
+std::chrono::milliseconds(COMMAND_TIMEOUT_MS),
+[, ]
+{
+return (isFound = 
AvailableChildSessions.find(session->getId()) != AvailableChildSessions.end());
+});
 
-Log::debug() << "Waiting for client session [" << 
clientSession->getId() << "] to connect." << Log::end;
-while (!TerminationFlag && retries-- && !isFound)
-{
-AvailableChildSessionCV.wait_for(
-lock,
-std::chrono::milliseconds(COMMAND_TIMEOUT_MS),
-[, ]
-{
-return (isFound = 
AvailableChildSessions.find(clientSession->getId()) != 
AvailableChildSessions.end());
-});
-
-if (!isFound)
-{
-//FIXME: outdated!
-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)
+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() + ".");
+// Let the client know we can't serve now.
+Log::error(session->getName() + ": Failed to connect to lokit 
process. Client cannot serve now.");
+throw 
WebSocketErrorMessageException(SERVICE_UNAVALABLE_INTERNAL_ERROR);
 }
 
-return isFound;
+Log::debug("Waiting child session permission, done!");
+AvailableChildSessions.erase(session->getId());
  

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

2016-04-24 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

New commits:
commit 6b1a3115b23f4eb33304d911cff806be4f101bd6
Author: Ashod Nakashian 
Date:   Sun Apr 24 12:40:23 2016 -0400

loolwsd: request new session from child before storing session

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 84b2a32..31de15e 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -272,6 +272,11 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session
 
 std::lock_guard lock(_mutex);
 
+// Request a new session from the child kit.
+const std::string aMessage = "session " + id + " " + _docKey + "\n";
+Log::debug("DocBroker to Child: " + aMessage.substr(0, aMessage.length() - 
1));
+_childProcess->getWebSocket()->sendFrame(aMessage.data(), aMessage.size());
+
 auto ret = _sessions.emplace(id, session);
 if (!ret.second)
 {
@@ -284,12 +289,6 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session
 session->sendTextFrame("editlock: 1");
 }
 
-// Request a new session from the child kit.
-const std::string aMessage = "session " + id + " " + _docKey + "\n";
-Log::debug("DocBroker to Child: " + aMessage.substr(0, aMessage.length() - 
1));
-//FIXME: The socket could be broken, child dead, etc. Must recover!
-_childProcess->getWebSocket()->sendFrame(aMessage.data(), aMessage.size());
-
 return _sessions.size();
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-24 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |1 +
 loolwsd/test/httpcrashtest.cpp |6 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

New commits:
commit 48bdc1e97a49479113fc3d71bdb8a07e9dd827c9
Author: Ashod Nakashian 
Date:   Sat Apr 23 16:00:09 2016 -0400

loolwsd: silence unused-result gcc error

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index deab8fc..b749f77 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -287,6 +287,7 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session
 // Request a new session from the child kit.
 const std::string aMessage = "session " + id + " " + _docKey + "\n";
 Log::debug("DocBroker to Child: " + aMessage.substr(0, aMessage.length() - 
1));
+//FIXME: The socket could be broken, child dead, etc. Must recover!
 _childProcess->getWebSocket()->sendFrame(aMessage.data(), aMessage.size());
 
 return _sessions.size();
diff --git a/loolwsd/test/httpcrashtest.cpp b/loolwsd/test/httpcrashtest.cpp
index 63d2c87..4169ebd 100644
--- a/loolwsd/test/httpcrashtest.cpp
+++ b/loolwsd/test/httpcrashtest.cpp
@@ -140,7 +140,11 @@ void HTTPCrashTest::testCrashKit()
 Poco::StringTokenizer tokens(statString, " ");
 if (tokens.count() > 3 && tokens[1] == "(loolkit)")
 {
-std::system(killLOKit.c_str());
+const auto res = std::system(killLOKit.c_str());
+if (res != 0)
+{
+std::cerr << "exit " + std::to_string(res) + " 
from " + killLOKit << std::endl;
+}
 }
 }
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-21 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp   |4 +++-
 loolwsd/DocumentBroker.hpp   |3 +++
 loolwsd/LOOLWSD.cpp  |5 -
 loolwsd/MasterProcessSession.cpp |   11 +++
 4 files changed, 21 insertions(+), 2 deletions(-)

New commits:
commit bde67c99344751702116e3409d96b52db07b15e8
Author: Ashod Nakashian 
Date:   Fri Apr 22 00:11:24 2016 -0400

loolwsd: track document modified state to avoid unnecessary auto-saving

This also avoids the feedback loop that results from the kit
thinking the previously inactive client is now active and
sending commands (.uno:Save).

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 10776b3..5a21bad 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -73,7 +73,8 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 _cacheRoot(getCachePath(uriPublic.toString())),
 _lastSaveTime(std::chrono::steady_clock::now()),
 _childProcess(childProcess),
-_markToDestroy(false)
+_markToDestroy(false),
+_isModified(false)
 {
 assert(!_docKey.empty());
 assert(!_childRoot.empty());
@@ -153,6 +154,7 @@ bool DocumentBroker::save()
 assert(_storage && _tileCache);
 if (_storage->saveLocalFileToStorage())
 {
+_isModified = false;
 _lastSaveTime = std::chrono::steady_clock::now();
 _tileCache->documentSaved();
 Log::debug("Saved to URI [" + uri + "] and updated tile cache.");
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 2a1e73d..b696a65 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -177,6 +177,8 @@ public:
 // Called when the last view is going out.
 bool canDestroy();
 bool isMarkedToDestroy() const { return _markToDestroy; }
+bool isModified() const { return _isModified; }
+void setModified(const bool value) { _isModified = value; }
 
 private:
 const Poco::URI _uriPublic;
@@ -192,6 +194,7 @@ private:
 std::unique_ptr _tileCache;
 std::shared_ptr _childProcess;
 bool _markToDestroy;
+bool _isModified;
 mutable std::mutex _mutex;
 std::condition_variable _saveCV;
 std::mutex _saveMutex;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index e6886a4..6a377fc 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1594,7 +1594,10 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 std::unique_lock 
docBrokersLock(docBrokersMutex);
 for (auto& brokerIt : docBrokers)
 {
-brokerIt.second->autoSave(false);
+if (brokerIt.second->isModified())
+{
+brokerIt.second->autoSave(false);
+}
 }
 }
 catch (const std::exception& exc)
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 1fa0a03..99f143e 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -164,6 +164,17 @@ bool MasterProcessSession::_handleInput(const char 
*buffer, int length)
 
 return true;
 }
+else if (tokens.count() == 2 && tokens[0] == "statechanged:")
+{
+StringTokenizer stateTokens(tokens[1], "=", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
+if (stateTokens.count() == 2 && stateTokens[0] == 
".uno:ModifiedStatus")
+{
+if (_docBroker)
+{
+_docBroker->setModified(stateTokens[1] == "true");
+}
+}
+}
 }
 
 if (peer && !_isDocPasswordProtected)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/Storage.cpp loolwsd/Storage.hpp

2016-04-19 Thread Miklos Vajna
 loolwsd/DocumentBroker.cpp |4 ++--
 loolwsd/Storage.cpp|6 +++---
 loolwsd/Storage.hpp|8 
 3 files changed, 9 insertions(+), 9 deletions(-)

New commits:
commit 17de53981e25828813cb0268c2f2f4a03d439b5e
Author: Miklos Vajna 
Date:   Tue Apr 19 09:10:07 2016 +0200

Storage: fix missing underscore for non-static members

Change-Id: Ibde55358c9640344e8bb4e6e24b287b1e7d8c6b5

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 75f3440..10776b3 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -130,8 +130,8 @@ bool DocumentBroker::load(const std::string& jailId)
 if (storage)
 {
 const auto fileInfo = storage->getFileInfo(_uriPublic);
-_tileCache.reset(new TileCache(_uriPublic.toString(), 
fileInfo.ModifiedTime, _cacheRoot));
-_filename = fileInfo.Filename;
+_tileCache.reset(new TileCache(_uriPublic.toString(), 
fileInfo._modifiedTime, _cacheRoot));
+_filename = fileInfo._filename;
 _storage = StorageBase::create(jailRoot, jailPath.toString(), 
_uriPublic);
 
 const auto localPath = _storage->loadStorageFileToLocal();
diff --git a/loolwsd/Storage.cpp b/loolwsd/Storage.cpp
index 309748d..41c8830 100644
--- a/loolwsd/Storage.cpp
+++ b/loolwsd/Storage.cpp
@@ -253,7 +253,7 @@ std::string WopiStorage::loadStorageFileToLocal()
 Log::info("Downloading URI [" + _uri + "].");
 
 _fileInfo = getFileInfo(Poco::URI(_uri));
-if (_fileInfo.Size == 0 && _fileInfo.Filename.empty())
+if (_fileInfo._size == 0 && _fileInfo._filename.empty())
 {
 //TODO: Should throw a more appropriate exception.
 throw std::runtime_error("Failed to load file from storage.");
@@ -286,7 +286,7 @@ std::string WopiStorage::loadStorageFileToLocal()
 
 logger << Log::end;
 
-_jailedFilePath = Poco::Path(getLocalRootPath(), 
_fileInfo.Filename).toString();
+_jailedFilePath = Poco::Path(getLocalRootPath(), 
_fileInfo._filename).toString();
 std::ofstream ofs(_jailedFilePath);
 std::copy(std::istreambuf_iterator(rs),
   std::istreambuf_iterator(),
@@ -298,7 +298,7 @@ std::string WopiStorage::loadStorageFileToLocal()
 << response.getStatus() << " " << response.getReason() << 
Log::end;
 
 // Now return the jailed path.
-return Poco::Path(_jailPath, _fileInfo.Filename).toString();
+return Poco::Path(_jailPath, _fileInfo._filename).toString();
 }
 
 bool WopiStorage::saveLocalFileToStorage()
diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp
index 564663c..84aa8a2 100644
--- a/loolwsd/Storage.hpp
+++ b/loolwsd/Storage.hpp
@@ -30,12 +30,12 @@ public:
 public:
 bool isValid() const
 {
-return !Filename.empty() && Size > 0;
+return !_filename.empty() && _size > 0;
 }
 
-std::string Filename;
-Poco::Timestamp ModifiedTime;
-size_t Size;
+std::string _filename;
+Poco::Timestamp _modifiedTime;
+size_t _size;
 };
 
 /// localStorePath the absolute root path of the chroot.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-17 Thread Ashod Nakashian
 loolwsd/DocumentBroker.cpp |   22 +-
 loolwsd/DocumentBroker.hpp |5 -
 loolwsd/LOOLWSD.cpp|   33 +++--
 3 files changed, 56 insertions(+), 4 deletions(-)

New commits:
commit b933988a5976e1a621dde7f4d2b0f57b34cd58cd
Author: Ashod Nakashian 
Date:   Sun Apr 17 23:29:03 2016 -0400

loolwsd: flag and wait if document is unloading before relaoding

When a new view is created on a document that is
in the process of unloading, all sorts of things
can go wrong. This is especially problematic when
the document needs to be saved before unloading,
which takes significantly longer than otherwise.

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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 7fdb7b3..75f3440 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -72,7 +72,8 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
 _childRoot(childRoot),
 _cacheRoot(getCachePath(uriPublic.toString())),
 _lastSaveTime(std::chrono::steady_clock::now()),
-_childProcess(childProcess)
+_childProcess(childProcess),
+_markToDestroy(false)
 {
 assert(!_docKey.empty());
 assert(!_childRoot.empty());
@@ -102,6 +103,12 @@ bool DocumentBroker::load(const std::string& jailId)
 
 std::unique_lock lock(_mutex);
 
+if (_markToDestroy)
+{
+// Tearing down.
+return false;
+}
+
 if (_storage)
 {
 // Already loaded. Nothing to do.
@@ -307,4 +314,17 @@ size_t DocumentBroker::removeSession(const std::string& id)
 return _sessions.size();
 }
 
+bool DocumentBroker::canDestroy()
+{
+std::unique_lock lock(_mutex);
+
+if (_sessions.size() == 1)
+{
+// Last view going away, can destroy.
+_markToDestroy = true;
+}
+
+return _markToDestroy;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 260a78d..2a1e73d 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -174,7 +174,9 @@ public:
 /// Removes a session by ID. Returns the new number of sessions.
 size_t removeSession(const std::string& id);
 
-void kill() { _childProcess->close(true); };
+// Called when the last view is going out.
+bool canDestroy();
+bool isMarkedToDestroy() const { return _markToDestroy; }
 
 private:
 const Poco::URI _uriPublic;
@@ -189,6 +191,7 @@ private:
 std::unique_ptr _storage;
 std::unique_ptr _tileCache;
 std::shared_ptr _childProcess;
+bool _markToDestroy;
 mutable std::mutex _mutex;
 std::condition_variable _saveCV;
 std::mutex _saveMutex;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 7f833fb..0313a1a 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -494,8 +494,33 @@ private:
 Log::debug("Found DocumentBroker for docKey [" + docKey + "].");
 docBroker = it->second;
 assert(docBroker);
+
+// If this document is going out, wait.
+if (docBroker->isMarkedToDestroy())
+{
+Log::debug("Document [" + docKey + "] is marked to destroy, 
waiting to load.");
+const auto timeout = POLL_TIMEOUT_MS / 2;
+for (size_t i = 0; i < COMMAND_TIMEOUT_MS / timeout; ++i)
+{
+docBrokersLock.unlock();
+
std::this_thread::sleep_for(std::chrono::milliseconds(timeout));
+docBrokersLock.lock();
+if (docBrokers.find(docKey) == docBrokers.end())
+{
+docBroker.reset();
+break;
+}
+}
+
+if (docBroker)
+{
+// Still here, but marked to destroy.
+throw std::runtime_error("Cannot load a view to document 
while unloading.");
+}
+}
 }
-else
+
+if (!docBroker)
 {
 // Request a kit process for this doc.
 auto child = getNewChild();
@@ -554,7 +579,11 @@ private:
 },
 []() { return TerminationFlag; });
 
-if (docBroker->getSessionsCount() == 1 && !session->_bLoadError)
+docBrokersLock.lock();
+const bool canDestroy = docBroker->canDestroy();
+docBrokersLock.unlock();
+
+if (canDestroy && !session->_bLoadError)
 {
 Log::info("Shutdown of the last session, saving the document 
before tearing down.");
 
___
Libreoffice-commits mailing list

  1   2   >