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

2016-08-31 Thread Ashod Nakashian
 loolwsd/Common.hpp  |1 +
 loolwsd/LOOLWSD.cpp |3 +++
 2 files changed, 4 insertions(+)

New commits:
commit 9b3343aad49637afe944da3ee83062e55217ee48
Author: Ashod Nakashian 
Date:   Wed Aug 31 23:40:42 2016 -0400

loolwsd: Don't block on client sockets and timeout in 1 second

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

diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp
index f76b823..3e5d5e9 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -20,6 +20,7 @@ constexpr int WSD_SLEEP_SECS = 2;
 constexpr int CHILD_TIMEOUT_SECS = 4;
 constexpr int POLL_TIMEOUT_MS = 1000;
 constexpr int COMMAND_TIMEOUT_MS = 5000;
+constexpr int WS_SEND_TIMEOUT_MICROSECS = 100; // 1 second.
 
 /// Pipe and Socket read buffer size.
 /// Should be large enough for ethernet packets
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 5efbd39..0637bf3 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -905,6 +905,9 @@ public:
 responded = true; // After upgrading to WS we should not set 
HTTP response.
 try
 {
+// First, setup WS options.
+ws->setBlocking(false);
+ws->setSendTimeout(WS_SEND_TIMEOUT_MICROSECS);
 handleGetRequest(request, ws, id);
 }
 catch (const WebSocketErrorMessageException& exc)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/Common.hpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp loolwsd/loolwsd.xml.in

2016-06-27 Thread Ashod Nakashian
 loolwsd/Common.hpp |1 +
 loolwsd/LOOLWSD.cpp|4 +---
 loolwsd/LOOLWSD.hpp|1 -
 loolwsd/loolwsd.xml.in |1 -
 4 files changed, 2 insertions(+), 5 deletions(-)

New commits:
commit b7e0766fea74f851ccda9b6b172357029eed05db
Author: Ashod Nakashian 
Date:   Mon Jun 27 08:27:08 2016 -0400

loolwsd: removed lo_jail_subpath

Really unused setting that caused deployment complications.

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

diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp
index f0be984..f76b823 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -36,6 +36,7 @@ constexpr auto FIFO_PATH = "pipe";
 constexpr auto JAILED_DOCUMENT_ROOT = "/user/docs/";
 constexpr auto CHILD_URI = "/loolws/child?";
 constexpr auto NEW_CHILD_URI = "/loolws/newchild?";
+constexpr auto LO_JAIL_SUBPATH = "lo";
 
 // The client port number, both loolwsd and the kits have this.
 extern int ClientPortNumber;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 903dad3..cef575f 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1174,7 +1174,6 @@ std::string LOOLWSD::Cache = LOOLWSD_CACHEDIR;
 std::string LOOLWSD::SysTemplate;
 std::string LOOLWSD::LoTemplate;
 std::string LOOLWSD::ChildRoot;
-std::string LOOLWSD::LoSubPath = "lo";
 std::string LOOLWSD::ServerName;
 std::string LOOLWSD::FileServerRoot;
 std::string LOOLWSD::LOKitVersion;
@@ -1273,7 +1272,6 @@ void LOOLWSD::initialize(Application& self)
 SysTemplate = getPathFromConfig("sys_template_path");
 LoTemplate = getPathFromConfig("lo_template_path");
 ChildRoot = getPathFromConfig("child_root_path");
-LoSubPath = getPathFromConfig("lo_jail_subpath");
 ServerName = config().getString("server_name");
 FileServerRoot = getPathFromConfig("file_server_root_path");
 NumPreSpawnedChildren = getUIntConfigValue(conf, "num_prespawn_children", 
1);
@@ -1427,7 +1425,7 @@ Process::PID LOOLWSD::createForKit()
 {
 Process::Args args;
 
-args.push_back("--losubpath=" + LOOLWSD::LoSubPath);
+args.push_back("--losubpath=" + std::string(LO_JAIL_SUBPATH));
 args.push_back("--systemplate=" + SysTemplate);
 args.push_back("--lotemplate=" + LoTemplate);
 args.push_back("--childroot=" + ChildRoot);
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index d82e026..76e942e 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -40,7 +40,6 @@ public:
 static std::string SysTemplate;
 static std::string LoTemplate;
 static std::string ChildRoot;
-static std::string LoSubPath;
 static std::string ServerName;
 static std::string FileServerRoot;
 static std::string LOKitVersion;
diff --git a/loolwsd/loolwsd.xml.in b/loolwsd/loolwsd.xml.in
index 3399ef8..c55cf30 100644
--- a/loolwsd/loolwsd.xml.in
+++ b/loolwsd/loolwsd.xml.in
@@ -7,7 +7,6 @@
 
 
 
-lo
 
 
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-05-12 Thread Ashod Nakashian
 loolwsd/Common.hpp  |2 +-
 loolwsd/LOOLWSD.cpp |   24 +---
 2 files changed, 14 insertions(+), 12 deletions(-)

New commits:
commit de5f77c00fca275361a403f222e8025eaa3b346c
Author: Ashod Nakashian 
Date:   Thu May 12 10:43:13 2016 -0400

loolwsd: better child management

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

diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp
index caa3ce0..f0be984 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -17,7 +17,7 @@ constexpr int MAX_SESSIONS = 1024;
 constexpr int DEFAULT_CLIENT_PORT_NUMBER = 9980;
 constexpr int DEFAULT_MASTER_PORT_NUMBER = 9981;
 constexpr int WSD_SLEEP_SECS = 2;
-constexpr int CHILD_TIMEOUT_SECS = 10;
+constexpr int CHILD_TIMEOUT_SECS = 4;
 constexpr int POLL_TIMEOUT_MS = 1000;
 constexpr int COMMAND_TIMEOUT_MS = 5000;
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index f2b47ad..bf8b674 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -149,7 +149,7 @@ static bool NoCapsForKit = false;
 static std::vector newChildren;
 static std::mutex newChildrenMutex;
 static std::condition_variable newChildrenCV;
-static std::chrono::steady_clock::time_point lastForkRequestTime;
+static std::chrono::steady_clock::time_point lastForkRequestTime = 
std::chrono::steady_clock::now();
 static std::map docBrokers;
 static std::mutex docBrokersMutex;
 // Sessions to pre-spawned child processes that have connected but are not yet 
assigned a
@@ -194,13 +194,7 @@ static void prespawnChildren()
 return;
 }
 
-const auto duration = (std::chrono::steady_clock::now() - 
lastForkRequestTime);
-if 
(std::chrono::duration_cast(duration).count() <= 
CHILD_TIMEOUT_SECS * 1000)
-{
-// Not enough time passed to balance children.
-return;
-}
-
+// Do the cleanup first.
 for (int i = newChildren.size() - 1; i >= 0; --i)
 {
 if (!newChildren[i]->isAlive())
@@ -209,6 +203,13 @@ static void prespawnChildren()
 }
 }
 
+const auto duration = (std::chrono::steady_clock::now() - 
lastForkRequestTime);
+if 
(std::chrono::duration_cast(duration).count() <= 
CHILD_TIMEOUT_SECS * 1000)
+{
+// Not enough time passed to balance children.
+return;
+}
+
 const int available = newChildren.size();
 int balance = LOOLWSD::NumPreSpawnedChildren;
 balance -= available;
@@ -263,11 +264,11 @@ static std::shared_ptr getNewChild()
 Log::debug("getNewChild: Returning new child [" + 
std::to_string(child->getPid()) + "].");
 return child;
 }
-
-Log::debug("getNewChild: No live child, forking more.");
 }
+
+Log::debug("getNewChild: No live child, forking more.");
 }
-while 
(chrono::duration_cast(chrono::steady_clock::now() - 
startTime).count() < CHILD_TIMEOUT_SECS * 2000);
+while 
(chrono::duration_cast(chrono::steady_clock::now() - 
startTime).count() < CHILD_TIMEOUT_SECS * 4000);
 
 Log::debug("getNewChild: Timed out while waiting for new child.");
 return nullptr;
@@ -1452,6 +1453,7 @@ Process::PID LOOLWSD::createForKit()
 Log::info("Launching forkit process: " + forKitPath + " " +
   Poco::cat(std::string(" "), args.begin(), args.end()));
 
+lastForkRequestTime = std::chrono::steady_clock::now();
 ProcessHandle child = Process::launch(forKitPath, args);
 
 return child.id();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-12 Thread Tor Lillqvist
 loolwsd/Common.hpp  |1 -
 loolwsd/LOOLWSD.cpp |   31 ---
 2 files changed, 32 deletions(-)

New commits:
commit 241d421fc7e4ae44b11446ecf997d5c578deac19
Author: Tor Lillqvist 
Date:   Tue Apr 12 18:03:57 2016 +0300

Kill the  "lool_admin_notify.fifo" thing as it is not used

The loolwsd process created it and opened it for reading, but nothing
opened it for writing.

There is still documentation for it in README, that needs to be either
rewritten to match reality or removed.

diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp
index 16b3594..cc9b4d1 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -34,7 +34,6 @@ constexpr int READ_BUFFER_SIZE = 2048;
 constexpr int SMALL_MESSAGE_SIZE = READ_BUFFER_SIZE / 2;
 
 constexpr auto CHILD_URI = "/loolws/child?";
-constexpr auto FIFO_ADMIN_NOTIFY = "lool_admin_notify.fifo";
 constexpr auto FIFO_LOOLWSD = "loolwsdfifo";
 constexpr auto FIFO_PATH = "pipe";
 constexpr auto JAILED_DOCUMENT_ROOT = "/user/docs/";
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index e46fa02..8e30bdf 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1323,37 +1323,6 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 return Application::EXIT_SOFTWARE;
 }
 
-// Open notify pipe
-int pipeFlags = O_RDONLY | O_NONBLOCK;
-int notifyPipe = -1;
-const std::string pipeNotify = Path(pipePath, 
FIFO_ADMIN_NOTIFY).toString();
-Log::debug("mkfifo(" + pipeNotify + ")");
-if (mkfifo(pipeNotify.c_str(), 0666) < 0 && errno != EEXIST)
-{
-Log::syserror("Failed to create fifo [" + pipeNotify + "].");
-std::exit(Application::EXIT_SOFTWARE);
-}
-
-if ((notifyPipe = open(pipeNotify.c_str(), pipeFlags) ) < 0)
-{
-Log::syserror("Failed to open pipe [" + pipeNotify + "] for reading.");
-std::exit(Application::EXIT_SOFTWARE);
-}
-Log::debug("open(" + pipeNotify + ", RDONLY) = " + 
std::to_string(notifyPipe));
-
-if ((pipeFlags = fcntl(notifyPipe, F_GETFL, 0)) < 0)
-{
-Log::syserror("Failed to get pipe flags [" + pipeNotify + "].");
-std::exit(Application::EXIT_SOFTWARE);
-}
-
-pipeFlags &= ~O_NONBLOCK;
-if (fcntl(notifyPipe, F_SETFL, pipeFlags) < 0)
-{
-Log::syserror("Failed to set pipe flags [" + pipeNotify + "].");
-std::exit(Application::EXIT_SOFTWARE);
-}
-
 const Process::PID forKitPid = createForKit();
 if (forKitPid < 0)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-10 Thread Ashod Nakashian
 loolwsd/Common.hpp  |1 +
 loolwsd/LOOLWSD.cpp |6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)

New commits:
commit 63068a5dda82c055b5d6844067e70d585d0fb4a2
Author: Ashod Nakashian 
Date:   Sun Apr 10 22:16:04 2016 -0400

loolwsd: command timeout is now a const

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

diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp
index d09c08b..1984f4d 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -21,6 +21,7 @@ constexpr int MASTER_PORT_NUMBER = 9981;
 constexpr int MAINTENANCE_INTERVAL = 1;
 constexpr int CHILD_TIMEOUT_SECS = 10;
 constexpr int POLL_TIMEOUT_MS = 1000;
+constexpr int COMMAND_TIMEOUT_MS = 5000;
 
 /// Pipe and Socket read buffer size.
 /// Should be large enough for ethernet packets
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 0f5a391..bf35d51 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -266,7 +266,7 @@ private:
 {
 AvailableChildSessionCV.wait_for(
 lock,
-std::chrono::milliseconds(3000),
+std::chrono::milliseconds(COMMAND_TIMEOUT_MS),
 [, ]
 {
 return (isFound = 
AvailableChildSessions.find(clientSession->getId()) != 
AvailableChildSessions.end());
@@ -354,7 +354,7 @@ private:
 response.send();
 return;
 }
-// Now the bridge beetween the client and kit process is 
connected
+// Now the bridge between the client and kit processes is 
connected
 // Let messages flow
 
 std::string encodedFrom;
@@ -600,7 +600,7 @@ private:
 // Note: technically, there is a race between these two (we should
 // hold the broker lock before issueing the save and waiting,)
 // but in practice this shouldn't happen.
-if (docBroker->autoSave(true) && !docBroker->waitSave(5000))
+if (docBroker->autoSave(true) && 
!docBroker->waitSave(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/Common.hpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp loolwsd/loolwsd.xml

2016-03-23 Thread Ashod Nakashian
 loolwsd/Common.hpp  |2 -
 loolwsd/LOOLWSD.cpp |   54 
 loolwsd/LOOLWSD.hpp |1 
 loolwsd/loolwsd.xml |6 +
 4 files changed, 45 insertions(+), 18 deletions(-)

New commits:
commit b4e4ccb666a594e40cd09fb9a0f8c6f0971b1f26
Author: Ashod Nakashian 
Date:   Wed Mar 23 07:08:01 2016 -0400

loolwsd: configuration support

Configuration XML is added with SSL as sample use-case.

A 'desc' attribute can be used to describe the fields,
and another 'type' to help define the corresponding data
type in the code.

Since Poco allows accessing group nodes (that have the
same name) by index, order can be preserved.

SSL initialization refactored and cert/key file
paths moved to the config file.

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

diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp
index 2f44df2..d96a09d 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -36,8 +36,6 @@ constexpr int SMALL_MESSAGE_SIZE = READ_BUFFER_SIZE / 2;
 static const std::string JailedDocumentRoot = "/user/docs/";
 static const std::string CHILD_URI = "/loolws/child?";
 static const std::string LOLEAFLET_PATH = "/loleaflet/dist/loleaflet.html?";
-static const std::string SSL_CERT_FILE = "cert.pem";
-static const std::string SSL_KEY_FILE = "key.pem";
 
 #endif
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ae896a3..a8a3996 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1042,6 +1042,42 @@ void LOOLWSD::initialize(Application& self)
 ServerApplication::initialize(self);
 }
 
+void LOOLWSD::initializeSSL()
+{
+auto& conf = config();
+
+auto ssl_cert_file_path = conf.getString("ssl.cert_file_path");
+if (conf.getBool("ssl.cert_file_path[@relative]"))
+{
+ssl_cert_file_path = 
Poco::Path(Application::instance().commandPath()).parent().append(ssl_cert_file_path).toString();
+}
+
+Log::info("SSL Cert file: " + ssl_cert_file_path);
+
+auto ssl_key_file_path = conf.getString("ssl.key_file_path");
+if (conf.getBool("ssl.key_file_path[@relative]"))
+{
+ssl_key_file_path = 
Poco::Path(Application::instance().commandPath()).parent().append(ssl_key_file_path).toString();
+}
+
+Log::info("SSL Key file: " + ssl_key_file_path);
+
+Poco::Crypto::initializeCrypto();
+
+Poco::Net::initializeSSL();
+Poco::Net::Context::Params sslParams;
+sslParams.certificateFile = ssl_cert_file_path;
+sslParams.privateKeyFile = ssl_key_file_path;
+// Don't ask clients for certificate
+sslParams.verificationMode = Poco::Net::Context::VERIFY_NONE;
+
+Poco::SharedPtr consoleHandler = 
new Poco::Net::KeyConsoleHandler(true);
+Poco::SharedPtr invalidCertHandler = 
new Poco::Net::ConsoleCertificateHandler(false);
+
+Poco::Net::Context::Ptr sslContext = new 
Poco::Net::Context(Poco::Net::Context::SERVER_USE, sslParams);
+Poco::Net::SSLManager::instance().initializeServer(consoleHandler, 
invalidCertHandler, sslContext);
+}
+
 void LOOLWSD::uninitialize()
 {
 ServerApplication::uninitialize();
@@ -1184,21 +1220,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 return Application::EXIT_USAGE;
 }
 
-Poco::Crypto::initializeCrypto();
-
-// SSL initialize
-Poco::Net::initializeSSL();
-Poco::Net::Context::Params sslParams;
-sslParams.certificateFile = 
Path(Application::instance().commandPath()).parent().toString() + SSL_CERT_FILE;
-sslParams.privateKeyFile = 
Path(Application::instance().commandPath()).parent().toString() + SSL_KEY_FILE;
-// Don't ask clients for certificate
-sslParams.verificationMode = Poco::Net::Context::VERIFY_NONE;
-
-Poco::SharedPtr consoleHandler = 
new Poco::Net::KeyConsoleHandler(true);
-Poco::SharedPtr invalidCertHandler = 
new Poco::Net::ConsoleCertificateHandler(false);
-
-Poco::Net::Context::Ptr sslContext = new 
Poco::Net::Context(Poco::Net::Context::SERVER_USE, sslParams);
-Poco::Net::SSLManager::instance().initializeServer(consoleHandler, 
invalidCertHandler, sslContext);
+initializeSSL();
 
 char *locale = setlocale(LC_ALL, nullptr);
 if (locale == nullptr || std::strcmp(locale, "C") == 0)
@@ -1435,7 +1457,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 std::unique_lock sessionsLock(sessionsMutex);
 for (auto& it : sessions)
 {
-if (it->lastMessageTime >= it->idleSaveTime && 
+if (it->lastMessageTime >= it->idleSaveTime &&
 it->lastMessageTime >= it->autoSaveTime)
 {
 // Trigger a .uno:Save
diff 

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

2016-01-31 Thread Ashod Nakashian
 loolwsd/Common.hpp  |3 +++
 loolwsd/LOOLWSD.cpp |   34 --
 2 files changed, 19 insertions(+), 18 deletions(-)

New commits:
commit 6f5afd92baa481fb27aaebe769d283fb5382fd84
Author: Ashod Nakashian 
Date:   Sun Jan 31 22:34:18 2016 -0500

loolwsd: fixed server thread-pool

TCPServer doesn't use the custom ThreadPool passed to it
to dispatch connections. This leads to starvation
when too many connections are initiated together.

Because we open an internal socket back to master, we
need to be able to dispatch two connections (two threads)
for each client connection.

Therefore, the default ThreadPool needs to have sufficient
capacity to grow. A new constant is added to define this
capacity and it is used to configure both the TCPServer
(which configures the default ThreadPool) and the customer
ThreadPool (used to host the actuall connection handler).

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

diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp
index f85f76d..57903f2 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -13,6 +13,9 @@
 
 #include 
 
+// The maximum number of client connections we can accept.
+constexpr int MAX_SESSIONS = 1024;
+
 constexpr int DEFAULT_CLIENT_PORT_NUMBER = 9980;
 constexpr int MASTER_PORT_NUMBER = 9981;
 constexpr int INTERVAL_PROBES = 10;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 83d4341..da474c9 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -959,18 +959,28 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 dropCapability();
 #endif
 
+// Configure the Server.
+// Note: TCPServer internally uses the default
+// ThreadPool to dispatch connections.
+// The capacity of the default ThreadPool
+// is increased to match MaxThreads.
+// We must have sufficient available threads
+// in the default ThreadPool to dispatch
+// connections, otherwise we will deadlock.
+auto params = new HTTPServerParams();
+params->setMaxThreads(MAX_SESSIONS);
+
 // Start a server listening on the port for clients
-ServerSocket svs(ClientPortNumber, NumPreSpawnedChildren*10);
-ThreadPool threadPool(NumPreSpawnedChildren*2, NumPreSpawnedChildren*5);
-HTTPServer srv(new RequestHandlerFactory(), 
threadPool, svs, new HTTPServerParams);
+ServerSocket svs(ClientPortNumber);
+ThreadPool threadPool(NumPreSpawnedChildren*6, MAX_SESSIONS * 2);
+HTTPServer srv(new RequestHandlerFactory(), 
threadPool, svs, params);
 
 srv.start();
 
 // And one on the port for child processes
 SocketAddress addr2("127.0.0.1", MASTER_PORT_NUMBER);
-ServerSocket svs2(addr2, NumPreSpawnedChildren);
-ThreadPool threadPool2(NumPreSpawnedChildren*2, NumPreSpawnedChildren*5);
-HTTPServer srv2(new RequestHandlerFactory(), 
threadPool2, svs2, new HTTPServerParams);
+ServerSocket svs2(addr2);
+HTTPServer srv2(new RequestHandlerFactory(), 
threadPool, svs2, params);
 
 srv2.start();
 
@@ -990,19 +1000,8 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 
 int status = 0;
 unsigned timeoutCounter = 0;
-std::chrono::steady_clock::time_point lastPoolTime = 
std::chrono::steady_clock::now();
-
 while (!TerminationFlag && !LOOLWSD::DoTest)
 {
-const auto duration = (std::chrono::steady_clock::now() - 
lastPoolTime);
-if (duration >= std::chrono::seconds(10))
-{
-if (threadPool.available() ==  0)
-Log::warn("The thread pool is full, no more connections are 
accepted.");
-
-lastPoolTime = std::chrono::steady_clock::now();
-}
-
 const pid_t pid = waitpid(-1, , WUNTRACED | WNOHANG);
 if (pid > 0)
 {
@@ -1070,7 +1069,6 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 
 // close all websockets
 threadPool.joinAll();
-threadPool2.joinAll();
 
 // Terminate child processes
 Util::writeFIFO(LOOLWSD::BrokerWritePipe, "eof\r\n");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-24 Thread Ashod Nakashian
 loolwsd/Common.hpp  |2 +-
 loolwsd/LOOLWSD.cpp |   13 +
 2 files changed, 10 insertions(+), 5 deletions(-)

New commits:
commit 9593ec5720704c910d3e2a733d092625f23fed68
Author: Ashod Nakashian 
Date:   Sat Jan 23 17:35:16 2016 -0500

loolwsd: improved polling and pong with client

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

diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp
index ff98222..f85f76d 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -18,7 +18,7 @@ constexpr int MASTER_PORT_NUMBER = 9981;
 constexpr int INTERVAL_PROBES = 10;
 constexpr int MAINTENANCE_INTERVAL = 1;
 constexpr int CHILD_TIMEOUT_SECS = 10;
-constexpr int POLL_TIMEOUT_MS = 500;
+constexpr int POLL_TIMEOUT_MS = 1000;
 
 /// Pipe and Socket read buffer size.
 /// Should be large enough for ethernet packets
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 91da2f9..4db32fb 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -200,7 +200,7 @@ void SocketProcessor(std::shared_ptr ws,
 {
 Log::info("Starting Socket Processor.");
 
-const Poco::Timespan waitTime(POLL_TIMEOUT_MS);
+const Poco::Timespan waitTime(POLL_TIMEOUT_MS * 1000);
 try
 {
 int flags = 0;
@@ -217,17 +217,22 @@ void SocketProcessor(std::shared_ptr ws,
 if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PING)
 {
 // Echo back the ping payload as pong.
-ws->sendFrame(buffer, n, WebSocket::FRAME_OP_PONG);
-continue;
+// Technically, we should send back a PONG control frame.
+// However Firefox (probably) or Node.js (possibly) doesn't
+// like that and closes the socket when we do.
+// Echoing the payload as a normal frame works with 
Firefox.
+ws->sendFrame(buffer, n /*, WebSocket::FRAME_OP_PONG*/);
 }
 else if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PONG)
 {
 // In case we do send pings in the future.
-continue;
 }
 else if (n <= 0)
 {
 // Connection closed.
+Log::warn() << "Received " << n
+<< " bytes. Connection closed. Flags: "
+<< std::hex << flags << Log::end;
 break;
 }
 else
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits