[Libreoffice-commits] online.git: loolwsd/Connect.cpp loolwsd/LOOLWebSocket.hpp loolwsd/LOOLWSD.cpp loolwsd/test

2016-11-24 Thread Ashod Nakashian
 loolwsd/Connect.cpp|   11 ++-
 loolwsd/LOOLWSD.cpp|5 +++--
 loolwsd/LOOLWebSocket.hpp  |   33 -
 loolwsd/test/UnitFonts.cpp |   13 ++---
 loolwsd/test/helpers.hpp   |   12 +++-
 loolwsd/test/httpcrashtest.cpp |9 +
 loolwsd/test/httpwstest.cpp|   40 +++-
 7 files changed, 50 insertions(+), 73 deletions(-)

New commits:
commit 45c1856c6ad1753f8a90d3bb90711ab0338d623c
Author: Ashod Nakashian 
Date:   Thu Nov 24 19:18:15 2016 -0500

loolwsd: kill receiveFrame with char* and cleanup usage cases

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

diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp
index 5b550dd..aad78fa 100644
--- a/loolwsd/Connect.cpp
+++ b/loolwsd/Connect.cpp
@@ -89,23 +89,24 @@ public:
 {
 do
 {
-char buffer[10];
-n = _ws.receiveFrame(buffer, sizeof(buffer), flags);
+Poco::Buffer buffer(READ_BUFFER_SIZE);
+buffer.resize(0);
+n = _ws.receiveFrame(buffer, flags);
 if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE)
 {
 {
 std::unique_lock lock(coutMutex);
-std::cout << "Got " << getAbbreviatedFrameDump(buffer, 
n, flags) << std::endl;
+std::cout << "Got " << 
getAbbreviatedFrameDump(buffer.begin(), n, flags) << std::endl;
 }
 
-std::string firstLine = getFirstLine(buffer, n);
+const std::string firstLine = getFirstLine(buffer.begin(), 
n);
 StringTokenizer tokens(firstLine, " ", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
 
 if (std::getenv("DISPLAY") != nullptr && tokens[0] == 
"tile:")
 {
 TemporaryFile pngFile;
 std::ofstream pngStream(pngFile.path(), 
std::ios::binary);
-pngStream.write(buffer + firstLine.size() + 1, n - 
firstLine.size() - 1);
+pngStream.write(buffer.begin() + firstLine.size() + 1, 
n - firstLine.size() - 1);
 pngStream.close();
 if (std::system((std::string("display ") + 
pngFile.path()).c_str()) == -1)
 {
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 5ca3fce..b7ad287 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -196,7 +196,7 @@ void shutdownLimitReached(LOOLWebSocket& ws)
 {
 int flags = 0;
 int retries = 7;
-std::vector buffer(READ_BUFFER_SIZE * 100);
+Poco::Buffer buffer(READ_BUFFER_SIZE);
 
 const Poco::Timespan waitTime(POLL_TIMEOUT_MS * 1000);
 do
@@ -214,7 +214,8 @@ void shutdownLimitReached(LOOLWebSocket& ws)
 // Ignore incoming messages.
 if (ws.poll(waitTime, Poco::Net::Socket::SELECT_READ))
 {
-ws.receiveFrame(buffer.data(), buffer.capacity(), flags);
+buffer.resize(0);
+ws.receiveFrame(buffer, flags);
 }
 
 // Shutdown.
diff --git a/loolwsd/LOOLWebSocket.hpp b/loolwsd/LOOLWebSocket.hpp
index fb1d88b..827c324 100644
--- a/loolwsd/LOOLWebSocket.hpp
+++ b/loolwsd/LOOLWebSocket.hpp
@@ -79,39 +79,6 @@ public:
 /// Wrapper for Poco::Net::WebSocket::receiveFrame() that handles PING 
frames
 /// (by replying with a PONG frame) and PONG frames. PONG frames are 
ignored.
 /// Should we also factor out the handling of non-final and continuation 
frames into this?
-int receiveFrame(char* buffer, const int length, int& flags)
-{
-#ifdef ENABLE_DEBUG
-// Delay receiving the frame
-std::this_thread::sleep_for(getWebSocketDelay());
-#endif
-// Timeout given is in microseconds.
-static const Poco::Timespan waitTime(POLL_TIMEOUT_MS * 1000);
-
-while (poll(waitTime, Poco::Net::Socket::SELECT_READ))
-{
-const int n = Poco::Net::WebSocket::receiveFrame(buffer, length, 
flags);
-if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PING)
-{
-sendFrame(buffer, n, WebSocket::FRAME_FLAG_FIN | 
WebSocket::FRAME_OP_PONG);
-}
-else if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PONG)
-{
-// In case we do send pongs in the future.
-}
-else
-{
-return n;
-}
-}
-
-return -1;
-}
-
-
-/// Wrapper for Poco::Net::WebSocket::receiveFrame() that handles PING 
frames
-//

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

2016-10-18 Thread Tor Lillqvist
 loolwsd/Connect.cpp |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

New commits:
commit e87cf1e5d817835e885af5cd0b4818227a51a1e0
Author: Tor Lillqvist 
Date:   Tue Oct 18 12:29:05 2016 +0300

Adapt to new URI format in the GET request

diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp
index 211e56e..237e7c2 100644
--- a/loolwsd/Connect.cpp
+++ b/loolwsd/Connect.cpp
@@ -175,7 +175,9 @@ protected:
 #else
 HTTPClientSession cs(_uri.getHost(), _uri.getPort());
 #endif
-HTTPRequest request(HTTPRequest::HTTP_GET, std::string("lool/ws/") + 
args[0]);
+std::string encodedUri;
+URI::encode(args[0], ":/?", encodedUri);
+HTTPRequest request(HTTPRequest::HTTP_GET, "/lool/" + encodedUri + 
"/ws");
 HTTPResponse response;
 WebSocket ws(cs, request, response);
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-09-19 Thread Ashod Nakashian
 loolwsd/Connect.cpp |4 +++-
 loolwsd/LOOLWSD.cpp |2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

New commits:
commit 53ba8a130785778603db65d454e4f7ea158588f5
Author: Ashod Nakashian 
Date:   Sat Sep 17 09:48:39 2016 -0400

loolwsd: use std sleep_for rather than POSIX or Poco

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

diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp
index 5b10efa..eb91903 100644
--- a/loolwsd/Connect.cpp
+++ b/loolwsd/Connect.cpp
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -200,7 +201,8 @@ protected:
 std::unique_lock lock(coutMutex);
 std::cout << "Sleeping " << sleepTime << " seconds" << 
std::endl;
 }
-Thread::sleep(sleepTime * 1000);
+
+std::this_thread::sleep_for(std::chrono::seconds(sleepTime));
 }
 else if (line == "exit")
 {
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index b496a1b..9f1d6d7 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1923,7 +1923,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 }
 }
 
-sleep(WSD_SLEEP_SECS);
+std::this_thread::sleep_for(std::chrono::seconds(WSD_SLEEP_SECS));
 
 // Make sure we have sufficient reserves.
 prespawnChildren();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/Connect.cpp loolwsd/IoUtil.cpp loolwsd/IoUtil.hpp loolwsd/LOOLKit.cpp loolwsd/LOOLTool.cpp loolwsd/MessageQueue.cpp loolwsd/MessageQueue.hpp loolwsd/TileCache

2016-04-27 Thread Miklos Vajna
 loolwsd/Connect.cpp  |2 +-
 loolwsd/IoUtil.cpp   |   12 ++--
 loolwsd/IoUtil.hpp   |   12 ++--
 loolwsd/LOOLKit.cpp  |2 +-
 loolwsd/LOOLTool.cpp |2 +-
 loolwsd/MessageQueue.cpp |2 +-
 loolwsd/MessageQueue.hpp |2 +-
 loolwsd/TileCache.cpp|2 +-
 8 files changed, 18 insertions(+), 18 deletions(-)

New commits:
commit 78308db763bf8886ec440298fe44377b5ea7f27b
Author: Miklos Vajna 
Date:   Wed Apr 27 14:58:33 2016 +0200

loolwsd: remaining 'unnecessary copy' fixes

Change-Id: I138e8473a002a15aae7752136950bb905a21fb1f

diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp
index 8c10f27..e1255bf 100644
--- a/loolwsd/Connect.cpp
+++ b/loolwsd/Connect.cpp
@@ -211,7 +211,7 @@ protected:
 }
 break;
 }
-else if (line.find("#") == 0)
+else if (line.find('#') == 0)
 {
 // Also comments can be useful in input files for this program
 }
diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp
index 92b0254..5e58a23 100644
--- a/loolwsd/IoUtil.cpp
+++ b/loolwsd/IoUtil.cpp
@@ -39,10 +39,10 @@ namespace IoUtil
 
 // Synchronously process WebSocket requests and dispatch to handler.
 // Handler returns false to end.
-void SocketProcessor(std::shared_ptr ws,
- std::function&)> handler,
- std::function closeFrame,
- std::function stopPredicate)
+void SocketProcessor(const std::shared_ptr& ws,
+ const std::function&)>& 
handler,
+ const std::function& closeFrame,
+ const std::function& stopPredicate)
 {
 Log::info("SocketProcessor starting.");
 
@@ -182,7 +182,7 @@ void SocketProcessor(std::shared_ptr ws,
 Log::info("SocketProcessor finished.");
 }
 
-void shutdownWebSocket(std::shared_ptr ws)
+void shutdownWebSocket(const std::shared_ptr& ws)
 {
 try
 {
@@ -247,7 +247,7 @@ ssize_t readFIFO(int pipe, char* buffer, ssize_t size)
 /// Returns 0 for timeout, <0 for error, and >0 on success.
 /// On success, line will contain the read message.
 int PipeReader::readLine(std::string& line,
- std::function stopPredicate)
+ const std::function& stopPredicate)
 {
 const char *endOfLine = static_cast(std::memchr(_data.data(), '\n', _data.size()));
 if (endOfLine != nullptr)
diff --git a/loolwsd/IoUtil.hpp b/loolwsd/IoUtil.hpp
index 2b49658..6f98136 100644
--- a/loolwsd/IoUtil.hpp
+++ b/loolwsd/IoUtil.hpp
@@ -23,13 +23,13 @@ namespace IoUtil
 {
 /// Synchronously process WebSocket requests and dispatch to handler.
 //. Handler returns false to end.
-void SocketProcessor(std::shared_ptr ws,
- std::function&)> handler,
- std::function closeFrame,
- std::function stopPredicate);
+void SocketProcessor(const std::shared_ptr& ws,
+ const std::function&)>& 
handler,
+ const std::function& closeFrame,
+ const std::function& stopPredicate);
 
 /// Call WebSocket::shutdown() ignoring Poco::IOException.
-void shutdownWebSocket(std::shared_ptr ws);
+void shutdownWebSocket(const std::shared_ptr& ws);
 
 ssize_t writeFIFO(int pipe, const char* buffer, ssize_t size);
 inline
@@ -55,7 +55,7 @@ namespace IoUtil
 /// Returns 0 for timeout, <0 for error, and >0 on success.
 /// On success, line will contain the read message.
 int readLine(std::string& line,
- std::function stopPredicate);
+ const std::function& stopPredicate);
 
 private:
 const std::string _name;
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 7a95bcb..5af4248 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -839,7 +839,7 @@ private:
 };
 
 namespace {
-void symlinkPathToJail(const Path jailPath, const std::string &loTemplate,
+void symlinkPathToJail(const Path& jailPath, const std::string &loTemplate,
const std::string &loSubPath)
 {
 Path symlinkSource(jailPath, Path(loTemplate.substr(1)));
diff --git a/loolwsd/LOOLTool.cpp b/loolwsd/LOOLTool.cpp
index 2e0acfc..7429ed2 100644
--- a/loolwsd/LOOLTool.cpp
+++ b/loolwsd/LOOLTool.cpp
@@ -92,7 +92,7 @@ public:
 
 void run() override
 {
-for (auto i : _files)
+for (const auto& i : _files)
 convertFile(i);
 }
 
diff --git a/loolwsd/MessageQueue.cpp b/loolwsd/MessageQueue.cpp
index 2dd57db..e6ef3d6 100644
--- a/loolwsd/MessageQueue.cpp
+++ b/loolwsd/MessageQueue.cpp
@@ -37,7 +37,7 @@ void MessageQueue::clear()
 clear_impl();
 }
 
-void MessageQueue::remove_if(std::function pred)
+void MessageQueue::remove_if(const std::function& pred)
 {
 std::unique_lock lock(_mutex);
 std::remove_if(_queue.begin(), _queue.e

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

2016-04-18 Thread Tor Lillqvist
 loolwsd/Connect.cpp |   12 
 1 file changed, 12 insertions(+)

New commits:
commit 5c0788254b14eda55266074563486f9eb02bc309
Author: Tor Lillqvist 
Date:   Mon Apr 18 21:09:36 2016 +0300

Add "exit" command and comment syntax to input files for the 'connect' 
program

diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp
index b7c5c70..8f64ff3 100644
--- a/loolwsd/Connect.cpp
+++ b/loolwsd/Connect.cpp
@@ -187,6 +187,18 @@ protected:
 std::cout << "Sleeping " << sleepTime << " seconds" << 
std::endl;
 Thread::sleep(sleepTime * 1000);
 }
+else if (line == "exit")
+{
+// While hacking on LOOL and editing input files for this 
program back and forth it
+// is a good idea to be able to add an enforced exit in the 
middle of the input
+// file.
+std::cout << "Exiting" << std::endl;
+break;
+}
+else if (line.find("#") == 0)
+{
+// Also comments can be useful in input files for this program
+}
 else
 {
 std::cout << "Sending: '" << line << "'" << std::endl;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-14 Thread Tor Lillqvist
 loolwsd/Connect.cpp |6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

New commits:
commit fe5f238c0885f272daaf78346ce6c881ace11033
Author: Tor Lillqvist 
Date:   Thu Apr 14 17:45:46 2016 +0300

Exit when receiving an *unexpected* CLOSE frame

Otherwise we will just keep waiting for a line on input from stdin,
which is unhelpful.

diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp
index 7f0bf83..b7c5c70 100644
--- a/loolwsd/Connect.cpp
+++ b/loolwsd/Connect.cpp
@@ -67,6 +67,8 @@ using Poco::Thread;
 using Poco::URI;
 using Poco::Util::Application;
 
+static bool closeExpected = false;
+
 class Output: public Runnable
 {
 public:
@@ -108,6 +110,8 @@ public:
 }
 while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE);
 std::cout << "CLOSE frame received" << std::endl;
+if (!closeExpected)
+std::_Exit(Application::EXIT_SOFTWARE);
 }
 catch (WebSocketException& exc)
 {
@@ -116,7 +120,6 @@ public:
 }
 
 WebSocket& _ws;
-
 };
 
 class Connect: public Poco::Util::Application
@@ -192,6 +195,7 @@ protected:
 }
 
 std::cout << "Shutting down websocket" << std::endl;
+closeExpected = true;
 ws.shutdown();
 thread.join();
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-09 Thread Ashod Nakashian
 loolwsd/Connect.cpp  |1 +
 loolwsd/UnitHTTP.hpp |1 +
 2 files changed, 2 insertions(+)

New commits:
commit 435b706f9a687f195d65e794827845416a3931c2
Author: Ashod Nakashian 
Date:   Sat Apr 9 15:39:20 2016 -0400

loolwsd: must include Poco/Version.h to define POCO_VERSION

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

diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp
index 5233b77..91c1418 100644
--- a/loolwsd/Connect.cpp
+++ b/loolwsd/Connect.cpp
@@ -14,6 +14,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
diff --git a/loolwsd/UnitHTTP.hpp b/loolwsd/UnitHTTP.hpp
index 4585caf..1c8f77e 100644
--- a/loolwsd/UnitHTTP.hpp
+++ b/loolwsd/UnitHTTP.hpp
@@ -9,6 +9,7 @@
 #ifndef INCLUDED_UNITHTTP_HPP
 #define INCLUDED_UNITHTTP_HPP
 
+#include 
 #include 
 #include 
 #include 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-08 Thread Tor Lillqvist
 loolwsd/Connect.cpp   |2 ++
 loolwsd/Storage.cpp   |2 ++
 loolwsd/test/httpposttest.cpp |2 ++
 loolwsd/test/httpwstest.cpp   |2 ++
 4 files changed, 8 insertions(+)

New commits:
commit 407f688cb67064d55e241ae3ed8e7ecd0d81561d
Author: Tor Lillqvist 
Date:   Fri Apr 8 14:49:33 2016 +0300

Include config.h to get ENABLE_SSL

diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp
index b48d2ba..5233b77 100644
--- a/loolwsd/Connect.cpp
+++ b/loolwsd/Connect.cpp
@@ -7,6 +7,8 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#include "config.h"
+
 #include 
 #include 
 #include 
diff --git a/loolwsd/Storage.cpp b/loolwsd/Storage.cpp
index c2ea816..849148c 100644
--- a/loolwsd/Storage.cpp
+++ b/loolwsd/Storage.cpp
@@ -7,6 +7,8 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#include "config.h"
+
 #include 
 #include 
 #include 
diff --git a/loolwsd/test/httpposttest.cpp b/loolwsd/test/httpposttest.cpp
index 35afcf7..5f71ebb 100644
--- a/loolwsd/test/httpposttest.cpp
+++ b/loolwsd/test/httpposttest.cpp
@@ -7,6 +7,8 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#include "config.h"
+
 #include 
 #include 
 #include 
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index 3591ae6..aad1e37 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -7,6 +7,8 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#include "config.h"
+
 #include 
 #include 
 #include 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/Connect.cpp loolwsd/LoadTest.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/test

2016-01-21 Thread Ashod Nakashian
 loolwsd/Connect.cpp |3 +--
 loolwsd/LOOLKit.cpp |5 ++---
 loolwsd/LOOLWSD.cpp |   20 +++-
 loolwsd/LoadTest.cpp|3 +--
 loolwsd/test/httpwstest.cpp |4 ++--
 5 files changed, 17 insertions(+), 18 deletions(-)

New commits:
commit 291b0aac6714094050f289bc720c64ea1ee89add
Author: Ashod Nakashian 
Date:   Thu Jan 21 09:00:58 2016 -0500

loolwsd: don't ignore the last few bytes of a closed socket

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

diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp
index 2f81a67..3aceeaf 100644
--- a/loolwsd/Connect.cpp
+++ b/loolwsd/Connect.cpp
@@ -76,8 +76,7 @@ public:
 {
 char buffer[10];
 n = _ws.receiveFrame(buffer, sizeof(buffer), flags);
-
-if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE)
+if (n > 0)
 {
 std::cout << "Got " << n << " bytes: " << 
getAbbreviatedMessage(buffer, n) << std::endl;
 
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index bceb1fa..c9160c3 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -381,8 +381,7 @@ public:
 {
 char buffer[1024];
 n = _ws->receiveFrame(buffer, sizeof(buffer), flags);
-
-if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE)
+if (n > 0)
 {
 std::string firstLine = getFirstLine(buffer, n);
 if (firstLine == "eof")
@@ -410,7 +409,7 @@ public:
 handle(queue, firstLine, buffer, n);
 }
 }
-while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE && !_stop);
+while (!_stop && n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE);
 Log::debug() << "Finishing " << thread_name << ". stop " << _stop
  << ", payload size: " << n
  << ", flags: " << std::hex << flags << Log::end;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index c0af9e3..78d53fd 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -223,8 +223,14 @@ void SocketProcessor(std::shared_ptr ws,
 {
 continue;
 }
-else if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE)
+else if (n <= 0)
 {
+// Connection closed.
+break;
+}
+else
+{
+assert(n > 0);
 const std::string firstLine = getFirstLine(buffer, n);
 if (firstLine == "eof")
 {
@@ -267,13 +273,10 @@ void SocketProcessor(std::shared_ptr ws,
 char largeBuffer[size]; //FIXME: Security 
risk! Flooding may segfault us.
 
 n = ws->receiveFrame(largeBuffer, size, flags);
-if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) 
!= WebSocket::FRAME_OP_CLOSE)
+if (n > 0 && !handler(largeBuffer, n, false))
 {
-if (!handler(largeBuffer, n, false))
-{
-Log::info("Socket handler flagged for 
finishing.");
-break;
-}
+Log::info("Socket handler flagged for 
finishing.");
+break;
 }
 }
 else
@@ -613,8 +616,7 @@ public:
 {
 char buffer[20];
 n = _ws.receiveFrame(buffer, sizeof(buffer), flags);
-
-if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE)
+if (n > 0)
 {
 Log::trace() << "Client got " << n << " bytes: "
  << getAbbreviatedMessage(buffer, n) << 
Log::end;
diff --git a/loolwsd/LoadTest.cpp b/loolwsd/LoadTest.cpp
index aaa2e3e..24fceec 100644
--- a/loolwsd/LoadTest.cpp
+++ b/loolwsd/LoadTest.cpp
@@ -92,8 +92,7 @@ public:
 {
 char buffer[10];
 n = _ws.receiveFrame(buffer, sizeof(buffer), flags);
-
-if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE)
+if (n > 0)
 {
 #if 0
 Log::debug() << "Client got " << n << " bytes: "
diff --git a/loolwsd/test/httpwstest.cpp b/loolw