loolwsd/Connect.cpp | 2 +- loolwsd/LOOLBroker.cpp | 6 +++--- loolwsd/LOOLKit.cpp | 2 +- loolwsd/LOOLWSD.cpp | 10 +++++++--- loolwsd/LoadTest.cpp | 5 +++-- loolwsd/test/httpwstest.cpp | 7 +++++-- 6 files changed, 20 insertions(+), 12 deletions(-)
New commits: commit 32dc0a3c87f3c97ee7e6ce9bc0e642365566fa3b Author: Tor Lillqvist <[email protected]> Date: Tue Feb 23 20:03:43 2016 +0200 Don't ever attempt to handle the payload of CLOSE frames diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp index 3aceeaf..43da98b 100644 --- a/loolwsd/Connect.cpp +++ b/loolwsd/Connect.cpp @@ -76,7 +76,7 @@ public: { char buffer[100000]; n = _ws.receiveFrame(buffer, sizeof(buffer), flags); - if (n > 0) + if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE) { std::cout << "Got " << n << " bytes: " << getAbbreviatedMessage(buffer, n) << std::endl; diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 4bc41fb..94559aa 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -224,7 +224,7 @@ public: { char buffer[1024]; n = _ws->receiveFrame(buffer, sizeof(buffer), flags); - if (n > 0) + if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE) { std::string firstLine = getFirstLine(buffer, n); if (firstLine == "eof") diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index feb7bef..19e8a8e 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -232,7 +232,7 @@ void SocketProcessor(std::shared_ptr<WebSocket> ws, << std::hex << flags << Log::end; break; } - else + else if ((flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE) { assert(n > 0); const std::string firstLine = getFirstLine(buffer, n); @@ -252,6 +252,10 @@ void SocketProcessor(std::shared_ptr<WebSocket> ws, while (true) { n = ws->receiveFrame(buffer, sizeof(buffer), flags); + + if (n <= 0 || (flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_CLOSE) + break; + message.insert(message.end(), buffer, buffer + n); if ((flags & WebSocket::FrameFlags::FRAME_FLAG_FIN) == WebSocket::FrameFlags::FRAME_FLAG_FIN) { @@ -272,7 +276,7 @@ void SocketProcessor(std::shared_ptr<WebSocket> ws, char largeBuffer[size]; //FIXME: Security risk! Flooding may segfault us. n = ws->receiveFrame(largeBuffer, size, flags); - if (n > 0 && !handler(largeBuffer, n, false)) + if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE && !handler(largeBuffer, n, false)) { Log::info("Socket handler flagged for finishing."); break; @@ -679,7 +683,7 @@ public: { char buffer[200000]; n = _ws.receiveFrame(buffer, sizeof(buffer), flags); - if (n > 0) + if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE) { Log::trace() << "Client got " << n << " bytes: " << getAbbreviatedMessage(buffer, n) << Log::end; diff --git a/loolwsd/LoadTest.cpp b/loolwsd/LoadTest.cpp index 24fceec..f9df891 100644 --- a/loolwsd/LoadTest.cpp +++ b/loolwsd/LoadTest.cpp @@ -92,7 +92,7 @@ public: { char buffer[100000]; n = _ws.receiveFrame(buffer, sizeof(buffer), flags); - if (n > 0) + if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE) { #if 0 Log::debug() << "Client got " << n << " bytes: " @@ -112,7 +112,8 @@ public: Log::debug() << "Client got " << n << " bytes: " << getAbbreviatedMessage(largeBuffer, n) << Log::end; #endif - response = getFirstLine(buffer, n); + if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE) + response = getFirstLine(largeBuffer, n); } else if (tokens[0] == "loolclient") { commit 7320d8ca51b7aa2c2a2fde98813f77e248cafa9e Author: Tor Lillqvist <[email protected]> Date: Tue Feb 23 20:02:54 2016 +0200 Bin unused 'using' diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp index 8ea1689..05e67b1 100644 --- a/loolwsd/test/httpwstest.cpp +++ b/loolwsd/test/httpwstest.cpp @@ -24,8 +24,6 @@ #include <Common.hpp> #include <ChildProcessSession.hpp> -using Poco::StringTokenizer; - /// Tests the HTTP WebSocket API of loolwsd. The server has to be started manually before running this test. class HTTPWSTest : public CPPUNIT_NS::TestFixture { commit 79037b687e916f0c1240e3fea34b6cc5b7745862 Author: Tor Lillqvist <[email protected]> Date: Tue Feb 23 20:02:29 2016 +0200 Log received messages to stderr diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp index dca3f75..8ea1689 100644 --- a/loolwsd/test/httpwstest.cpp +++ b/loolwsd/test/httpwstest.cpp @@ -108,6 +108,7 @@ void HTTPWSTest::testPaste() n = socket.receiveFrame(buffer, sizeof(buffer), flags); if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE) { + std::cerr << "Received message length " << n << ": " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << '\n'; const std::string line = LOOLProtocol::getFirstLine(buffer, n); const std::string prefix = "textselectioncontent: "; if (line.find(prefix) == 0) @@ -162,6 +163,7 @@ void HTTPWSTest::testLargePaste() n = socket.receiveFrame(buffer, sizeof(buffer), flags); if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE) { + std::cerr << "Received message length " << n << ": " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << '\n'; std::string line = LOOLProtocol::getFirstLine(buffer, n); std::string prefix = "textselectioncontent: "; if (line.find(prefix) == 0) @@ -200,6 +202,7 @@ void HTTPWSTest::testRenderingOptions() n = socket.receiveFrame(buffer, sizeof(buffer), flags); if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE) { + std::cerr << "Received message length " << n << ": " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << '\n'; std::string line = LOOLProtocol::getFirstLine(buffer, n); std::string prefix = "status: "; if (line.find(prefix) == 0) @@ -404,6 +407,7 @@ bool HTTPWSTest::isDocumentLoaded(Poco::Net::WebSocket& ws) bytes = ws.receiveFrame(buffer, sizeof(buffer), flags); if (bytes > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE) { + std::cerr << "Received message length " << bytes << ": " << LOOLProtocol::getAbbreviatedMessage(buffer, bytes) << '\n'; const std::string line = LOOLProtocol::getFirstLine(buffer, bytes); const std::string prefixIndicator = "statusindicatorfinish:"; const std::string prefixStatus = "status:"; @@ -450,6 +454,7 @@ void HTTPWSTest::getResponseMessage(Poco::Net::WebSocket& ws, const std::string& bytes = ws.receiveFrame(buffer, sizeof(buffer), flags); if (bytes > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE) { + std::cerr << "Received message length " << bytes << ": " << LOOLProtocol::getAbbreviatedMessage(buffer, bytes) << '\n'; const std::string message = isLine ? LOOLProtocol::getFirstLine(buffer, bytes) : std::string(buffer, bytes); commit fbee03cae258ca2646e2d4ec88bfa862ce5c9560 Author: Tor Lillqvist <[email protected]> Date: Tue Feb 23 15:48:15 2016 +0200 Minor clarification No need to pass the value of a variable, initialised much earlier, to a system call when one can pass the required constant value as such. Much clearer. diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp index a8ed8e3..bc11143 100644 --- a/loolwsd/LOOLBroker.cpp +++ b/loolwsd/LOOLBroker.cpp @@ -486,7 +486,6 @@ static int createLibreOfficeKit(const bool sharePages, { Process::PID childPID; int fifoWriter = -1; - int flags = O_WRONLY | O_NONBLOCK; const Path pipePath = Path::forDirectory(childRoot + Path::separator() + FIFO_PATH); const std::string pipeKit = Path(pipePath, BROKER_PREFIX + std::to_string(childCounter++) + BROKER_SUFIX).toString(); @@ -567,9 +566,9 @@ static int createLibreOfficeKit(const bool sharePages, fifoCV.wait_for( lock, std::chrono::microseconds(80000), - [&fifoWriter, &pipeKit, flags] + [&fifoWriter, &pipeKit] { - return (fifoWriter = open(pipeKit.c_str(), flags)) >= 0; + return (fifoWriter = open(pipeKit.c_str(), O_WRONLY | O_NONBLOCK)) >= 0; }); if (fifoWriter < 0) @@ -590,6 +589,7 @@ static int createLibreOfficeKit(const bool sharePages, return -1; } + int flags; if ((flags = fcntl(fifoWriter, F_GETFL, 0)) < 0) { Log::error("Error: failed to get pipe flags [" + pipeKit + "]."); _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
