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

2016-01-06 Thread Ashod Nakashian
 loolwsd/LOOLKit.cpp  |2 -
 loolwsd/LOOLWSD.cpp  |   66 +++
 loolwsd/QueueHandler.hpp |   16 ++-
 3 files changed, 15 insertions(+), 69 deletions(-)

New commits:
commit f9cfdd902152bde395ce2289b072e19cf1073073
Author: Ashod Nakashian 
Date:   Wed Jan 6 08:38:21 2016 -0500

loolwsd: reuse QueueHandler

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

diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index c352422..d468739 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -396,7 +396,7 @@ public:
 _session->sendTextFrame(hello);
 
 TileQueue queue;
-QueueHandler handler(queue, _session);
+QueueHandler handler(queue, _session, "kit_queue_" + 
_session->getId());
 
 Thread queueHandlerThread;
 queueHandlerThread.start(handler);
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 259b97e..03dc308 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -108,7 +108,7 @@ DEALINGS IN THE SOFTWARE.
 #include "MasterProcessSession.hpp"
 #include "ChildProcessSession.hpp"
 #include "LOOLWSD.hpp"
-#include "MessageQueue.hpp"
+#include "QueueHandler.hpp"
 #include "Util.hpp"
 
 using namespace LOOLProtocol;
@@ -151,58 +151,6 @@ using Poco::NamedMutex;
 using Poco::ProcessHandle;
 using Poco::URI;
 
-class QueueHandler: public Runnable
-{
-public:
-QueueHandler(MessageQueue& queue):
-_queue(queue)
-{
-}
-
-void setSession(std::shared_ptr session)
-{
-_session = session;
-}
-
-void run() override
-{
-static const std::string thread_name = "wsd_queue";
-#ifdef __linux
-if (prctl(PR_SET_NAME, reinterpret_cast(thread_name.c_str()), 0, 0, 0) != 0)
-Log::error("Cannot set thread name to " + thread_name + ".");
-#endif
-Log::debug("Thread [" + thread_name + "] started.");
-
-try
-{
-while (true)
-{
-const std::string input = _queue.get();
-if (input == "eof")
-break;
-if (!_session->handleInput(input.c_str(), input.size()))
-break;
-}
-}
-catch (const std::exception& exc)
-{
-Log::error(std::string("Exception: ") + exc.what());
-raise(SIGABRT);
-}
-catch (...)
-{
-Log::error("Unexpected Exception.");
-raise(SIGABRT);
-}
-
-Log::debug("Thread [" + thread_name + "] finished.");
-}
-
-private:
-std::shared_ptr _session;
-MessageQueue& _queue;
-};
-
 /// Handles the filename part of the convert-to POST request payload.
 class ConvertToPartHandler : public Poco::Net::PartHandler
 {
@@ -473,11 +421,6 @@ public:
 return;
 }
 
-BasicTileQueue queue;
-Thread queueHandlerThread;
-QueueHandler handler(queue);
-Poco::Timespan waitTime(POLL_TIMEOUT);
-
 try
 {
 auto ws = std::make_shared(request, response);
@@ -488,7 +431,10 @@ public:
 // For ToClient sessions, we store incoming messages in a queue 
and have a separate
 // thread that handles them. This is so that we can empty the 
queue when we get a
 // "canceltiles" message.
-handler.setSession(session);
+BasicTileQueue queue;
+QueueHandler handler(queue, session, "wsd_queue_" + 
session->getId());
+
+Thread queueHandlerThread;
 queueHandlerThread.start(handler);
 
 SocketProcessor(ws, response, [, ](const char* data, 
const int size, const bool singleLine)
@@ -540,8 +486,6 @@ public:
 #endif
 Log::debug("Thread [" + thread_name + "] started.");
 
-Poco::Timespan waitTime(POLL_TIMEOUT);
-
 try
 {
 auto ws = std::make_shared(request, response);
diff --git a/loolwsd/QueueHandler.hpp b/loolwsd/QueueHandler.hpp
index 5d07b9a..5111382 100644
--- a/loolwsd/QueueHandler.hpp
+++ b/loolwsd/QueueHandler.hpp
@@ -18,20 +18,21 @@
 class QueueHandler: public Poco::Runnable
 {
 public:
-QueueHandler(MessageQueue& queue, const std::shared_ptr& 
session):
+QueueHandler(MessageQueue& queue, const std::shared_ptr& 
session,
+ const std::string& name):
 _queue(queue),
-_session(session)
+_session(session),
+_name(name)
 {
 }
 
 void run() override
 {
-static const std::string thread_name = "kit_queue_" + 
_session->getId();
 #ifdef __linux
-if (prctl(PR_SET_NAME, reinterpret_cast(thread_name.c_str()), 0, 0, 0) != 0)
-Log::error("Cannot set thread name to " + 

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

2016-01-06 Thread Ashod Nakashian
 loolwsd/LOOLKit.cpp  |6 +-
 loolwsd/LOOLWSD.cpp  |   31 ++-
 loolwsd/QueueHandler.hpp |2 --
 3 files changed, 31 insertions(+), 8 deletions(-)

New commits:
commit 7bf3fe843a62061deff2f6c2f269c6713e4861f6
Author: Ashod Nakashian 
Date:   Wed Jan 6 09:13:21 2016 -0500

loolwsd: more exception handling

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

diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index d468739..6c765ab 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -432,7 +432,7 @@ public:
 }
 catch (const Exception& exc)
 {
-Log::error() << exc.displayText()
+Log::error() << "Error: " << exc.displayText()
  << (exc.nested() ? " (" + exc.nested()->displayText() 
+ ")" : "")
  << Log::end;
 }
@@ -440,6 +440,10 @@ public:
 {
 Log::error(std::string("Exception: ") + exc.what());
 }
+catch (...)
+{
+Log::error("Unexpected Exception.");
+}
 
 Log::debug("Thread [" + thread_name + "] finished.");
 }
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 979bbb4..2669011 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -445,7 +445,8 @@ public:
 // FIXME: There is a race here when a request A gets in 
the queue and
 // is processed _after_ a later request B, because B gets 
processed
 // synchronously and A is waiting in the queue thread.
-// Fix is to push everything into the queue.
+// The fix is to push everything into the queue
+// (i.e. change MessageQueue to vector).
 if (singleLine)
 {
 const std::string firstLine = getFirstLine(data, size);
@@ -462,9 +463,19 @@ public:
 queue.put("eof");
 queueHandlerThread.join();
 }
-catch (const IOException& exc)
+catch (const Exception& exc)
 {
-Log::error("IOException: " + exc.message());
+Log::error() << "Error: " << exc.displayText()
+ << (exc.nested() ? " (" + exc.nested()->displayText() 
+ ")" : "")
+ << Log::end;
+}
+catch (const std::exception& exc)
+{
+Log::error(std::string("Exception: ") + exc.what());
+}
+catch (...)
+{
+Log::error("Unexpected Exception.");
 }
 
 Log::debug("Thread [" + thread_name + "] finished.");
@@ -501,9 +512,19 @@ public:
 return session->handleInput(data, size);
 });
 }
-catch (const IOException& exc)
+catch (const Exception& exc)
+{
+Log::error() << "Error: " << exc.displayText()
+ << (exc.nested() ? " (" + exc.nested()->displayText() 
+ ")" : "")
+ << Log::end;
+}
+catch (const std::exception& exc)
+{
+Log::error(std::string("Exception: ") + exc.what());
+}
+catch (...)
 {
-Log::error("IOException: " + exc.message());
+Log::error("Unexpected Exception.");
 }
 
 Log::debug("Thread [" + thread_name + "] finished.");
diff --git a/loolwsd/QueueHandler.hpp b/loolwsd/QueueHandler.hpp
index 5111382..759c175 100644
--- a/loolwsd/QueueHandler.hpp
+++ b/loolwsd/QueueHandler.hpp
@@ -48,12 +48,10 @@ public:
 catch (const std::exception& exc)
 {
 Log::error(std::string("Exception: ") + exc.what());
-raise(SIGABRT);
 }
 catch (...)
 {
 Log::error("Unexpected Exception.");
-raise(SIGABRT);
 }
 
 Log::debug("Thread [" + _name + "] finished.");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits