[Libreoffice-commits] online.git: common/IoUtil.cpp common/IoUtil.hpp common/Session.cpp configure.ac kit/ChildSession.hpp kit/ForKit.cpp kit/Kit.cpp Makefile.am test/Makefile.am test/UnitConvert.cpp

2020-04-10 Thread Michael Meeks (via logerrit)
 Makefile.am|5 
 common/IoUtil.cpp  |  318 -
 common/IoUtil.hpp  |   64 -
 common/Session.cpp |1 
 configure.ac   |2 
 kit/ChildSession.hpp   |2 
 kit/ForKit.cpp |1 
 kit/Kit.cpp|1 
 test/Makefile.am   |1 
 test/UnitConvert.cpp   |1 
 test/UnitFuzz.cpp  |1 
 test/UnitOOB.cpp   |1 
 wsd/Admin.cpp  |1 
 wsd/DocumentBroker.hpp |1 
 wsd/LOOLWSD.cpp|1 
 15 files changed, 2 insertions(+), 399 deletions(-)

New commits:
commit a7dc2d1467f20cc52783cc47f458c7bf7f3376a6
Author: Michael Meeks 
AuthorDate: Fri Apr 10 12:45:14 2020 +0100
Commit: Michael Meeks 
CommitDate: Fri Apr 10 16:38:25 2020 +0200

kill IoUtil - obsolete & unused.

The switch away from LOOLWebSocket and the use of a websocket
for talking to forkit removes the need for the pipe code.

Change-Id: Ifb0c6c88681289e7a1709d9bc3281532935c7be4
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92033
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Michael Meeks 

diff --git a/Makefile.am b/Makefile.am
index 3ce60690d..bc2aa55ba 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -89,7 +89,6 @@ AM_ETAGSFLAGS = --c++-kinds=+p --fields=+iaS --extra=+q -R 
--totals=yes --exclud
 AM_CTAGSFLAGS = $(AM_ETAGSFLAGS)
 
 shared_sources = common/FileUtil.cpp \
- common/IoUtil.cpp \
  common/Log.cpp \
  common/Protocol.cpp \
  common/StringVector.cpp \
@@ -144,8 +143,7 @@ connect_SOURCES = tools/Connect.cpp \
   common/StringVector.cpp \
   common/Util.cpp
 
-lokitclient_SOURCES = common/IoUtil.cpp \
-  common/Log.cpp \
+lokitclient_SOURCES = common/Log.cpp \
   tools/KitClient.cpp \
   common/Protocol.cpp \
   common/StringVector.cpp \
@@ -231,7 +229,6 @@ shared_headers = common/Common.hpp \
  common/Clipboard.hpp \
  common/Crypto.hpp \
  common/JsonUtil.hpp \
- common/IoUtil.hpp \
  common/FileUtil.hpp \
  common/Log.hpp \
  common/LOOLWebSocket.hpp \
diff --git a/common/IoUtil.cpp b/common/IoUtil.cpp
deleted file mode 100644
index f7ea25225..0
--- a/common/IoUtil.cpp
+++ /dev/null
@@ -1,318 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#include 
-
-#include "IoUtil.hpp"
-
-#include 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
-
-#include "Common.hpp"
-#include "Protocol.hpp"
-#include "LOOLWebSocket.hpp"
-#include "Log.hpp"
-#include "Util.hpp"
-
-using Poco::Net::Socket;
-using Poco::Net::WebSocket;
-
-namespace IoUtil
-{
-
-// Synchronously process LOOLWebSocket requests and dispatch to handler.
-// Handler returns false to end.
-void SocketProcessor(const std::shared_ptr& ws,
- const std::string& name,
- const std::function&)>& 
handler,
- const std::function& closeFrame,
- const std::function& stopPredicate)
-{
-LOG_INF("SocketProcessor [" << name << "] starting.");
-
-// Timeout given is in microseconds.
-static const Poco::Timespan waitTime(POLL_TIMEOUT_MICRO_S);
-int flags = 0;
-int n = -1;
-bool stop = false;
-std::vector payload(READ_BUFFER_SIZE);
-payload.resize(0);
-try
-{
-// We poll, no need for timeout.
-ws->setReceiveTimeout(0);
-
-for (;;)
-{
-stop = stopPredicate();
-if (stop)
-{
-LOG_INF("SocketProcessor [" << name << "]: Stop flagged.");
-break;
-}
-
-if (!ws->poll(waitTime, Poco::Net::Socket::SELECT_READ) ||
-stopPredicate())
-{
-// If SELECT_READ fails, it might mean the socket is in error.
-if (ws->poll(Poco::Timespan(0), 
Poco::Net::Socket::SELECT_ERROR))
-{
-LOG_WRN("SocketProcessor [" << name << "]: Socket error.");
-closeFrame();
-break;
-}
-
-// Wait some more.
-continue;
-}
-
-try
-{
-payload.resize(payload.capacity());
-n = -1; // In case receiveFrame throws we log dropped data 
below.
-(void)n;
-   

[Libreoffice-commits] online.git: common/IoUtil.cpp common/Util.cpp test/httpwstest.cpp test/TileCacheTests.cpp test/TileQueueTests.cpp wsd/ClientSession.cpp wsd/FileServer.cpp

2017-11-03 Thread Miklos Vajna
 common/IoUtil.cpp   |1 -
 common/Util.cpp |1 -
 test/TileCacheTests.cpp |2 +-
 test/TileQueueTests.cpp |1 -
 test/httpwstest.cpp |1 -
 wsd/ClientSession.cpp   |1 -
 wsd/FileServer.cpp  |1 -
 7 files changed, 1 insertion(+), 7 deletions(-)

New commits:
commit a3d6dee5030678baf141e91706d2e80a8f3af44f
Author: Miklos Vajna 
Date:   Fri Nov 3 15:18:38 2017 +0100

Remove unused strings

Change-Id: I621c462bca38222dcf26dfa1e414cf27e1a3e088

diff --git a/common/IoUtil.cpp b/common/IoUtil.cpp
index da9a4242..c93023af 100644
--- a/common/IoUtil.cpp
+++ b/common/IoUtil.cpp
@@ -113,7 +113,6 @@ void SocketProcessor(const std::shared_ptr& 
ws,
 
 LOG_CHECK(n > 0);
 
-const std::string firstLine = LOOLProtocol::getFirstLine(payload);
 if ((flags & WebSocket::FrameFlags::FRAME_FLAG_FIN) != 
WebSocket::FrameFlags::FRAME_FLAG_FIN)
 {
 // One WS message split into multiple frames.
diff --git a/common/Util.cpp b/common/Util.cpp
index a3e5e798..9dd3c80c 100644
--- a/common/Util.cpp
+++ b/common/Util.cpp
@@ -164,7 +164,6 @@ namespace Util
 while (!isdigit(line[len]) && line[len] != '\0')
 ++len;
 
-const auto str = std::string(line + len, strlen(line + len) - 1);
 return line + len;
 }
 
diff --git a/test/TileCacheTests.cpp b/test/TileCacheTests.cpp
index cac39144..2231dfa9 100644
--- a/test/TileCacheTests.cpp
+++ b/test/TileCacheTests.cpp
@@ -381,7 +381,7 @@ void TileCacheTests::testDisconnectMultiView()
 }
 
 // Should never get more than 4 tiles on socket2.
-const auto res2 = getResponseString(socket2, "tile:", 
"disconnectMultiView-2 ", 500);
+getResponseString(socket2, "tile:", "disconnectMultiView-2 ", 500);
 }
 }
 
diff --git a/test/TileQueueTests.cpp b/test/TileQueueTests.cpp
index 72f263eb..bcf38ba3 100644
--- a/test/TileQueueTests.cpp
+++ b/test/TileQueueTests.cpp
@@ -119,7 +119,6 @@ void TileQueueTests::testTileCombinedRendering()
 const std::string req1 = "tile part=0 width=256 height=256 tileposx=0 
tileposy=0 tilewidth=3840 tileheight=3840";
 const std::string req2 = "tile part=0 width=256 height=256 tileposx=3840 
tileposy=0 tilewidth=3840 tileheight=3840";
 const std::string req3 = "tile part=0 width=256 height=256 tileposx=0 
tileposy=3840 tilewidth=3840 tileheight=3840";
-const std::string req4 = "tile part=0 width=256 height=256 tileposx=3840 
tileposy=3840 tilewidth=3840 tileheight=3840";
 
 const std::string resHor = "tilecombine part=0 width=256 height=256 
tileposx=0,3840 tileposy=0,0 imgsize=0,0 tilewidth=3840 tileheight=3840 
ver=-1,-1 oldwid=0,0 wid=0,0";
 const TileQueue::Payload payloadHor(resHor.data(), resHor.data() + 
resHor.size());
diff --git a/test/httpwstest.cpp b/test/httpwstest.cpp
index 14a2fb24..dee2e160 100644
--- a/test/httpwstest.cpp
+++ b/test/httpwstest.cpp
@@ -2375,7 +2375,6 @@ void HTTPWSTest::testEachView(const std::string& doc, 
const std::string& type,
   const std::string& testname)
 {
 const std::string view = testname + "view %d -> ";
-const std::string load = testname + "view %d, cannot load the document ";
 const std::string error = testname + "view %d, did not receive a %s 
message as expected";
 
 try
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index be9f542f..630c0f38 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -861,7 +861,6 @@ bool ClientSession::forwardToClient(const 
std::shared_ptr& payload)
 
 Authorization ClientSession::getAuthorization() const
 {
-std::string accessToken;
 Poco::URI::QueryParameters queryParams = _uriPublic.getQueryParameters();
 
 // prefer the access_token
diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index f27d9272..949ad0f1 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -132,7 +132,6 @@ bool FileServerRequestHandler::isAdminLoggedIn(const 
HTTPRequest& request,
 if (credentials.getUsername() == user &&
 userProvidedPwd == pass)
 {
-const std::string htmlMimeType = "text/html";
 // generate and set the cookie
 JWTAuth authAgent(sslKeyPath, "admin", "admin", "admin");
 const std::string jwtToken = authAgent.getAccessToken();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: common/IoUtil.cpp wsd/LOOLWSD.cpp

2017-01-15 Thread Ashod Nakashian
 common/IoUtil.cpp |4 +++-
 wsd/LOOLWSD.cpp   |   12 +---
 2 files changed, 12 insertions(+), 4 deletions(-)

New commits:
commit 373b4646451200d7565d23793e276540adecf3f9
Author: Ashod Nakashian 
Date:   Sun Jan 15 12:32:20 2017 -0500

wsd: logs and cosmetics

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

diff --git a/common/IoUtil.cpp b/common/IoUtil.cpp
index 3466dca..3991fc3 100644
--- a/common/IoUtil.cpp
+++ b/common/IoUtil.cpp
@@ -206,14 +206,16 @@ void SocketProcessor(const 
std::shared_ptr& ws,
 ssize_t writeToPipe(int pipe, const char* buffer, ssize_t size)
 {
 ssize_t count = 0;
-while(true)
+for (;;)
 {
 LOG_TRC("Writing to pipe. Data: [" << 
Util::formatLinesForLog(std::string(buffer, size)) << "].");
 const auto bytes = write(pipe, buffer + count, size - count);
 if (bytes < 0)
 {
 if (errno == EINTR || errno == EAGAIN)
+{
 continue;
+}
 
 LOG_SYS("Failed to write to pipe. Data: [" << std::string(buffer, 
size) << "].");
 count = -1;
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 7d0bb9f..e7d4ee7 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -399,13 +399,16 @@ static void preForkChildren()
 UnitWSD::get().preSpawnCount(numPreSpawn);
 
 // Wait until we have at least one child.
-const auto timeout = std::chrono::milliseconds(CHILD_TIMEOUT_MS * 3);
+const auto timeoutMs = CHILD_TIMEOUT_MS * 3;
+const auto timeout = std::chrono::milliseconds(timeoutMs);
+LOG_TRC("Waiting for a new child for a max of " << timeoutMs << " ms.");
 NewChildrenCV.wait_for(lock, timeout, []() { return !NewChildren.empty(); 
});
 
 // Now spawn more, as needed.
 rebalanceChildren(numPreSpawn);
 
 // Make sure we have at least one before moving forward.
+LOG_TRC("Waiting for a new child for a max of " << timeoutMs << " ms.");
 if (!NewChildrenCV.wait_for(lock, timeout, []() { return 
!NewChildren.empty(); }))
 {
 const auto msg = "Failed to fork child processes.";
@@ -469,6 +472,7 @@ static std::shared_ptr getNewChild()
 ++numPreSpawn; // Replace the one we'll dispatch just now.
 rebalanceChildren(numPreSpawn);
 
+LOG_TRC("Waiting for a new child for a max of " << CHILD_TIMEOUT_MS << 
" ms.");
 const auto timeout = chrono::milliseconds(CHILD_TIMEOUT_MS);
 if (NewChildrenCV.wait_for(lock, timeout, []() { return 
!NewChildren.empty(); }))
 {
@@ -1021,7 +1025,7 @@ private:
 if (!child)
 {
 // Let the client know we can't serve now.
-LOG_ERR("Failed to get new child. Service Unavailable.");
+LOG_ERR("Failed to get new child.");
 return nullptr;
 }
 
@@ -1104,6 +1108,9 @@ private:
 {
 LOG_CHECK_RET(docBroker && "Null docBroker instance", );
 
+const auto docKey = docBroker->getDocKey();
+LOG_DBG("Removing docBroker [" << docKey << "]" << (id.empty() ? "" : 
(" and session [" + id + "].")));
+
 std::unique_lock docBrokersLock(DocBrokersMutex);
 auto lock = docBroker->getLock();
 
@@ -1114,7 +1121,6 @@ private:
 
 if (docBroker->getSessionsCount() == 0 || !docBroker->isAlive())
 {
-const auto docKey = docBroker->getDocKey();
 LOG_INF("Removing unloaded DocumentBroker for docKey [" << docKey 
<< "].");
 DocBrokers.erase(docKey);
 docBroker->terminateChild(lock);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: common/IoUtil.cpp common/IoUtil.hpp common/Session.cpp common/Session.hpp wsd/DocumentBroker.hpp wsd/LOOLWebSocket.hpp

2017-01-15 Thread Ashod Nakashian
 common/IoUtil.cpp  |   19 ---
 common/IoUtil.hpp  |4 
 common/Session.cpp |   29 +++--
 common/Session.hpp |3 ++-
 wsd/DocumentBroker.hpp |7 ++-
 wsd/LOOLWebSocket.hpp  |   33 +
 6 files changed, 48 insertions(+), 47 deletions(-)

New commits:
commit b1ff72e13f2af829e0e5e0c79739230a54a982e0
Author: Ashod Nakashian 
Date:   Sun Jan 15 12:28:52 2017 -0500

wsd: move shutdown web socket helper into LOOLWebSocket

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

diff --git a/common/IoUtil.cpp b/common/IoUtil.cpp
index cc62244..3466dca 100644
--- a/common/IoUtil.cpp
+++ b/common/IoUtil.cpp
@@ -203,25 +203,6 @@ void SocketProcessor(const std::shared_ptr& 
ws,
 ", flags: " << std::hex << flags);
 }
 
-void shutdownWebSocket(const std::shared_ptr& ws)
-{
-try
-{
-// Calling LOOLWebSocket::shutdown, in case of error, would try to 
send a 'close' frame
-// which won't work in case of broken pipe or timeout from peer. Just 
close the
-// socket in that case preventing 'close' frame from being sent.
-if (ws && ws->poll(Poco::Timespan(0), 
Socket::SelectMode::SELECT_ERROR))
-ws->close();
-else if (ws)
-ws->shutdown();
-}
-catch (const Poco::Exception& exc)
-{
-LOG_WRN("Util::shutdownWebSocket: Exception: " << exc.displayText() <<
-(exc.nested() ? " (" + exc.nested()->displayText() + ")" : 
""));
-}
-}
-
 ssize_t writeToPipe(int pipe, const char* buffer, ssize_t size)
 {
 ssize_t count = 0;
diff --git a/common/IoUtil.hpp b/common/IoUtil.hpp
index 6a81f19..416607b 100644
--- a/common/IoUtil.hpp
+++ b/common/IoUtil.hpp
@@ -27,10 +27,6 @@ namespace IoUtil
  const std::function& closeFrame,
  const std::function& stopPredicate);
 
-/// Call LOOLWebSocket::shutdown() ignoring Poco::IOException.
-/// TODO: consider moving this directly to LOOLWebSocket
-void shutdownWebSocket(const std::shared_ptr& ws);
-
 ssize_t writeToPipe(int pipe, const char* buffer, ssize_t size);
 inline ssize_t writeToPipe(int pipe, const std::string& message)
 {
diff --git a/common/Session.cpp b/common/Session.cpp
index c409a57..75b5e4b 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -176,25 +176,17 @@ void Session::parseDocOptions(const StringTokenizer& 
tokens, int& part, std::str
 
 void Session::disconnect()
 {
-try
-{
-if (!_disconnected)
-{
-_disconnected = true;
-IoUtil::shutdownWebSocket(_ws);
-}
-}
-catch (const IOException& exc)
+if (!_disconnected)
 {
-LOG_ERR("Session::disconnect: Exception: " << exc.displayText() <<
-(exc.nested() ? " (" + exc.nested()->displayText() + ")" : 
""));
+_disconnected = true;
+shutdown();
 }
 }
 
 bool Session::handleDisconnect()
 {
 _disconnected = true;
-IoUtil::shutdownWebSocket(_ws);
+shutdown();
 return false;
 }
 
@@ -202,16 +194,9 @@ void Session::shutdown(Poco::UInt16 statusCode, const 
std::string& statusMessage
 {
 if (_ws)
 {
-try
-{
-LOG_TRC("Shutting down WS [" << getName() << "] with statusCode [" 
<< statusCode << "] and reason [" << statusMessage << "].");
-_ws->shutdown(statusCode, statusMessage);
-}
-catch (const Poco::Exception )
-{
-LOG_WRN("Session::shutdown LOOLWebSocket: Exception: " <<
-exc.displayText() << (exc.nested() ? " (" + 
exc.nested()->displayText() + ")" : ""));
-}
+LOG_TRC("Shutting down WS [" << getName() << "] with statusCode [" <<
+statusCode << "] and reason [" << statusMessage << "].");
+_ws->shutdown(statusCode, statusMessage);
 }
 }
 
diff --git a/common/Session.hpp b/common/Session.hpp
index 8277c5e..d5fe524 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -51,7 +51,8 @@ public:
 /// Called to handle disconnection command from socket.
 virtual bool handleDisconnect();
 
-void shutdown(Poco::UInt16 statusCode, const std::string& statusMessage = 
"");
+void shutdown(Poco::UInt16 statusCode = 
Poco::Net::WebSocket::StatusCodes::WS_NORMAL_CLOSE,
+  const std::string& statusMessage = "");
 
 bool isActive() const { return _isActive; }
 void setIsActive(bool active) { _isActive = active; }
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 0c2457a..27c4916 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -92,7 +92,12 @@ public:
 {
 LOG_DBG("Closing 

[Libreoffice-commits] online.git: common/IoUtil.cpp common/Log.hpp

2016-12-12 Thread Ashod Nakashian
 common/IoUtil.cpp |9 ++---
 common/Log.hpp|2 ++
 2 files changed, 4 insertions(+), 7 deletions(-)

New commits:
commit 4bc318fb8848490c0306ab9a5089a0a57c9ea6ba
Author: Ashod Nakashian 
Date:   Mon Dec 12 23:31:00 2016 -0500

loolwsd: LOG_CHECK to replace assertion when logging suffices

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

diff --git a/common/IoUtil.cpp b/common/IoUtil.cpp
index 9958bfe..cc62244 100644
--- a/common/IoUtil.cpp
+++ b/common/IoUtil.cpp
@@ -110,7 +110,7 @@ void SocketProcessor(const std::shared_ptr& 
ws,
 continue;
 }
 
-assert(n > 0);
+LOG_CHECK(n > 0);
 
 const std::string firstLine = LOOLProtocol::getFirstLine(payload);
 if ((flags & WebSocket::FrameFlags::FRAME_FLAG_FIN) != 
WebSocket::FrameFlags::FRAME_FLAG_FIN)
@@ -164,12 +164,7 @@ void SocketProcessor(const std::shared_ptr& 
ws,
 }
 }
 
-if (n <= 0 || (flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_CLOSE)
-{
-closeFrame();
-LOG_WRN("SocketProcessor [" << name << "]: Connection 
closed.");
-break;
-}
+LOG_CHECK(n > 0);
 
 // Call the handler.
 const auto success = handler(payload);
diff --git a/common/Log.hpp b/common/Log.hpp
index ebd0ba4..ee7dc55 100644
--- a/common/Log.hpp
+++ b/common/Log.hpp
@@ -180,6 +180,8 @@ namespace Log
 #define LOG_FTL(X) if (Log::fatalEnabled()) { LOG_BODY("FTL", X); 
Log::logger().fatal(oss_.str()); }
 #define LOG_SFL(X) if (Log::errorEnabled()) { LOG_BODY("FTL", X << " (errno: " 
<< std::strerror(errno) << ")"); Log::logger().fatal(oss_.str()); }
 
+#define LOG_CHECK(X) if (!(X)) { LOG_ERR("Check failed. Expected (" #X ")."); }
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-12-12 Thread Ashod Nakashian
 common/IoUtil.cpp |   31 ++-
 1 file changed, 22 insertions(+), 9 deletions(-)

New commits:
commit 6b8ed0dac64dd08fab947f6b6c0af5ddbdc65a9c
Author: Ashod Nakashian 
Date:   Mon Dec 12 21:48:42 2016 -0500

loolwsd: handle socket error and close better

If the socket is in error, SELECT_READ returns
immediatly as failure. In this case we sit
in a tight loop polling read over and over.
We now check for SELECT_ERROR when SElECT_READ
fails to properly close the socket and break.

When receiveFrame returns -1, we should first
check the flags for socket close, as that
is a legitimate case of returning -ve.

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

diff --git a/common/IoUtil.cpp b/common/IoUtil.cpp
index a8cd003..9958bfe 100644
--- a/common/IoUtil.cpp
+++ b/common/IoUtil.cpp
@@ -72,6 +72,14 @@ void SocketProcessor(const std::shared_ptr& 
ws,
 if (!ws->poll(waitTime, Poco::Net::Socket::SELECT_READ) ||
 stopPredicate())
 {
+// If SELECT_READ fails, it might mean the socket is in error.
+if (ws->poll(Poco::Timespan(0), 
Poco::Net::Socket::SELECT_ERROR))
+{
+LOG_WRN("SocketProcessor [" << name << "]: Socket error.");
+closeFrame();
+break;
+}
+
 // Wait some more.
 continue;
 }
@@ -79,7 +87,7 @@ void SocketProcessor(const std::shared_ptr& ws,
 try
 {
 payload.resize(payload.capacity());
-n = -1; // In case receiveFrame throws we log dropped data.
+n = -1; // In case receiveFrame throws we log dropped data 
below.
 (void)n;
 n = ws->receiveFrame(payload.data(), payload.size(), flags);
 payload.resize(std::max(n, 0));
@@ -90,17 +98,17 @@ void SocketProcessor(const std::shared_ptr& 
ws,
 continue;
 }
 
-if (n == -1)
-{
-LOG_DBG("SocketProcessor [" << name << "]: was not an 
interesting frame, nothing to do here");
-continue;
-}
-else if (n == 0 || ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_CLOSE))
+if (n == 0 || ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_CLOSE))
 {
 LOG_WRN("SocketProcessor [" << name << "]: Connection 
closed.");
 closeFrame();
 break;
 }
+else if (n < 0)
+{
+LOG_DBG("SocketProcessor [" << name << "]: was not an 
interesting frame, nothing to do here");
+continue;
+}
 
 assert(n > 0);
 
@@ -109,17 +117,22 @@ void SocketProcessor(const 
std::shared_ptr& ws,
 {
 // One WS message split into multiple frames.
 // TODO: Is this even possible with Poco if we never construct 
such messages outselves?
-LOG_WRN("SocketProcessor [" << name << "]: Receiving 
multi-parm frame.");
+LOG_WRN("SocketProcessor [" << name << "]: Receiving 
multi-part frame.");
 while (true)
 {
 char buffer[READ_BUFFER_SIZE];
 n = ws->receiveFrame(buffer, sizeof(buffer), flags);
-if (n <= 0 || (flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_CLOSE)
+if (n == 0 || (flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_CLOSE)
 {
 LOG_WRN("SocketProcessor [" << name << "]: Connection 
closed while reading multiframe message.");
 closeFrame();
 break;
 }
+else if (n < 0)
+{
+LOG_DBG("SocketProcessor [" << name << "]: was not an 
interesting frame, nothing to do here");
+continue;
+}
 
 payload.insert(payload.end(), buffer, buffer + n);
 if ((flags & WebSocket::FrameFlags::FRAME_FLAG_FIN) == 
WebSocket::FrameFlags::FRAME_FLAG_FIN)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: common/IoUtil.cpp kit/ForKit.cpp

2016-11-28 Thread Ashod Nakashian
 common/IoUtil.cpp |1 +
 kit/ForKit.cpp|4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

New commits:
commit 7a4250b90e4273f73ab5ab94c35728aeba9f0d63
Author: Ashod Nakashian 
Date:   Mon Nov 28 20:34:18 2016 -0500

loolwsd: terminate forkit when wsd dies

When we the pipe with wsd is closed we
assume wsd has died and we terminate too.

WSD can fork us anew, if it's still alive.

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

diff --git a/common/IoUtil.cpp b/common/IoUtil.cpp
index 6fea0b4..32238f3 100644
--- a/common/IoUtil.cpp
+++ b/common/IoUtil.cpp
@@ -329,6 +329,7 @@ int PipeReader::readLine(std::string& line,
 }
 else if (pipe.revents & (POLLERR | POLLHUP | POLLNVAL))
 {
+LOG_FTL("Pipe closed.");
 return -1;
 }
 }
diff --git a/kit/ForKit.cpp b/kit/ForKit.cpp
index 4680c4d..b727817 100644
--- a/kit/ForKit.cpp
+++ b/kit/ForKit.cpp
@@ -75,9 +75,9 @@ public:
 if (ready <= 0)
 {
 // Termination is done via SIGTERM, which breaks the wait.
-if (TerminationFlag)
+if (ready < 0)
 {
-if (ready < 0)
+if (TerminationFlag)
 {
 LOG_INF("Poll interrupted in " << getName() << " and 
Termination flag set.");
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-28 Thread Ashod Nakashian
 common/IoUtil.cpp |1 +
 1 file changed, 1 insertion(+)

New commits:
commit 21b1287444fc483adb8561243497ef466cd53fa9
Author: Ashod Nakashian 
Date:   Mon Nov 28 21:38:34 2016 -0500

Revert "IoUtil: remove never read write of 'n'"

Setting 'n = -1;' helps to detect where the failure happened
when receiveFrame throws. At the bottom of the function we log
partially processed data by checking n (among others).

This reverts commit 752372a2b022ad4a450df61bcc58c978840b9b37.

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

diff --git a/common/IoUtil.cpp b/common/IoUtil.cpp
index 2ee9c84..6fea0b4 100644
--- a/common/IoUtil.cpp
+++ b/common/IoUtil.cpp
@@ -79,6 +79,7 @@ void SocketProcessor(const std::shared_ptr& ws,
 try
 {
 payload.resize(payload.capacity());
+n = -1; // In case receiveFrame throws we log dropped data.
 n = ws->receiveFrame(payload.data(), payload.size(), flags);
 payload.resize(std::max(n, 0));
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: common/IoUtil.cpp Makefile.am

2016-11-28 Thread Miklos Vajna
 Makefile.am   |2 +-
 common/IoUtil.cpp |1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

New commits:
commit 752372a2b022ad4a450df61bcc58c978840b9b37
Author: Miklos Vajna 
Date:   Mon Nov 28 09:11:11 2016 +0100

IoUtil: remove never read write of 'n'

Change-Id: I2dfd85696b39ae1f1c7bbc33cec544bc04f980ac

diff --git a/Makefile.am b/Makefile.am
index 5f120ad..df8a679 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -193,7 +193,7 @@ clean-cache cache-clean:
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
+   for i in {common,kit,tools,wsd}/*.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
diff --git a/common/IoUtil.cpp b/common/IoUtil.cpp
index b4751ac..2ee9c84 100644
--- a/common/IoUtil.cpp
+++ b/common/IoUtil.cpp
@@ -79,7 +79,6 @@ void SocketProcessor(const std::shared_ptr& ws,
 try
 {
 payload.resize(payload.capacity());
-n = -1;
 n = ws->receiveFrame(payload.data(), payload.size(), flags);
 payload.resize(std::max(n, 0));
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-11-27 Thread Ashod Nakashian
 common/IoUtil.cpp |   12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

New commits:
commit b16fb68ec61188365db40a38f7f5209b65158988
Author: Ashod Nakashian 
Date:   Sat Nov 26 22:39:48 2016 -0500

loolwsd: shrink SocketProcessor buffer when too large

When receiving large messages the dynamic socket buffer
is resized to accomodate the incoming large message.

This buffer was previously never reduced in size.
This is an obvious leak that is now avoided.

When the buffer grows beyond quadruple the default
size, it is shrunk back to the default. This gives
a decent balance between memory waste and unnecessary
resizing up and down after each large message received.

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

diff --git a/common/IoUtil.cpp b/common/IoUtil.cpp
index 768ab95..b4751ac 100644
--- a/common/IoUtil.cpp
+++ b/common/IoUtil.cpp
@@ -54,12 +54,12 @@ void SocketProcessor(const std::shared_ptr& 
ws,
 int n = -1;
 bool stop = false;
 std::vector payload(READ_BUFFER_SIZE);
+payload.resize(0);
 try
 {
+// We poll, no need for timeout.
 ws->setReceiveTimeout(0);
 
-payload.resize(0);
-
 for (;;)
 {
 stop = stopPredicate();
@@ -161,6 +161,14 @@ void SocketProcessor(const std::shared_ptr& 
ws,
 LOG_INF("SocketProcessor [" << name << "]: Handler flagged to 
finish.");
 break;
 }
+
+if (payload.capacity() > READ_BUFFER_SIZE * 4)
+{
+LOG_INF("Compacting buffer of SocketProcessor [" << name << "] 
from " <<
+payload.capacity() / 1024 << "KB to " << 
READ_BUFFER_SIZE / 1024 << "KB.");
+payload = std::vector(READ_BUFFER_SIZE);
+payload.resize(0);
+}
 }
 }
 catch (const std::exception& exc)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits