[Libreoffice-commits] online.git: net/Socket.cpp net/WebSocketHandler.hpp
net/Socket.cpp |6 -- net/WebSocketHandler.hpp | 33 ++--- 2 files changed, 22 insertions(+), 17 deletions(-) New commits: commit d664d4ab40f699d2efec34b7c2d7c99a6b18a7be Author: Tor Lillqvist AuthorDate: Wed Jun 24 13:50:08 2020 +0300 Commit: Tor Lillqvist CommitDate: Wed Jun 24 13:27:47 2020 +0200 No pinging necessary in the MOBILEAPP case There aren't multiple processes that would need to "ping" each others. Ifdef out the related member variables and code completely. Having them partially in caused lots of FakeSocket polling with zero timeout which is less than ideal. Change-Id: Ibdfa4980d6d4fc9c00ea5146ca8d75ca0df81f1d Reviewed-on: https://gerrit.libreoffice.org/c/online/+/97021 Tested-by: Jenkins Tested-by: Jenkins CollaboraOffice Reviewed-by: Tor Lillqvist diff --git a/net/Socket.cpp b/net/Socket.cpp index 0d0b3ed0b..cc0e9cf64 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -525,8 +525,10 @@ const int WebSocketHandler::PingFrequencyMicroS = 18 * 1000 * 1000; void WebSocketHandler::dumpState(std::ostream& os) { -os << (_shuttingDown ? "shutd " : "alive ") - << std::setw(5) << _pingTimeUs/1000. << "ms "; +os << (_shuttingDown ? "shutd " : "alive "); +#if !MOBILEAPP +os << std::setw(5) << _pingTimeUs/1000. << "ms "; +#endif if (_wsPayload.size() > 0) Util::dumpHex(os, "\t\tws queued payload:\n", "\t\t", _wsPayload); os << '\n'; diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp index 9c4ac5bb4..4aca03e38 100644 --- a/net/WebSocketHandler.hpp +++ b/net/WebSocketHandler.hpp @@ -29,16 +29,16 @@ private: /// The socket that owns us (we can't own it). std::weak_ptr _socket; +#if !MOBILEAPP std::chrono::steady_clock::time_point _lastPingSentTime; int _pingTimeUs; +bool _isMasking; +bool _inFragmentBlock; +#endif std::vector _wsPayload; std::atomic _shuttingDown; bool _isClient; -#if !MOBILEAPP -bool _isMasking; -bool _inFragmentBlock; -#endif protected: struct WSFrameMask @@ -60,15 +60,15 @@ public: /// defragmentation should be handled inside message handler (true) or the message handler /// should be called after all fragments of a message were received and the message /// was defragmented (false). -WebSocketHandler(bool isClient = false, bool isMasking = true) -: _lastPingSentTime(std::chrono::steady_clock::now()) -, _pingTimeUs(0) -, _shuttingDown(false) -, _isClient(isClient) +WebSocketHandler(bool isClient = false, bool isMasking = true) : #if !MOBILEAPP -, _isMasking(isClient && isMasking) -, _inFragmentBlock(false) +_lastPingSentTime(std::chrono::steady_clock::now()), +_pingTimeUs(0), +_isMasking(isClient && isMasking), +_inFragmentBlock(false), #endif +_shuttingDown(false), +_isClient(isClient) { } @@ -79,16 +79,16 @@ public: WebSocketHandler(const std::weak_ptr& socket, const Poco::Net::HTTPRequest& request) : _socket(socket) +#if !MOBILEAPP , _lastPingSentTime(std::chrono::steady_clock::now() - std::chrono::microseconds(PingFrequencyMicroS) - std::chrono::microseconds(InitialPingDelayMicroS)) , _pingTimeUs(0) -, _shuttingDown(false) -, _isClient(false) -#if !MOBILEAPP , _isMasking(false) , _inFragmentBlock(false) #endif +, _shuttingDown(false) +, _isClient(false) { upgradeToWebSocket(request); } @@ -430,12 +430,14 @@ public: int getPollEvents(std::chrono::steady_clock::time_point now, int64_t & timeoutMaxMicroS) override { +#if !MOBILEAPP if (!_isClient) { const int64_t timeSincePingMicroS = std::chrono::duration_cast(now - _lastPingSentTime).count(); timeoutMaxMicroS = std::min(timeoutMaxMicroS, PingFrequencyMicroS - timeSincePingMicroS); } +#endif int events = POLLIN; if (_msgHandler && _msgHandler->hasQueuedMessages()) events |= POLLOUT; @@ -810,10 +812,11 @@ protected: std::shared_ptr socket = _socket.lock(); if (socket) socket->setWebSocket(); - +#if !MOBILEAPP // No need to ping right upon connection/upgrade, // but do reset the time to avoid pinging immediately after. _lastPingSentTime = std::chrono::steady_clock::now(); +#endif } }; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp
net/Socket.cpp | 11 +-- 1 file changed, 9 insertions(+), 2 deletions(-) New commits: commit 9cfdba5f56c5da3a5e6b6f947a251647db367e4f Author: Jan Holesovsky AuthorDate: Fri Jun 12 12:19:50 2020 +0200 Commit: Jan Holesovsky CommitDate: Fri Jun 12 12:53:07 2020 +0200 Snap needs a specific unix socket name. Change-Id: I7fd816eb6d23df0f27e40f345181833dbe85e022 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96197 Tested-by: Jenkins Tested-by: Jenkins CollaboraOffice Reviewed-by: Jan Holesovsky diff --git a/net/Socket.cpp b/net/Socket.cpp index ee76a5a1a..0d0b3ed0b 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -755,15 +755,22 @@ std::string LocalServerSocket::bind() { int rc; struct sockaddr_un addrunix; + +// snap needs a specific socket name +std::string socketAbstractUnixName(SOCKET_ABSTRACT_UNIX_NAME); +const char* snapInstanceName = std::getenv("SNAP_INSTANCE_NAME"); +if (snapInstanceName && snapInstanceName[0]) +socketAbstractUnixName = std::string("0snap.") + snapInstanceName + ".loolwsd-"; + do { std::memset(&addrunix, 0, sizeof(addrunix)); addrunix.sun_family = AF_UNIX; -std::memcpy(addrunix.sun_path, SOCKET_ABSTRACT_UNIX_NAME, sizeof(SOCKET_ABSTRACT_UNIX_NAME)); +std::memcpy(addrunix.sun_path, socketAbstractUnixName.c_str(), socketAbstractUnixName.length()); addrunix.sun_path[0] = '\0'; // abstract name std::string rand = Util::rng::getFilename(8); -memcpy(addrunix.sun_path + sizeof(SOCKET_ABSTRACT_UNIX_NAME) - 1, rand.c_str(), 8); +memcpy(addrunix.sun_path + socketAbstractUnixName.length(), rand.c_str(), 8); rc = ::bind(getFD(), (const sockaddr *)&addrunix, sizeof(struct sockaddr_un)); LOG_TRC("Bind to location " << std::string(&addrunix.sun_path[1]) << ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp test/UnitWOPITemplate.cpp wsd/ClientSession.cpp wsd/FileServer.cpp wsd/LOOLWSD.cpp
net/Socket.cpp| 38 ++ net/Socket.hpp|8 test/UnitWOPITemplate.cpp |4 +--- wsd/ClientSession.cpp |2 +- wsd/FileServer.cpp|3 ++- wsd/LOOLWSD.cpp |8 ++-- 6 files changed, 32 insertions(+), 31 deletions(-) New commits: commit 714640993bb09f34cef97e878fd8e8b13ea4fb2b Author: Michael Meeks AuthorDate: Wed Jun 3 16:06:10 2020 +0100 Commit: Michael Meeks CommitDate: Wed Jun 3 18:15:33 2020 +0200 Remember to shutdown the socket after serving files. re-factor to make it hard not to. Change-Id: I26ebc48b4660276ede64a22167ac4779cebf5cd4 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/95440 Tested-by: Jenkins CollaboraOffice Reviewed-by: Michael Meeks diff --git a/net/Socket.cpp b/net/Socket.cpp index e388d412a..ee76a5a1a 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -1022,14 +1022,19 @@ namespace HttpHelper } } -void sendFile(const std::shared_ptr& socket, - const std::string& path, - const std::string& mediaType, - Poco::Net::HTTPResponse& response, - const bool noCache, - const bool deflate, - const bool headerOnly) +void sendFileAndShutdown(const std::shared_ptr& socket, + const std::string& path, + const std::string& mediaType, + Poco::Net::HTTPResponse *optResponse, + const bool noCache, + const bool deflate, + const bool headerOnly) { +Poco::Net::HTTPResponse *response = optResponse; +Poco::Net::HTTPResponse localResponse; +if (!response) +response = &localResponse; + struct stat st; if (stat(path.c_str(), &st) != 0) { @@ -1040,16 +1045,16 @@ namespace HttpHelper if (!noCache) { // 60 * 60 * 24 * 128 (days) = 11059200 -response.set("Cache-Control", "max-age=11059200"); -response.set("ETag", "\"" LOOLWSD_VERSION_HASH "\""); +response->set("Cache-Control", "max-age=11059200"); +response->set("ETag", "\"" LOOLWSD_VERSION_HASH "\""); } else { -response.set("Cache-Control", "no-cache"); +response->set("Cache-Control", "no-cache"); } -response.setContentType(mediaType); -response.add("X-Content-Type-Options", "nosniff"); +response->setContentType(mediaType); +response->add("X-Content-Type-Options", "nosniff"); int bufferSize = std::min(st.st_size, (off_t)Socket::MaximumSendBufferSize); if (st.st_size >= socket->getSendBufferSize()) @@ -1063,24 +1068,25 @@ namespace HttpHelper // IE/Edge before enabling the deflate again if (!deflate || true) { -response.setContentLength(st.st_size); +response->setContentLength(st.st_size); LOG_TRC('#' << socket->getFD() << ": Sending " << (headerOnly ? "header for " : "") << " file [" << path << "]."); -socket->send(response); +socket->send(*response); if (!headerOnly) sendUncompressedFileContent(socket, path, bufferSize); } else { -response.set("Content-Encoding", "deflate"); +response->set("Content-Encoding", "deflate"); LOG_TRC('#' << socket->getFD() << ": Sending " << (headerOnly ? "header for " : "") << " file [" << path << "]."); -socket->send(response); +socket->send(*response); if (!headerOnly) sendDeflatedFileContent(socket, path, st.st_size); } +socket->shutdown(); } } diff --git a/net/Socket.hpp b/net/Socket.hpp index 7e011bb9d..55cfe05bb 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -1278,10 +1278,10 @@ enum class WSOpCode : unsigned char { namespace HttpHelper { -/// Sends file as HTTP response. -void sendFile(const std::shared_ptr& socket, const std::string& path, const std::string& mediaType, - Poco::Net::HTTPResponse& response, bool noCache = false, bool deflate = false, - const bool headerOnly = false); +/// Sends file as HTTP response and shutdown the socket. +void sendFileAndShutdown(const std::shared_ptr& socket, const std::string& path, const std::string& mediaType, + Poco::Net::HTTPResponse *optResponse = nullptr, bool noCache = false, bool deflate = false, + const bool headerOnly = false); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/UnitWOPITemplate.cpp b/test/UnitWOPITemplate.cpp i
[Libreoffice-commits] online.git: net/Socket.cpp
net/Socket.cpp |4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) New commits: commit a87bafb403a983d34886f784808bb13f06db55d9 Author: Michael Meeks AuthorDate: Wed May 20 14:51:46 2020 +0100 Commit: Michael Meeks CommitDate: Thu May 21 22:26:50 2020 +0200 Improve exceptions. Change-Id: I7d10ff831563f47e8c01431803b307cdbcb20349 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/94579 Tested-by: Jenkins Tested-by: Jenkins CollaboraOffice Reviewed-by: Michael Meeks diff --git a/net/Socket.cpp b/net/Socket.cpp index 568fcca5e..0703f9c0a 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -928,14 +928,14 @@ bool StreamSocket::parseHeader(const char *clientName, } catch (const Poco::Exception& exc) { -LOG_DBG("parseHeader exception caught: " << exc.displayText()); +LOG_DBG("parseHeader exception caught with " << _inBuffer.size() << " bytes: " << exc.displayText()); // Probably don't have enough data just yet. // TODO: timeout if we never get enough. return false; } catch (const std::exception& exc) { -LOG_DBG("parseHeader exception caught: " << exc.what()); +LOG_DBG("parseHeader std::exception caught with " << _inBuffer.size() << " bytes: " << exc.what()); // Probably don't have enough data just yet. // TODO: timeout if we never get enough. return false; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp wsd/ProxyProtocol.cpp
net/Socket.cpp|2 ++ wsd/ProxyProtocol.cpp |2 ++ 2 files changed, 4 insertions(+) New commits: commit b3d2e03b39a22c5acc419c5b7a8e09170ce0 Author: Michael Meeks AuthorDate: Sat Mar 21 14:27:15 2020 + Commit: Jan Holesovsky CommitDate: Fri Apr 24 16:43:22 2020 +0200 Proxy: ensure dumpState dumps via the MessageHandlerInterface too. Change-Id: If514e2359188d56bbf7ddef6e04f9d8bf5c50910 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92812 Tested-by: Jenkins CollaboraOffice Reviewed-by: Jan Holesovsky diff --git a/net/Socket.cpp b/net/Socket.cpp index 372f9ea1a..24041bc4b 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -524,6 +524,8 @@ void WebSocketHandler::dumpState(std::ostream& os) if (_wsPayload.size() > 0) Util::dumpHex(os, "\t\tws queued payload:\n", "\t\t", _wsPayload); os << "\n"; +if (_msgHandler) +_msgHandler->dumpState(os); } void StreamSocket::dumpState(std::ostream& os) diff --git a/wsd/ProxyProtocol.cpp b/wsd/ProxyProtocol.cpp index 6279682f2..c8f578559 100644 --- a/wsd/ProxyProtocol.cpp +++ b/wsd/ProxyProtocol.cpp @@ -217,6 +217,8 @@ void ProxyProtocolHandler::dumpState(std::ostream& os) os << "proxy protocol sockets: " << _outSockets.size() << " writeQueue: " << _writeQueue.size() << ":\n"; for (auto it : _writeQueue) Util::dumpHex(os, "\twrite queue entry:", "\t\t", *it); +if (_msgHandler) +_msgHandler->dumpState(os); } int ProxyProtocolHandler::getPollEvents(std::chrono::steady_clock::time_point /* now */, ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp
net/Socket.cpp |5 - net/Socket.hpp | 31 +-- wsd/DocumentBroker.cpp | 16 ++-- wsd/DocumentBroker.hpp |3 --- 4 files changed, 3 insertions(+), 52 deletions(-) New commits: commit 7d8477f5118d6f7fdc9b9a2b9be0fbe3dedc2b18 Author: Jan Holesovsky AuthorDate: Wed Apr 8 14:33:24 2020 +0200 Commit: Tor Lillqvist CommitDate: Thu Apr 9 13:27:29 2020 +0200 Revert "wsd: minimize wait when DocBroker terminates" With the change that is reverted here, the editing session on Android returns without proper cleanup which leads to occassional hangs when the user tries to open a new editing session quickly. Also, in the iOS app, with the change that is reverted, when closing the document we never get the LOK_CALLBACK_UNO_COMMAND_RESULT for the .uno:Save and thus we never get to save it properly from the system's point of view. This reverts commit a73590d81f4cf910568aa49f73e78abfb412eab7. Change-Id: Ia77fe2fd9b59d30c343ca1e10f69d5a434bc3628 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/91915 Tested-by: Jenkins CollaboraOffice Reviewed-by: Michael Meeks Reviewed-on: https://gerrit.libreoffice.org/c/online/+/91965 Reviewed-by: Tor Lillqvist diff --git a/net/Socket.cpp b/net/Socket.cpp index cb19c99cd..5bb1fa250 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -200,11 +200,6 @@ void SocketPoll::wakeupWorld() wakeup(fd); } -bool ProtocolHandlerInterface::hasPendingWork() const -{ -return _msgHandler && _msgHandler->hasQueuedMessages(); -} - #if !MOBILEAPP void SocketPoll::insertNewWebSocketSync( diff --git a/net/Socket.hpp b/net/Socket.hpp index fd0a5278d..ab56e5d10 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -162,9 +162,6 @@ public: std::chrono::steady_clock::time_point now, int events) = 0; -/// Is all data sent, so tha we can shutdown ? -virtual bool hasPendingWork() const { return false; } - /// manage latency issues around packet aggregation void setNoDelay() { @@ -293,7 +290,7 @@ public: } /// Asserts in the debug builds, otherwise just logs. -void assertCorrectThread() const +void assertCorrectThread() { if (InhibitThreadChecks) return; @@ -395,9 +392,6 @@ public: _msgHandler = msgHandler; } -/// Do we have something to send ? -virtual bool hasPendingWork() const; - /// Clear all external references virtual void dispose() { _msgHandler.reset(); } @@ -779,21 +773,6 @@ public: return _pollSockets.size(); } -bool hasPendingWork() const -{ -assertCorrectThread(); - -if (_newCallbacks.size() > 0 || -_newSockets.size() > 0) -return true; - -for (auto &i : _pollSockets) -if (i->hasPendingWork()) -return true; - -return false; -} - const std::string& name() const { return _name; } /// Start the polling thread (if desired) @@ -952,14 +931,6 @@ public: return events; } -bool hasPendingWork() const override -{ -assertCorrectThread(); -if (!_outBuffer.empty() || !_inBuffer.empty()) -return true; -return _socketHandler && _socketHandler->hasPendingWork(); -} - /// Send data to the socket peer. void send(const char* data, const int len, const bool flush = true) { diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 0c28b94bd..02f6d2a2b 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -448,14 +448,14 @@ void DocumentBroker::pollThread() << ", TerminationFlag: " << SigUtil::getTerminationFlag() << ". Terminating child with reason: [" << _closeReason << "]."); const auto flushStartTime = std::chrono::steady_clock::now(); -while (_poll->hasPendingWork() || hasDisconnectingSessions()) +while (_poll->getSocketCount()) { const auto now = std::chrono::steady_clock::now(); const int elapsedMs = std::chrono::duration_cast(now - flushStartTime).count(); if (elapsedMs > flushTimeoutMs) break; -_poll->poll(std::min(flushTimeoutMs - elapsedMs, POLL_TIMEOUT_MS / 10)); +_poll->poll(std::min(flushTimeoutMs - elapsedMs, POLL_TIMEOUT_MS / 5)); } LOG_INF("Finished flushing socket for doc [" << _docKey << "]. stop: " << _stop << ", continuePolling: " << @@ -480,18 +480,6 @@ void DocumentBroker::pollThread() LOG_INF("Finished docBroker polling thread for docKey [" << _docKey << "]."); } -bool DocumentBroker::hasDisconnectingSessions() const -{ -for (const auto& pair : _sessions) -{ -const std::shared_ptr &session = pair.second; -// need to wait around to fetch clipboards from disconnecting sessions. -
[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp
net/Socket.cpp |5 + net/Socket.hpp | 31 ++- wsd/DocumentBroker.cpp | 16 ++-- wsd/DocumentBroker.hpp |3 +++ 4 files changed, 52 insertions(+), 3 deletions(-) New commits: commit a73590d81f4cf910568aa49f73e78abfb412eab7 Author: Michael Meeks AuthorDate: Tue Mar 24 12:20:41 2020 + Commit: Michael Meeks CommitDate: Thu Mar 26 12:03:06 2020 +0100 wsd: minimize wait when DocBroker terminates Add checking up the stack to detect when we have clean queues and buffers so we can exit fast. Change-Id: I82c3843f816bbe869094c21f070774e6d034ac65 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90358 Reviewed-by: Michael Meeks Tested-by: Jenkins CollaboraOffice diff --git a/net/Socket.cpp b/net/Socket.cpp index 5bb1fa250..cb19c99cd 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -200,6 +200,11 @@ void SocketPoll::wakeupWorld() wakeup(fd); } +bool ProtocolHandlerInterface::hasPendingWork() const +{ +return _msgHandler && _msgHandler->hasQueuedMessages(); +} + #if !MOBILEAPP void SocketPoll::insertNewWebSocketSync( diff --git a/net/Socket.hpp b/net/Socket.hpp index a6395b9b4..d09c39334 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -162,6 +162,9 @@ public: std::chrono::steady_clock::time_point now, int events) = 0; +/// Is all data sent, so tha we can shutdown ? +virtual bool hasPendingWork() const { return false; } + /// manage latency issues around packet aggregation void setNoDelay() { @@ -290,7 +293,7 @@ public: } /// Asserts in the debug builds, otherwise just logs. -void assertCorrectThread() +void assertCorrectThread() const { if (InhibitThreadChecks) return; @@ -392,6 +395,9 @@ public: _msgHandler = msgHandler; } +/// Do we have something to send ? +virtual bool hasPendingWork() const; + /// Clear all external references virtual void dispose() { _msgHandler.reset(); } @@ -768,6 +774,21 @@ public: return _pollSockets.size(); } +bool hasPendingWork() const +{ +assertCorrectThread(); + +if (_newCallbacks.size() > 0 || +_newSockets.size() > 0) +return true; + +for (auto &i : _pollSockets) +if (i->hasPendingWork()) +return true; + +return false; +} + const std::string& name() const { return _name; } /// Start the polling thread (if desired) @@ -926,6 +947,14 @@ public: return events; } +bool hasPendingWork() const override +{ +assertCorrectThread(); +if (!_outBuffer.empty() || !_inBuffer.empty()) +return true; +return _socketHandler && _socketHandler->hasPendingWork(); +} + /// Send data to the socket peer. void send(const char* data, const int len, const bool flush = true) { diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 8c229fd18..4aa52622e 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -448,14 +448,14 @@ void DocumentBroker::pollThread() << ", TerminationFlag: " << SigUtil::getTerminationFlag() << ". Terminating child with reason: [" << _closeReason << "]."); const auto flushStartTime = std::chrono::steady_clock::now(); -while (_poll->getSocketCount()) +while (_poll->hasPendingWork() || hasDisconnectingSessions()) { const auto now = std::chrono::steady_clock::now(); const int elapsedMs = std::chrono::duration_cast(now - flushStartTime).count(); if (elapsedMs > flushTimeoutMs) break; -_poll->poll(std::min(flushTimeoutMs - elapsedMs, POLL_TIMEOUT_MS / 5)); +_poll->poll(std::min(flushTimeoutMs - elapsedMs, POLL_TIMEOUT_MS / 10)); } LOG_INF("Finished flushing socket for doc [" << _docKey << "]. stop: " << _stop << ", continuePolling: " << @@ -480,6 +480,18 @@ void DocumentBroker::pollThread() LOG_INF("Finished docBroker polling thread for docKey [" << _docKey << "]."); } +bool DocumentBroker::hasDisconnectingSessions() const +{ +for (const auto& pair : _sessions) +{ +const std::shared_ptr &session = pair.second; +// need to wait around to fetch clipboards from disconnecting sessions. +if (session->inWaitDisconnected()) +return true; +} +return false; +} + bool DocumentBroker::isAlive() const { if (!_stop || _poll->isAlive()) diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp index 68369d274..e304cd60c 100644 --- a/wsd/DocumentBroker.hpp +++ b/wsd/DocumentBroker.hpp @@ -442,6 +442,9 @@ private: /// Starts the Kit <-> DocumentBroker shutdown handshake void disconnectSessionInternal(const std::string& id); +/// Are any of our sessions still dis-conn
[Libreoffice-commits] online.git: net/Socket.cpp
net/Socket.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit 68d834ac4fea7405acffa547da3436afc7648cbd Author: Ashod Nakashian AuthorDate: Thu Sep 19 10:08:45 2019 -0400 Commit: Ashod Nakashian CommitDate: Sun Sep 22 20:18:51 2019 +0200 wsd: asan: stack-use-after-scope Change-Id: Ia14e67f36b22ab45782cf0d1808b71e37b834104 Reviewed-on: https://gerrit.libreoffice.org/79324 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/net/Socket.cpp b/net/Socket.cpp index f5661c3dd..345e1d652 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -693,7 +693,7 @@ bool StreamSocket::parseHeader(const char *clientName, if (map) map->_messageSize += contentLength; -const std::string& expect = request.get("Expect", ""); +const std::string expect = request.get("Expect", ""); bool getExpectContinue = !expect.empty() && Poco::icompare(expect, "100-continue") == 0; if (getExpectContinue && !_sentHTTPContinue) { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp tools/WebSocketDump.cpp wsd/LOOLWSD.cpp wsd/TraceFile.hpp
net/Socket.cpp |2 +- tools/WebSocketDump.cpp |2 +- wsd/LOOLWSD.cpp |4 ++-- wsd/TraceFile.hpp |6 -- 4 files changed, 8 insertions(+), 6 deletions(-) New commits: commit 8aea22a32b28728033c4f06a79f93e63b1322151 Author: DarkByt31 AuthorDate: Fri Sep 6 15:26:30 2019 +0530 Commit: Michael Meeks CommitDate: Fri Sep 6 13:25:41 2019 +0200 tdf#107038 Poco::Timestamp replacement with std::chrono Replaced Poco::DateTimeFormatter with Util::getHttpTimeNow Change-Id: I1a8591a434140270929406386218d08c71a888cc Reviewed-on: https://gerrit.libreoffice.org/78700 Reviewed-by: Michael Meeks Tested-by: Michael Meeks diff --git a/net/Socket.cpp b/net/Socket.cpp index cb5043414..f5661c3dd 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -415,7 +415,7 @@ void StreamSocket::dumpState(std::ostream& os) void StreamSocket::send(Poco::Net::HTTPResponse& response) { response.set("User-Agent", HTTP_AGENT_STRING); -response.set("Date", Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT)); +response.set("Date", Util::getHttpTimeNow()); std::ostringstream oss; response.write(oss); diff --git a/tools/WebSocketDump.cpp b/tools/WebSocketDump.cpp index 39212b7e0..e7fe14800 100644 --- a/tools/WebSocketDump.cpp +++ b/tools/WebSocketDump.cpp @@ -161,7 +161,7 @@ private: // Bad request. std::ostringstream oss; oss << "HTTP/1.1 400\r\n" -<< "Date: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" +<< "Date: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: LOOLWSD WOPI Agent\r\n" << "Content-Length: 0\r\n" << "\r\n"; diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index 5a1dbce41..f84a73238 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -2438,7 +2438,7 @@ private: // Bad request. std::ostringstream oss; oss << "HTTP/1.1 400\r\n" -<< "Date: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" +<< "Date: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: LOOLWSD WOPI Agent\r\n" << "Content-Length: 0\r\n" << "\r\n" @@ -2740,7 +2740,7 @@ private: LOG_ERR("Download file [" << filePathAnonym << "] not found."); std::ostringstream oss; oss << "HTTP/1.1 404 Not Found\r\n" -<< "Date: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" +<< "Date: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: " << HTTP_AGENT_STRING << "\r\n" << "Content-Length: 0\r\n" << "\r\n"; diff --git a/wsd/TraceFile.hpp b/wsd/TraceFile.hpp index 5f3ac7202..82f5a75ce 100644 --- a/wsd/TraceFile.hpp +++ b/wsd/TraceFile.hpp @@ -91,7 +91,8 @@ public: const bool compress, const bool takeSnapshot, const std::vector& filters) : -_epochStart(Poco::Timestamp().epochMicroseconds()), + _epochStart(std::chrono::duration_cast(std::chrono::system_clock::now() + .time_since_epoch()).count()), _recordOutgoing(recordOugoing), _compress(compress), _takeSnapshot(takeSnapshot), @@ -258,7 +259,8 @@ private: { Util::assertIsLocked(_mutex); -const Poco::Int64 usec = Poco::Timestamp().epochMicroseconds() - _epochStart; +const Poco::Int64 usec = std::chrono::duration_cast(std::chrono + ::system_clock::now().time_since_epoch()).count() - _epochStart; if (_compress) { _deflater.write(&delim, 1); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp test/UnitHTTP.cpp
net/Socket.cpp|4 +++- test/UnitHTTP.cpp |5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) New commits: commit f4dbe43c3ec0d4c1b6353d3d506f609665df5f84 Author: Andras Timar AuthorDate: Mon Jul 8 18:20:19 2019 +0200 Commit: Andras Timar CommitDate: Mon Jul 8 21:05:46 2019 +0200 keep the project buildable with poco 1.7.8 Change-Id: I87957a0b928f92f02ce72b7e6a2a575f2e5bad8d Reviewed-on: https://gerrit.libreoffice.org/75231 Reviewed-by: Michael Meeks Tested-by: Andras Timar diff --git a/net/Socket.cpp b/net/Socket.cpp index 8205519c9..17ceb3858 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -694,7 +694,9 @@ bool StreamSocket::parseHeader(const char *clientName, if (map) map->_messageSize += contentLength; -if (request.getExpectContinue() && !_sentHTTPContinue) +const std::string& expect = request.get("Expect", ""); +bool getExpectContinue = !expect.empty() && Poco::icompare(expect, "100-continue") == 0; +if (getExpectContinue && !_sentHTTPContinue) { LOG_TRC("#" << getFD() << " got Expect: 100-continue, sending Continue"); // FIXME: should validate authentication headers early too. diff --git a/test/UnitHTTP.cpp b/test/UnitHTTP.cpp index 5439124af..70bda0733 100644 --- a/test/UnitHTTP.cpp +++ b/test/UnitHTTP.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -52,10 +53,10 @@ public: switch(i) { case 0: -request.setExpectContinue(false); +request.erase("Expect"); break; case 1: -request.setExpectContinue(true); +request.set("Expect", "100-continue"); break; default: break; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp
net/Socket.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit 8f029d972d9542bb63f2d43f92adae4550a546ee Author: Samuel Mehrbrodt AuthorDate: Fri Jun 14 16:35:21 2019 +0200 Commit: Adolfo Jayme Barrientos CommitDate: Sun Jun 16 22:35:45 2019 +0200 Fix typo Change-Id: Ib960a8b77ba293bbbe16b2ae91ed66d42364d64f Reviewed-on: https://gerrit.libreoffice.org/74052 Reviewed-by: Adolfo Jayme Barrientos Tested-by: Adolfo Jayme Barrientos diff --git a/net/Socket.cpp b/net/Socket.cpp index 34942d2f1..8205519c9 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -936,7 +936,7 @@ namespace HttpHelper bool StreamSocket::sniffSSL() const { -// Only sniffing the first bytes of a sockte. +// Only sniffing the first bytes of a socket. if (_bytesSent > 0 || _bytesRecvd != _inBuffer.size() || _bytesRecvd < 6) return false; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp
net/Socket.cpp |1 + 1 file changed, 1 insertion(+) New commits: commit 9657e4dfa3a608ef779810a2518688099af24d79 Author: Henry Castro AuthorDate: Tue Apr 2 10:26:02 2019 -0400 Commit: Henry Castro CommitDate: Tue Apr 2 10:31:08 2019 -0400 fix build: "sockaddr_un addrunix’ has incomplete type ... and cannot be defined" Change-Id: I2c136fc47c800ec3efd6268b4601100033e22724 diff --git a/net/Socket.cpp b/net/Socket.cpp index 345f566e2..5a952302d 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -17,6 +17,7 @@ #include #include #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: net/Socket.cpp
net/Socket.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit 71b9faca7cb367668c87b5baa7836b523e783bf1 Author: Samuel Mehrbrodt AuthorDate: Mon Apr 1 14:18:23 2019 +0200 Commit: Samuel Mehrbrodt CommitDate: Mon Apr 1 14:18:23 2019 +0200 Fix -Werror=maybe-uninitialized Change-Id: I076fb4b9ef80e4fbf13cdd22cff51ab1e99a2c6c diff --git a/net/Socket.cpp b/net/Socket.cpp index f4fb12c2b..345f566e2 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -43,7 +43,7 @@ std::atomic Socket::InhibitThreadChecks(false); int Socket::createSocket(Socket::Type type) { #if !MOBILEAPP -int domain; +int domain = AF_UNSPEC; switch (type) { case Type::IPv4: domain = AF_INET; break; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp
net/Socket.cpp | 11 +-- 1 file changed, 5 insertions(+), 6 deletions(-) New commits: commit 7b70aab367ccafb82a8b62892df290415b8e18af Author: Michael Meeks AuthorDate: Mon Apr 1 10:56:15 2019 +0100 Commit: Michael Meeks CommitDate: Mon Apr 1 10:56:15 2019 +0100 peercred: fixup compile issues. Change-Id: I87d956f5754e7b353776c538b7bb9dfea7f62883 diff --git a/net/Socket.cpp b/net/Socket.cpp index 441128f16..f4fb12c2b 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -570,16 +570,16 @@ std::shared_ptr LocalServerSocket::accept() // Sanity check this incoming socket struct ucred creds; socklen_t credSize = sizeof(struct ucred); -if (getsockopt(GetFD(), SOL_SOCKET, SO_PEERCRED, &creds, &credSize) < 0) +if (getsockopt(getFD(), SOL_SOCKET, SO_PEERCRED, &creds, &credSize) < 0) { -LOG_ERR("Failed to get peer creds on " << GetFD() << " " << strerror(errno)); +LOG_ERR("Failed to get peer creds on " << getFD() << " " << strerror(errno)); ::close(rc); return std::shared_ptr(nullptr); } -int uid = getuid(); -int gid = getgid(); -if (creds.uid != uid || cred.gid != gid) +uid_t uid = getuid(); +uid_t gid = getgid(); +if (creds.uid != uid || creds.gid != gid) { LOG_ERR("Peercred mis-match on domain socket - closing connection. uid: " << creds.uid << "vs." << uid << " gid: " << creds.gid << "vs." << gid); @@ -590,7 +590,6 @@ std::shared_ptr LocalServerSocket::accept() addr.append(std::to_string(creds.pid)); _socket->setClientAddress(addr); -std::shared_ptr _socket = _sockFactory->create(rc); LOG_DBG("Accepted socket is UDS - address " << addr << " and pid/gid " << creds.pid << "/" << creds.gid); return _socket; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp
net/Socket.cpp |4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) New commits: commit 3c005f952a7ff43ce6a743d89a15c209b3b50b17 Author: Andras Timar AuthorDate: Wed Oct 3 13:25:36 2018 +0200 Commit: Andras Timar CommitDate: Fri Oct 5 16:38:03 2018 +0200 fix that internal port 9981 was opened on all interfaces Change-Id: I04cd12b7fa2f0be9b08a3d325f08b36ca2ce240e Reviewed-on: https://gerrit.libreoffice.org/61296 Reviewed-by: Andras Timar Tested-by: Andras Timar diff --git a/net/Socket.cpp b/net/Socket.cpp index 91006f069..56c356221 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -379,9 +379,9 @@ bool ServerSocket::bind(Type type, int port) addrv4.sin_family = AF_INET; addrv4.sin_port = htons(port); if (type == Type::Public) -addrv4.sin_addr.s_addr = type == htonl(INADDR_ANY); +addrv4.sin_addr.s_addr = htonl(INADDR_ANY); else -addrv4.sin_addr.s_addr = type == htonl(INADDR_LOOPBACK); +addrv4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); rc = ::bind(getFD(), (const sockaddr *)&addrv4, sizeof(addrv4)); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp
net/Socket.cpp | 26 ++ net/Socket.hpp | 26 +- 2 files changed, 27 insertions(+), 25 deletions(-) New commits: commit 4841ee4f47c3d7d376105830bab6cb1b4108b387 Author: Tor Lillqvist AuthorDate: Thu Sep 13 09:31:52 2018 +0300 Commit: Tor Lillqvist CommitDate: Thu Sep 13 09:33:40 2018 +0300 Move SocketPoll::pollingThreadEntry() implementation to cpp file Makes it easier to put a breakpoint in it in Xcode... Not sure if we have any consistent convention around here anyway about which member functions should be defined inline in the class definition in the hpp file, and which ones should be in the cpp file. diff --git a/net/Socket.cpp b/net/Socket.cpp index 74a0dff16..5c133b33a 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -153,6 +153,32 @@ void SocketPoll::feed(const std::string& payload) #endif +void SocketPoll::pollingThreadEntry() +{ +try +{ +Util::setThreadName(_name); +LOG_INF("Starting polling thread [" << _name << "]."); + +_owner = std::this_thread::get_id(); +LOG_DBG("Thread affinity of " << _name << " set to " << +Log::to_string(_owner) << "."); + +// Invoke the virtual implementation. +pollingThread(); + +// Release sockets. +_pollSockets.clear(); +_newSockets.clear(); +} +catch (const std::exception& exc) +{ +LOG_ERR("Exception in polling thread [" << _name << "]: " << exc.what()); +} + +_threadFinished = true; +} + void SocketPoll::wakeupWorld() { #ifndef MOBILEAPP diff --git a/net/Socket.hpp b/net/Socket.hpp index 074734ca9..3e86055e0 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -675,31 +675,7 @@ private: /// The polling thread entry. /// Used to set the thread name and mark the thread as stopped when done. -void pollingThreadEntry() -{ -try -{ -Util::setThreadName(_name); -LOG_INF("Starting polling thread [" << _name << "]."); - -_owner = std::this_thread::get_id(); -LOG_DBG("Thread affinity of " << _name << " set to " << -Log::to_string(_owner) << "."); - -// Invoke the virtual implementation. -pollingThread(); - -// Release sockets. -_pollSockets.clear(); -_newSockets.clear(); -} -catch (const std::exception& exc) -{ -LOG_ERR("Exception in polling thread [" << _name << "]: " << exc.what()); -} - -_threadFinished = true; -} +void pollingThreadEntry(); private: /// Debug name used for logging. ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp net/WebSocketHandler.hpp
net/Socket.cpp |3 --- net/WebSocketHandler.hpp |4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) New commits: commit 195b88ac8dab2c682fb22cbc396a02a27fecb465 Author: Tor Lillqvist AuthorDate: Mon Sep 10 16:10:53 2018 +0300 Commit: Tor Lillqvist CommitDate: Mon Sep 10 16:10:53 2018 +0300 Just define these static const int members in-class diff --git a/net/Socket.cpp b/net/Socket.cpp index 38bacdde8..237674419 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -256,9 +256,6 @@ void SocketDisposition::execute() #endif -const int WebSocketHandler::InitialPingDelayMs = 25; -const int WebSocketHandler::PingFrequencyMs = 18 * 1000; - void WebSocketHandler::dumpState(std::ostream& os) { os << (_shuttingDown ? "shutd " : "alive ") diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp index 3e1faabb4..7e6befa15 100644 --- a/net/WebSocketHandler.hpp +++ b/net/WebSocketHandler.hpp @@ -44,8 +44,8 @@ protected: static const unsigned char Mask = 0x80; }; -static const int InitialPingDelayMs; -static const int PingFrequencyMs; +static const int InitialPingDelayMs = 25; +static const int PingFrequencyMs = 18 * 1000; public: /// Perform upgrade ourselves, or select a client web socket. ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp
net/Socket.cpp | 15 ++- 1 file changed, 14 insertions(+), 1 deletion(-) New commits: commit 997503a8d17178bb6eaab50e796f1be1dc84bbab Author: Tor Lillqvist AuthorDate: Tue Sep 4 12:02:20 2018 +0300 Commit: Tor Lillqvist CommitDate: Tue Sep 4 12:24:48 2018 +0300 Make this file compile for iOS Again, note that I don't claim this file (or the code-base as such) would make much sense for iOS as such at the moment. I just want it to compile for now. Baby steps etc. (And there is no public Xcode project to compile it even partially.) Change-Id: I1321d61e9e911c7d97c7309b78aab46d9cecec29 diff --git a/net/Socket.cpp b/net/Socket.cpp index 2fc2a1425..98bb6b996 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -24,14 +24,18 @@ #include #include "Socket.hpp" +#ifdef __linux #include "ServerSocket.hpp" #include "SslSocket.hpp" +#endif #include "WebSocketHandler.hpp" int SocketPoll::DefaultPollTimeoutMs = 5000; std::atomic SocketPoll::InhibitThreadChecks(false); std::atomic Socket::InhibitThreadChecks(false); +#ifdef __linux + int Socket::createSocket(Socket::Type type) { int domain = type == Type::IPv4 ? AF_INET : AF_INET6; @@ -216,12 +220,15 @@ void SocketPoll::insertNewWebSocketSync(const Poco::URI &uri, const std::shared_ LOG_ERR("Failed to lookup client websocket host '" << uri.getHost() << "' skipping"); } +#endif + +#ifdef __linux + void ServerSocket::dumpState(std::ostream& os) { os << "\t" << getFD() << "\t\n"; } - void SocketDisposition::execute() { // We should have hard ownership of this socket. @@ -238,6 +245,8 @@ void SocketDisposition::execute() const int WebSocketHandler::InitialPingDelayMs = 25; const int WebSocketHandler::PingFrequencyMs = 18 * 1000; +#endif + void WebSocketHandler::dumpState(std::ostream& os) { os << (_shuttingDown ? "shutd " : "alive ") @@ -272,6 +281,8 @@ void StreamSocket::send(Poco::Net::HTTPResponse& response) send(oss.str()); } +#ifdef __linux + void SocketPoll::dumpState(std::ostream& os) { // FIXME: NOT thread-safe! _pollSockets is modified from the polling thread! @@ -333,6 +344,8 @@ bool ServerSocket::bind(Type type, int port) return rc == 0; } +#endif + bool StreamSocket::parseHeader(const char *clientName, Poco::MemoryInputStream &message, Poco::Net::HTTPRequest &request, ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp wsd/Admin.cpp
net/Socket.cpp |3 +-- wsd/Admin.cpp |1 + 2 files changed, 2 insertions(+), 2 deletions(-) New commits: commit a5215217aad85b5f954af1b43f1a23c35d25 Author: Michael Meeks Date: Fri Jun 15 17:36:13 2018 +0100 Fix logging a little. Change-Id: I858ffb40e071eae3907eeff9c2d6291fd805dc02 diff --git a/net/Socket.cpp b/net/Socket.cpp index dddfe4fc0..2fc2a1425 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -161,7 +161,6 @@ void SocketPoll::insertNewWebSocketSync(const Poco::URI &uri, const std::shared_ { int fd = socket(ai->ai_addr->sa_family, SOCK_STREAM | SOCK_NONBLOCK, 0); int res = connect(fd, ai->ai_addr, ai->ai_addrlen); -// FIXME: SSL sockets presumably need some setup, checking etc. and ... =) if (fd < 0 || (res < 0 && errno != EINPROGRESS)) { LOG_ERR("Failed to connect to " << uri.getHost()); @@ -259,7 +258,7 @@ void StreamSocket::dumpState(std::ostream& os) if (_inBuffer.size() > 0) Util::dumpHex(os, "\t\tinBuffer:\n", "\t\t", _inBuffer); if (_outBuffer.size() > 0) -Util::dumpHex(os, "\t\toutBuffer:\n", "\t\t", _inBuffer); +Util::dumpHex(os, "\t\toutBuffer:\n", "\t\t", _outBuffer); } void StreamSocket::send(Poco::Net::HTTPResponse& response) diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp index 723bb22f9..f28a741ec 100644 --- a/wsd/Admin.cpp +++ b/wsd/Admin.cpp @@ -675,6 +675,7 @@ public: void Admin::connectToMonitorSync(const std::string &uri) { +LOG_TRC("Add monitor " << uri); insertNewWebSocketSync(Poco::URI(uri), std::make_shared(this, uri)); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp wsd/FileServer.cpp
net/Socket.cpp |4 wsd/FileServer.cpp | 21 ++--- 2 files changed, 22 insertions(+), 3 deletions(-) New commits: commit d66e8d13b7fc0fc638122fae44cf1591eca1aaca Author: Andras Timar Date: Fri May 18 09:48:07 2018 +0200 serve files with old gith hash in their path, that comes from cached discovery.xml moreover: * noCache is always true in debug mode * when noCache is true we return an explicit "Cache-Control: no-cache" line Change-Id: I157a410df0a90f9ab151b899e44566b95cbd9929 Reviewed-on: https://gerrit.libreoffice.org/54517 Reviewed-by: Michael Meeks Tested-by: Michael Meeks diff --git a/net/Socket.cpp b/net/Socket.cpp index 9a07986c9..4faa4f753 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -374,6 +374,10 @@ namespace HttpHelper response.set("Cache-Control", "max-age=11059200"); response.set("ETag", "\"" LOOLWSD_VERSION_HASH "\""); } +else +{ +response.set("Cache-Control", "no-cache"); +} response.setContentType(mediaType); response.add("X-Content-Type-Options", "nosniff"); diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp index f8e62f4a5..ab95c6a45 100644 --- a/wsd/FileServer.cpp +++ b/wsd/FileServer.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -264,11 +265,21 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request, Poco::M try { bool noCache = false; +#if ENABLE_DEBUG +noCache = true; +#endif Poco::Net::HTTPResponse response; Poco::URI requestUri(request.getURI()); LOG_TRC("Fileserver request: " << requestUri.toString()); requestUri.normalize(); // avoid .'s and ..'s +std::string path(requestUri.getPath()); +if (path.find("loleaflet/" LOOLWSD_VERSION_HASH "/") == std::string::npos) +{ +LOG_WRN("client - server version mismatch, disabling browser cache."); +noCache = true; +} + std::vector requestSegments; requestUri.getPathSegments(requestSegments); const std::string relPath = getRequestPathname(request); @@ -533,9 +544,13 @@ std::string FileServerRequestHandler::getRequestPathname(const HTTPRequest& requ requestUri.normalize(); std::string path(requestUri.getPath()); - -// Convert version back to a real file name. -Poco::replaceInPlace(path, std::string("/loleaflet/" LOOLWSD_VERSION_HASH "/"), std::string("/loleaflet/dist/")); +Poco::RegularExpression gitHashRe("/([0-9a-f]+)/"); +std::string gitHash; +if (gitHashRe.extract(path, gitHash)) +{ +// Convert version back to a real file name. +Poco::replaceInPlace(path, std::string("/loleaflet" + gitHash), std::string("/loleaflet/dist/")); +} return path; } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp wsd/LOOLWSD.cpp
net/Socket.cpp | 66 + net/Socket.hpp | 19 +- wsd/LOOLWSD.cpp | 98 +++- 3 files changed, 96 insertions(+), 87 deletions(-) New commits: commit b5a1af763cf0e2295286f3e27c767ec51551cf2f Author: Michael Meeks Date: Tue May 1 14:57:17 2018 +0100 Share HTTP header parsing inside the StreamSocket. Change-Id: Id98e895a939d931ac10b7cd7403da4cbe822ee82 diff --git a/net/Socket.cpp b/net/Socket.cpp index 1bf847cba..9a07986c9 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include #include @@ -241,6 +243,70 @@ bool ServerSocket::bind(Type type, int port) return rc == 0; } +bool StreamSocket::parseHeader(const char *clientName, + Poco::MemoryInputStream &message, + Poco::Net::HTTPRequest &request, + size_t *requestSize) +{ +LOG_TRC("#" << getFD() << " handling incoming " << _inBuffer.size() << " bytes."); + +assert(!requestSize || *requestSize == 0); + +// Find the end of the header, if any. +static const std::string marker("\r\n\r\n"); +auto itBody = std::search(_inBuffer.begin(), _inBuffer.end(), + marker.begin(), marker.end()); +if (itBody == _inBuffer.end()) +{ +LOG_TRC("#" << getFD() << " doesn't have enough data yet."); +return false; +} + +// Skip the marker. +itBody += marker.size(); +if (requestSize) +*requestSize = static_cast(itBody - _inBuffer.begin()); + +try +{ +request.read(message); + +Log::StreamLogger logger = Log::info(); +if (logger.enabled()) +{ +logger << "#" << getFD() << ": " << clientName << " HTTP Request: " + << request.getMethod() << ' ' + << request.getURI() << ' ' + << request.getVersion(); + +for (const auto& it : request) +{ +logger << " / " << it.first << ": " << it.second; +} + +LOG_END(logger); +} + +const std::streamsize contentLength = request.getContentLength(); +const auto offset = itBody - _inBuffer.begin(); +const std::streamsize available = _inBuffer.size() - offset; + +if (contentLength != Poco::Net::HTTPMessage::UNKNOWN_CONTENT_LENGTH && available < contentLength) +{ +LOG_DBG("Not enough content yet: ContentLength: " << contentLength << ", available: " << available); +return false; +} +} +catch (const std::exception& exc) +{ +// Probably don't have enough data just yet. +// TODO: timeout if we never get enough. +return false; +} + +return true; +} + namespace HttpHelper { diff --git a/net/Socket.hpp b/net/Socket.hpp index d3d48128f..84632a4f2 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -40,8 +40,10 @@ namespace Poco { +class MemoryInputStream; namespace Net { +class HTTPRequest; class HTTPResponse; } } @@ -833,6 +835,20 @@ public: return socket; } +/// Remove the first @count bytes from input buffer +void eraseFirstInputBytes(size_t count) +{ +_inBuffer.erase(_inBuffer.begin(), _inBuffer.begin() + count); +} + +/// Detects if we have an HTTP header in the provided message and +/// populates a request for that. +bool parseHeader(const char *clientLoggingName, + Poco::MemoryInputStream &message, + Poco::Net::HTTPRequest &request, + size_t *requestSize = nullptr); + +/// Get input/output statistics on this stream void getIOStats(uint64_t &sent, uint64_t &recv) { sent = _bytesSent; @@ -1021,8 +1037,7 @@ namespace HttpHelper void sendFile(const std::shared_ptr& socket, const std::string& path, const std::string& mediaType, Poco::Net::HTTPResponse& response, bool noCache = false, bool deflate = false, const bool headerOnly = false); -}; - +} #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index 9d39ba2ce..668916500 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -1608,42 +1608,16 @@ private: } std::shared_ptr socket = _socket.lock(); -std::vector& in = socket->_inBuffer; -// Find the end of the header, if any. -static const std::string marker("\r\n\r\n"); -auto itBody = std::search(in.begin(), in.end(), - marker.begin(), marker.end()); -if (itBody == in.end()) -{ -LOG_TRC("#" << socket->getFD() << " doesn't have enough data yet."); -return; -} - -// Skip the m
[Libreoffice-commits] online.git: net/Socket.cpp net/WebSocketHandler.hpp wsd/Admin.cpp wsd/Admin.hpp
net/Socket.cpp |3 +++ net/WebSocketHandler.hpp |4 ++-- wsd/Admin.cpp|3 +++ wsd/Admin.hpp|4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) New commits: commit e5c7c62713b399526f7fafd85c1f02c9a2a5f45f Author: Miklos Vajna Date: Mon Feb 26 16:30:30 2018 +0100 'static const int' needs an explicit definition in C++11 core.git equivalent situation is e.g. SwXMLTableContext::MAX_WIDTH. Change-Id: Id6f4201e875a7453ab2363161ea9560ae6e40384 diff --git a/net/Socket.cpp b/net/Socket.cpp index 31ad77c6..1bf847cb 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -143,6 +143,9 @@ void SocketDisposition::execute() _socketMove = nullptr; } +const int WebSocketHandler::InitialPingDelayMs = 25; +const int WebSocketHandler::PingFrequencyMs = 18 * 1000; + void WebSocketHandler::dumpState(std::ostream& os) { os << (_shuttingDown ? "shutd " : "alive ") diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp index d981ab4d..b363364f 100644 --- a/net/WebSocketHandler.hpp +++ b/net/WebSocketHandler.hpp @@ -40,8 +40,8 @@ protected: static const unsigned char Mask = 0x80; }; -static const int InitialPingDelayMs = 25; -static const int PingFrequencyMs = 18 * 1000; +static const int InitialPingDelayMs; +static const int PingFrequencyMs; public: WebSocketHandler() : diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp index 8add6956..41407d07 100644 --- a/wsd/Admin.cpp +++ b/wsd/Admin.cpp @@ -44,6 +44,9 @@ using Poco::Net::HTTPResponse; using Poco::StringTokenizer; using Poco::Util::Application; +const int Admin::MinStatsIntervalMs = 50; +const int Admin::DefStatsIntervalMs = 2500; + /// Process incoming websocket messages void AdminSocketHandler::handleMessage(bool /* fin */, WSOpCode /* code */, std::vector &payload) diff --git a/wsd/Admin.hpp b/wsd/Admin.hpp index e3386952..57197940 100644 --- a/wsd/Admin.hpp +++ b/wsd/Admin.hpp @@ -153,8 +153,8 @@ private: DocProcSettings _defDocProcSettings; // Don't update any more frequently than this since it's excessive. -static const int MinStatsIntervalMs = 50; -static const int DefStatsIntervalMs = 2500; +static const int MinStatsIntervalMs; +static const int DefStatsIntervalMs; }; #endif ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp net/WebSocketHandler.hpp
net/Socket.cpp |2 - net/Socket.hpp | 25 +++ net/WebSocketHandler.hpp | 59 +++ 3 files changed, 46 insertions(+), 40 deletions(-) New commits: commit 71f4597059f2606ad8394161b6eda1c51c88c8d3 Author: Ashod Nakashian Date: Sun Feb 11 19:14:21 2018 -0500 wsd: WebSocket state is a property of the socket This resolves the erroneous warnings of pinging on a non-upgraded (i.e. HTTP) socket. This was due to the fact that we moved the socket from one SocketHandlerInterface to a WebSocketHandler after upgrading and since the WSState was a property of the handler, the WebSocketHandler didn't know that the socket had already been upgraded. Also other cosmetics and cleanups. Change-Id: I1a88edef750117ed551d23245e49380371561422 Reviewed-on: https://gerrit.libreoffice.org/49911 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/net/Socket.cpp b/net/Socket.cpp index d0a791ec..31ad77c6 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -146,7 +146,7 @@ void SocketDisposition::execute() void WebSocketHandler::dumpState(std::ostream& os) { os << (_shuttingDown ? "shutd " : "alive ") - << std::setw(5) << 1.0*_pingTimeUs/1000 << "ms "; + << std::setw(5) << _pingTimeUs/1000. << "ms "; if (_wsPayload.size() > 0) Util::dumpHex(os, "\t\tws queued payload:\n", "\t\t", _wsPayload); os << "\n"; diff --git a/net/Socket.hpp b/net/Socket.hpp index bec3744d..7c856335 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -283,7 +283,7 @@ protected: setNoDelay(); _sendBufferSize = DefaultSendBufferSize; _owner = std::this_thread::get_id(); -LOG_DBG("#" << _fd << " Thread affinity set to " << _owner << "."); +LOG_DBG("#" << _fd << " Thread affinity set to " << Log::to_string(_owner) << "."); #if ENABLE_DEBUG if (std::getenv("LOOL_ZERO_BUFFER_SIZE")) @@ -700,10 +700,11 @@ public: StreamSocket(const int fd, std::shared_ptr socketHandler) : Socket(fd), _socketHandler(std::move(socketHandler)), -_closed(false), -_shutdownSignalled(false), _bytesSent(0), -_bytesRecvd(0) +_bytesRecvd(0), +_wsState(WSState::HTTP), +_closed(false), +_shutdownSignalled(false) { LOG_DBG("StreamSocket ctor #" << fd); @@ -730,6 +731,8 @@ public: } bool isClosed() const { return _closed; } +bool isWebSocket() const { return _wsState == WSState::WS; } +void setWebSocket() { _wsState = WSState::WS; } /// Just trigger the async shutdown. virtual void shutdown() override @@ -968,18 +971,20 @@ protected: /// Client handling the actual data. std::shared_ptr _socketHandler; +std::vector _inBuffer; +std::vector _outBuffer; + +uint64_t _bytesSent; +uint64_t _bytesRecvd; + +enum class WSState { HTTP, WS } _wsState; + /// True if we are already closed. bool _closed; /// True when shutdown was requested via shutdown(). bool _shutdownSignalled; -std::vector< char > _inBuffer; -std::vector< char > _outBuffer; - -uint64_t _bytesSent; -uint64_t _bytesRecvd; - // To be able to access _inBuffer and _outBuffer. // TODO we probably need accessors to the _inBuffer & _outBuffer // instead of this many friends... diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp index dd869ebb..d981ab4d 100644 --- a/net/WebSocketHandler.hpp +++ b/net/WebSocketHandler.hpp @@ -25,30 +25,29 @@ class WebSocketHandler : public SocketHandlerInterface { protected: -// The socket that owns us (we can't own it). +/// The socket that owns us (we can't own it). std::weak_ptr _socket; -const int InitialPingDelayMs = 25; -const int PingFrequencyMs = 18 * 1000; -std::chrono::steady_clock::time_point _pingSent; +std::chrono::steady_clock::time_point _lastPingSentTime; int _pingTimeUs; std::vector _wsPayload; -bool _shuttingDown; -enum class WSState { HTTP, WS } _wsState; +std::atomic _shuttingDown; -enum class WSFrameMask : unsigned char +struct WSFrameMask { -Fin = 0x80, -Mask = 0x80 +static const unsigned char Fin = 0x80; +static const unsigned char Mask = 0x80; }; +static const int InitialPingDelayMs = 25; +static const int PingFrequencyMs = 18 * 1000; + public: WebSocketHandler() : -_pingSent(std::chrono::steady_clock::now()), +_lastPingSentTime(std::chrono::steady_clock::now()), _pingTimeUs(0), -_shuttingDown(false), -_wsState(WSState::HTTP) +_shuttingDown(false) { } @@ -56,12 +55,11 @@ public: WebSocketHandler(const std::weak_ptr& socket, const Poco::Net::HTTPRequest& request) : _socket(s
[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp
net/Socket.cpp |4 +++- net/Socket.hpp | 16 +++- 2 files changed, 18 insertions(+), 2 deletions(-) New commits: commit c224413a9d013a4253ed66fccb8ee40dc01be8f8 Author: Michael Meeks Date: Fri May 26 15:50:08 2017 +0100 Track bytes recv'd and sent on StreamSockets. Dump on USR1 as part of our state. Change-Id: I4c6b87c19bca768402c9b0b8e26f16336e007749 diff --git a/net/Socket.cpp b/net/Socket.cpp index 06afce83..13424cd3 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -181,6 +181,7 @@ void WebSocketHandler::dumpState(std::ostream& os) << std::setw(5) << 1.0*_pingTimeUs/1000 << "ms "; if (_wsPayload.size() > 0) dump_hex(os, "\t\tws queued payload:\n", "\t\t", _wsPayload); +os << "\n"; } void StreamSocket::dumpState(std::ostream& os) @@ -188,7 +189,8 @@ void StreamSocket::dumpState(std::ostream& os) int timeoutMaxMs = SocketPoll::DefaultPollTimeoutMs; int events = getPollEvents(std::chrono::steady_clock::now(), timeoutMaxMs); os << "\t" << getFD() << "\t" << events << "\t" - << _inBuffer.size() << "\t" << _outBuffer.size() << "\t"; + << _inBuffer.size() << "\t" << _outBuffer.size() << "\t" + << " r: " << _bytesRecvd << "\t w: " << _bytesSent << "\t"; _socketHandler->dumpState(os); if (_inBuffer.size() > 0) dump_hex(os, "\t\tinBuffer:\n", "\t\t", _inBuffer); diff --git a/net/Socket.hpp b/net/Socket.hpp index 88e24f05..a7cc426d 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "common/Common.hpp" #include "common/Log.hpp" @@ -691,7 +692,9 @@ public: Socket(fd), _socketHandler(std::move(socketHandler)), _closed(false), -_shutdownSignalled(false) +_shutdownSignalled(false), +_bytesSent(0), +_bytesRecvd(0) { LOG_DBG("StreamSocket ctor #" << fd); @@ -785,6 +788,7 @@ public: if (len > 0) { assert (len <= ssize_t(sizeof(buf))); +_bytesRecvd += len; _inBuffer.insert(_inBuffer.end(), &buf[0], &buf[len]); } // else poll will handle errors. @@ -915,6 +919,7 @@ protected: if (len > 0) { +_bytesSent += len; _outBuffer.erase(_outBuffer.begin(), _outBuffer.begin() + len); } else @@ -942,6 +947,12 @@ protected: void dumpState(std::ostream& os) override; +void getStats(uint64_t &sent, uint64_t &recv) +{ +sent = _bytesSent; +recv = _bytesRecvd; +} + protected: /// Client handling the actual data. std::shared_ptr _socketHandler; @@ -955,6 +966,9 @@ protected: std::vector< char > _inBuffer; std::vector< char > _outBuffer; +std::atomic _bytesSent; +std::atomic _bytesRecvd; + // To be able to access _inBuffer and _outBuffer. // TODO we probably need accessors to the _inBuffer & _outBuffer // instead of this many friends... ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp wsd/LOOLWSD.cpp
net/Socket.cpp |1 + net/Socket.hpp |3 +++ wsd/LOOLWSD.cpp |3 +++ 3 files changed, 7 insertions(+) New commits: commit 7cff4fb08a2dba769a992300d24c0d5c3192b0a9 Author: Ashod Nakashian Date: Sun May 14 21:42:10 2017 -0400 wsd: fix server shutdown Thread-affinity checks must be inhibited not just on Socket, but on the SocketPoll as well, before destroying DocumentBroker instances. Also, properly initialize the inhibit statics. Change-Id: I2ced1554d477f0c3faf09bda74034cbae99e4ce1 Reviewed-on: https://gerrit.libreoffice.org/37608 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/net/Socket.cpp b/net/Socket.cpp index 97018c86..06afce83 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -25,6 +25,7 @@ #include "WebSocketHandler.hpp" int SocketPoll::DefaultPollTimeoutMs = 5000; +std::atomic SocketPoll::InhibitThreadChecks(false); std::atomic Socket::InhibitThreadChecks(false); // help with initialization order diff --git a/net/Socket.hpp b/net/Socket.hpp index 0468eb9c..7c7b55ab 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -317,6 +317,7 @@ public: /// Default poll time - useful to increase for debugging. static int DefaultPollTimeoutMs; +static std::atomic InhibitThreadChecks; /// Stop the polling thread. void stop() @@ -368,6 +369,8 @@ public: /// Asserts in the debug builds, otherwise just logs. void assertCorrectThread() const { +if (InhibitThreadChecks) +return; // 0 owner means detached and can be invoked by any thread. const bool sameThread = (!isAlive() || _owner == std::thread::id(0) || std::this_thread::get_id() == _owner); if (!sameThread) diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index 8c116654..8598d763 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -2221,6 +2221,7 @@ public: { // FIXME: add some stop-world magic before doing the dump(?) Socket::InhibitThreadChecks = true; +SocketPoll::InhibitThreadChecks = true; os << "LOOLWSDServer:\n" << " Ports: server " << ClientPortNumber @@ -2254,6 +2255,7 @@ public: i.second->dumpState(os); Socket::InhibitThreadChecks = false; +SocketPoll::InhibitThreadChecks = false; } private: @@ -2532,6 +2534,7 @@ int LOOLWSD::innerMain() // Disable thread checking - we'll now cleanup lots of things if we can Socket::InhibitThreadChecks = true; +SocketPoll::InhibitThreadChecks = true; DocBrokers.clear(); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp wsd/LOOLWSD.cpp
net/Socket.cpp |4 wsd/LOOLWSD.cpp |1 - 2 files changed, 4 insertions(+), 1 deletion(-) New commits: commit 495d6da532d7ec9f05713ed81bb6e12fd894c41f Author: Michael Meeks Date: Mon May 8 15:23:49 2017 +0100 Reset ownership before executing the socket move. Change-Id: I98532e59ef9c78a6cc1eb25a5a8535c4e2d9b15d diff --git a/net/Socket.cpp b/net/Socket.cpp index 5faeced7..652c7568 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -128,7 +128,11 @@ void SocketDisposition::execute() // We should have hard ownership of this socket. assert(_socket->getThreadOwner() == std::this_thread::get_id()); if (_socketMove) +{ +// Drop pretentions of ownership before _socketMove. +_socket->setThreadOwner(std::thread::id(0)); _socketMove(_socket); +} _socketMove = nullptr; } diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index a6771996..ce983651 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -1485,7 +1485,6 @@ private: // until we attach the childProcess (with this socket) // to a docBroker, which will do the polling. disposition.setMove([child](const std::shared_ptr &){ -// Drop pretentions of ownership before adding to the list. addNewChild(child); }); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp wsd/Admin.cpp wsd/ClientSession.cpp wsd/FileServer.cpp wsd/LOOLWSD.cpp
net/Socket.cpp| 12 net/Socket.hpp| 29 +++-- wsd/Admin.cpp |1 + wsd/ClientSession.cpp |4 +++- wsd/FileServer.cpp|1 + wsd/LOOLWSD.cpp |3 ++- 6 files changed, 30 insertions(+), 20 deletions(-) New commits: commit 8b3a2ed9d7fd3df4b6830a011222f0c387bb2364 Author: Ashod Nakashian Date: Sun Apr 23 21:25:09 2017 -0400 wsd: reduce included headers Change-Id: I3107b18b2edae34a76e9f56a5cbd24836b1b57c0 Reviewed-on: https://gerrit.libreoffice.org/36872 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/net/Socket.cpp b/net/Socket.cpp index c8780327..ad912880 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "SigUtil.hpp" #include "Socket.hpp" @@ -173,6 +174,17 @@ void StreamSocket::dumpState(std::ostream& os) dump_hex("\t\toutBuffer:\n", "\t\t", _inBuffer); } +void StreamSocket::send(Poco::Net::HTTPResponse& response) +{ +response.set("User-Agent", HTTP_AGENT_STRING); +response.set("Date", Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT)); + +std::ostringstream oss; +response.write(oss); + +send(oss.str()); +} + void SocketPoll::dumpState(std::ostream& os) { // FIXME: NOT thread-safe! _pollSockets is modified from the polling thread! diff --git a/net/Socket.hpp b/net/Socket.hpp index 6f1397f0..014f023d 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -31,13 +31,19 @@ #include #include -#include - #include "Common.hpp" #include "Log.hpp" #include "Util.hpp" #include "SigUtil.hpp" +namespace Poco +{ +namespace Net +{ +class HTTPResponse; +} +} + /// A non-blocking, streaming socket. class Socket { @@ -705,13 +711,8 @@ public: } /// Sends HTTP response. -void send(Poco::Net::HTTPResponse& response) -{ -response.set("User-Agent", HTTP_AGENT_STRING); -std::ostringstream oss; -response.write(oss); -send(oss.str()); -} +/// Adds Date and User-Agent. +void send(Poco::Net::HTTPResponse& response); /// Reads data by invoking readData() and buffering. /// Return false iff the socket is closed. @@ -914,18 +915,10 @@ protected: namespace HttpHelper { +/// Sends file as HTTP response. void sendFile(const std::shared_ptr& socket, const std::string& path, const std::string& mediaType, Poco::Net::HTTPResponse& response, bool noCache = false, bool deflate = false, const bool headerOnly = false); - -inline void sendFile(const std::shared_ptr& socket, const std::string& path, - const std::string& mediaType, bool noCache = false, bool deflate = false, - const bool headerOnly = false) - -{ -Poco::Net::HTTPResponse response; -sendFile(socket, path, mediaType, response, noCache, deflate, headerOnly); -} }; #endif diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp index f4bbe1de..700b860b 100644 --- a/wsd/Admin.cpp +++ b/wsd/Admin.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include "Admin.hpp" diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 11db33af..0bec1538 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -13,6 +13,7 @@ #include +#include #include #include "Common.hpp" @@ -599,7 +600,8 @@ bool ClientSession::handleKitToClientMessage(const char* buffer, const int lengt std::string encodedFilePath; Poco::URI::encode(resultURL.getPath(), "", encodedFilePath); LOG_TRC("Sending file: " << encodedFilePath); -HttpHelper::sendFile(_saveAsSocket, encodedFilePath, mimeType); +Poco::Net::HTTPResponse response; +HttpHelper::sendFile(_saveAsSocket, encodedFilePath, mimeType, response); } // Conversion is done, cleanup this fake session. diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp index 43216996..b49d2c34 100644 --- a/wsd/FileServer.cpp +++ b/wsd/FileServer.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index c604206e..4e136d4e 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -1747,7 +1747,8 @@ private: } auto socket = _socket.lock(); -HttpHelper::sendFile(socket, faviconPath, mimeType); +Poco::Net::HTTPResponse response; +HttpHelper::sendFile(socket, faviconPath, mimeType, response); socket->shutdown(); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp
net/Socket.cpp | 112 ++--- net/Socket.hpp |9 +++- 2 files changed, 66 insertions(+), 55 deletions(-) New commits: commit 988ddaf7be50c556618685a52f0c0f724947274d Author: Ashod Nakashian Date: Sat Apr 22 21:10:54 2017 -0400 wsd: cleanup sendFile to allow header-only response HTTP HEAD verb requires sending back NO content. Currently we don't support HEAD and that harms the browser from using its cache where possible. Change-Id: I3c67dc106df95312c73f6ae786b7b1657a4167fb Reviewed-on: https://gerrit.libreoffice.org/36871 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/net/Socket.cpp b/net/Socket.cpp index b38dd3fe..c8780327 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -187,19 +187,64 @@ void SocketPoll::dumpState(std::ostream& os) namespace HttpHelper { -void sendFile(const std::shared_ptr& socket, const std::string& path, const std::string& mediaType, - Poco::Net::HTTPResponse& response, bool noCache, bool deflate) +void sendUncompressedFileContent(const std::shared_ptr& socket, + const std::string& path, + const int bufferSize) +{ +std::ifstream file(path, std::ios::binary); +std::unique_ptr buf(new char[bufferSize]); +do +{ +file.read(&buf[0], bufferSize); +const int size = file.gcount(); +if (size > 0) +socket->send(&buf[0], size, true); +else +break; +} +while (file); +} + +void sendDeflatedFileContent(const std::shared_ptr& socket, + const std::string& path, + const int fileSize) +{ +// FIXME: Should compress once ahead of time +// compression of bundle.js takes significant time: +// 200's ms for level 9 (468k), 72ms for level 1(587k) +// down from 2Mb. +if (fileSize > 0) +{ +std::ifstream file(path, std::ios::binary); +std::unique_ptr buf(new char[fileSize]); +file.read(&buf[0], fileSize); + +static const unsigned int Level = 1; +const long unsigned int size = file.gcount(); +long unsigned int compSize = compressBound(size); +std::unique_ptr cbuf(new char[compSize]); +compress2((Bytef *)&cbuf[0], &compSize, (Bytef *)&buf[0], size, Level); + +if (size > 0) +socket->send(&cbuf[0], compSize, true); +} +} + +void sendFile(const std::shared_ptr& socket, + const std::string& path, + const std::string& mediaType, + Poco::Net::HTTPResponse& response, + const bool noCache, + const bool deflate, + const bool headerOnly) { struct stat st; if (stat(path.c_str(), &st) != 0) { LOG_WRN("#" << socket->getFD() << ": Failed to stat [" << path << "]. File will not be sent."); throw Poco::FileNotFoundException("Failed to stat [" + path + "]. File will not be sent."); -return; } -response.set("User-Agent", HTTP_AGENT_STRING); -response.set("Date", Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT)); if (!noCache) { // 60 * 60 * 24 * 128 (days) = 11059200 @@ -223,59 +268,22 @@ namespace HttpHelper if (!deflate || true) { response.setContentLength(st.st_size); -std::ostringstream oss; -response.write(oss); -const std::string header = oss.str(); -LOG_TRC("#" << socket->getFD() << ": Sending file [" << path << "]: " << header); -socket->send(header); +LOG_TRC("#" << socket->getFD() << ": Sending " << +(headerOnly ? "header for " : "") << " file [" << path << "]."); +socket->send(response); -std::ifstream file(path, std::ios::binary); -bool flush = true; -std::unique_ptr buf(new char[bufferSize]); -do -{ -file.read(&buf[0], bufferSize); -const int size = file.gcount(); -if (size > 0) -socket->send(&buf[0], size, flush); -else -break; -flush = false; -} -while (file); +if (!headerOnly) +sendUncompressedFileContent(socket, path, bufferSize); } else { response.set("Content-Encoding", "deflate"); -std::ostringstream oss; -response.write(oss); -const std::string header = oss.str(); -L
[Libreoffice-commits] online.git: net/Socket.cpp
net/Socket.cpp |4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) New commits: commit 2124ec30c61917f934b1af77e69fbc2e457eb854 Author: Pranav Kant Date: Thu Apr 6 20:37:40 2017 +0530 net: Disable deflate unconditionally First reason is that compression is very slow, and we re-compress the files again and again. Another reason is that IE/Edge doesn't work well with deflate turned on. Related: https://connect.microsoft.com/IE/feedbackdetail/view/950689 The documents are not loaded at all with current code snapshot modulo this patch. Change-Id: I1fdd85856f448dc4ce02e1ab79e9c7474c3bb7f3 diff --git a/net/Socket.cpp b/net/Socket.cpp index 5850e9c4..e4d2df4e 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -215,7 +215,9 @@ namespace HttpHelper } // Disable deflate for now - until we can cache deflated data. -if (!deflate && true) +// FIXME: IE/Edge doesn't work well with deflate, so check with +// IE/Edge before enabling the deflate again +if (!deflate || true) { response.setContentLength(st.st_size); std::ostringstream oss; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp
net/Socket.cpp |1 + net/Socket.hpp |9 ++--- wsd/DocumentBroker.cpp |1 + wsd/LOOLWSD.cpp|6 +++--- 4 files changed, 11 insertions(+), 6 deletions(-) New commits: commit 3d03a0fb5d9a4dcb69202816f142943578c58f8a Author: Ashod Nakashian Date: Thu Apr 6 02:56:21 2017 -0400 wsd: accomodate accept_poll shutdown When shutting down accept_poll from main, we can't remove sockets or cleanup. That work needs to be done fro within accept_poll's thread. This is different from when DocBroker's poll needs to cleanup its own sockets before it exists. So we split the stop and removeSockets so they can each be called in the proper way. For accept_poll and others that joinThread we queue a callback to cleanup before stopping. Change-Id: If780d6a97ac0fc6da6897f895d5b4dda443f9e73 Reviewed-on: https://gerrit.libreoffice.org/36186 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/net/Socket.cpp b/net/Socket.cpp index 21ab00f2..5850e9c4 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -96,6 +96,7 @@ void SocketPoll::startThread() void SocketPoll::joinThread() { +addCallback([this](){ removeSockets(); }); stop(); if (_threadStarted && _thread.joinable()) { diff --git a/net/Socket.hpp b/net/Socket.hpp index cd1ea6cc..bb08dca1 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -264,9 +264,14 @@ public: /// Stop the polling thread. void stop() { -LOG_DBG("Stopping " << _name << " and removing all sockets."); +LOG_DBG("Stopping " << _name << "."); _stop = true; +wakeup(); +} +void removeSockets() +{ +LOG_DBG("Removing all sockets from " << _name << "."); assert(socket); assertCorrectThread(); @@ -280,8 +285,6 @@ public: _pollSockets.pop_back(); } - -wakeup(); } bool isAlive() const { return _threadStarted && !_threadFinished; } diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 8dd3fa42..1b6f5d45 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -266,6 +266,7 @@ void DocumentBroker::pollThread() // Stop to mark it done and cleanup. _poll->stop(); +_poll->removeSockets(); // Async cleanup. LOOLWSD::doHousekeeping(); diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index ac721294..e5d4cb68 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -2474,9 +2474,6 @@ int LOOLWSD::innerMain() LOG_INF("Stopping server socket listening. ShutdownFlag: " << ShutdownRequestFlag << ", TerminationFlag: " << TerminationFlag); -// Disable thread checking - we'll now cleanup lots of things if we can -Socket::InhibitThreadChecks = true; - // Wait until documents are saved and sessions closed. srv.stop(); @@ -2485,6 +2482,9 @@ int LOOLWSD::innerMain() for (auto& docBrokerIt : DocBrokers) docBrokerIt.second->joinThread(); +// Disable thread checking - we'll now cleanup lots of things if we can +Socket::InhibitThreadChecks = true; + DocBrokers.clear(); #ifndef KIT_IN_PROCESS ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp
net/Socket.cpp | 28 1 file changed, 16 insertions(+), 12 deletions(-) New commits: commit 61d912cd6fd3112a35c584772b279afe2dbdd3f7 Author: Michael Meeks Date: Tue Apr 4 13:17:23 2017 +0100 Use heap buffers for file transfer and disable deflate for now. diff --git a/net/Socket.cpp b/net/Socket.cpp index 1f6d64d0..55bd4fb5 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -212,9 +212,8 @@ namespace HttpHelper bufferSize = socket->getSendBufferSize(); } -// Deflate is done over the full file, which can be too large. -// Skip deflating (ironically) if the file is too large. -if (!deflate || st.st_size > Socket::MaximumSendBufferSize * 10) +// Disable deflate for now - until we can cache deflated data. +if (!deflate && true) { response.setContentLength(st.st_size); std::ostringstream oss; @@ -225,13 +224,13 @@ namespace HttpHelper std::ifstream file(path, std::ios::binary); bool flush = true; +std::unique_ptr buf(new char[bufferSize]); do { -char buf[bufferSize]; -file.read(buf, sizeof(buf)); +file.read(&buf[0], bufferSize); const int size = file.gcount(); if (size > 0) -socket->send(buf, size, flush); +socket->send(&buf[0], size, flush); else break; flush = false; @@ -249,17 +248,22 @@ namespace HttpHelper std::ifstream file(path, std::ios::binary); bool flush = true; + +// FIXME: Should compress once ahead of time +// compression of bundle.js takes significant time: +// 200's ms for level 9 (468k), 72ms for level 1(587k) +// down from 2Mb. +std::unique_ptr buf(new char[st.st_size]); do { -static const unsigned int level = 9; -char buf[st.st_size]; // FIXME: Should compress in chunks. -file.read(buf, st.st_size); +static const unsigned int level = 1; +file.read(&buf[0], st.st_size); const long unsigned int size = file.gcount(); long unsigned int compSize = compressBound(size); -char cbuf[compSize]; -compress2((Bytef *)&cbuf, &compSize, (Bytef *)&buf, size, level); +std::unique_ptr cbuf(new char[compSize]); +compress2((Bytef *)&cbuf[0], &compSize, (Bytef *)&buf[0], size, level); if (size > 0) -socket->send(cbuf, compSize, flush); +socket->send(&cbuf[0], compSize, flush); else break; flush = false; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp
net/Socket.cpp | 28 ++-- 1 file changed, 14 insertions(+), 14 deletions(-) New commits: commit b734284b599bb612cd8eee13e761ce42c8eb8a6a Author: Ashod Nakashian Date: Mon Apr 3 23:57:59 2017 -0400 wsd: cleanup deflating HTTP responses Change-Id: Id21bdfcb5d3e04f27b681ee9581a0ed06283d163 Reviewed-on: https://gerrit.libreoffice.org/36058 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/net/Socket.cpp b/net/Socket.cpp index bac3a741..1f6d64d0 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -205,15 +205,17 @@ namespace HttpHelper response.set("ETag", "\"" LOOLWSD_VERSION_HASH "\""); } -if(!deflate) +int bufferSize = std::min(st.st_size, (off_t)Socket::MaximumSendBufferSize); +if (st.st_size >= socket->getSendBufferSize()) { -int bufferSize = std::min(st.st_size, (off_t)Socket::MaximumSendBufferSize); -if (st.st_size >= socket->getSendBufferSize()) -{ -socket->setSocketBufferSize(bufferSize); -bufferSize = socket->getSendBufferSize(); -} +socket->setSocketBufferSize(bufferSize); +bufferSize = socket->getSendBufferSize(); +} +// Deflate is done over the full file, which can be too large. +// Skip deflating (ironically) if the file is too large. +if (!deflate || st.st_size > Socket::MaximumSendBufferSize * 10) +{ response.setContentLength(st.st_size); std::ostringstream oss; response.write(oss); @@ -246,18 +248,16 @@ namespace HttpHelper socket->send(header); std::ifstream file(path, std::ios::binary); -uLong bufferSize; -bufferSize = st.st_size; -char buf[bufferSize]; bool flush = true; do { -unsigned int a = 9; -file.read(buf, sizeof(buf)); -long unsigned int size = file.gcount(); +static const unsigned int level = 9; +char buf[st.st_size]; // FIXME: Should compress in chunks. +file.read(buf, st.st_size); +const long unsigned int size = file.gcount(); long unsigned int compSize = compressBound(size); char cbuf[compSize]; -compress2((Bytef *)&cbuf, &compSize, (Bytef *)&buf, size, a) ; +compress2((Bytef *)&cbuf, &compSize, (Bytef *)&buf, size, level); if (size > 0) socket->send(cbuf, compSize, flush); else ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp
net/Socket.cpp | 13 ++--- net/Socket.hpp |6 ++ 2 files changed, 8 insertions(+), 11 deletions(-) New commits: commit d7858b08b90f989b0fe08c1f0309e4cd7f82c409 Author: Ashod Nakashian Date: Sun Apr 2 18:43:21 2017 -0400 wsd: fix race in setting SocketPoll owner thread id Change-Id: Idace925ab02425ed66ac07efc22ab933d229d42e Reviewed-on: https://gerrit.libreoffice.org/36032 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/net/Socket.cpp b/net/Socket.cpp index 3a07470c..bac3a741 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -52,16 +52,8 @@ SocketPoll::SocketPoll(const std::string& threadName) throw std::runtime_error("Failed to allocate pipe for SocketPoll [" + threadName + "] waking."); } -{ -std::lock_guard lock(getPollWakeupsMutex()); -getWakeupsArray().push_back(_wakeup[1]); -} - -#if ENABLE_DEBUG -_owner = std::this_thread::get_id(); -LOG_DBG("Thread affinity of " << _name << " set to 0x" << -std::hex << _owner << "." << std::dec); -#endif +std::lock_guard lock(getPollWakeupsMutex()); +getWakeupsArray().push_back(_wakeup[1]); } SocketPoll::~SocketPoll() @@ -92,7 +84,6 @@ void SocketPoll::startThread() try { _thread = std::thread(&SocketPoll::pollingThreadEntry, this); -_owner = _thread.get_id(); } catch (const std::exception& exc) { diff --git a/net/Socket.hpp b/net/Socket.hpp index 9977f481..200c389b 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -493,6 +493,12 @@ private: Util::setThreadName(_name); LOG_INF("Starting polling thread [" << _name << "]."); +#if ENABLE_DEBUG +_owner = std::this_thread::get_id(); +LOG_DBG("Thread affinity of " << _name << " set to 0x" << +std::hex << _owner << "." << std::dec); +#endif + // Invoke the virtual implementation. pollingThread(); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp wsd/LOOLWSD.cpp
net/Socket.cpp |5 - net/Socket.hpp | 15 --- wsd/LOOLWSD.cpp |4 +--- 3 files changed, 13 insertions(+), 11 deletions(-) New commits: commit d6577654bdc45892d9546ecfccdccd549b01921a Author: Ashod Nakashian Date: Sun Apr 2 17:49:14 2017 -0400 wsd: initialization and logging Change-Id: Icd82a966b94875a65ddb3817c88a3c4c7bedd4ff Reviewed-on: https://gerrit.libreoffice.org/36030 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/net/Socket.cpp b/net/Socket.cpp index 2b9899f8..3a07470c 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -43,7 +43,8 @@ SocketPoll::SocketPoll(const std::string& threadName) : _name(threadName), _stop(false), _threadStarted(false), - _threadFinished(false) + _threadFinished(false), + _owner(std::this_thread::get_id()) { // Create the wakeup fd. if (::pipe2(_wakeup, O_CLOEXEC | O_NONBLOCK) == -1) @@ -56,9 +57,11 @@ SocketPoll::SocketPoll(const std::string& threadName) getWakeupsArray().push_back(_wakeup[1]); } +#if ENABLE_DEBUG _owner = std::this_thread::get_id(); LOG_DBG("Thread affinity of " << _name << " set to 0x" << std::hex << _owner << "." << std::dec); +#endif } SocketPoll::~SocketPoll() diff --git a/net/Socket.hpp b/net/Socket.hpp index 94d4cc34..9977f481 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -47,15 +47,14 @@ public: Socket() : _fd(socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0)), -_sendBufferSize(DefaultSendBufferSize) +_sendBufferSize(DefaultSendBufferSize), +_owner(std::this_thread::get_id()) { init(); } virtual ~Socket() { -// TODO: Should we shutdown here or up to the client? - LOG_TRC("#" << getFD() << " Socket dtor."); // Doesn't block on sockets; no error handling needed. @@ -231,11 +230,13 @@ protected: _sendBufferSize = DefaultSendBufferSize; #if ENABLE_DEBUG _owner = std::this_thread::get_id(); -LOG_DBG("#" << _fd << " Thread affinity set to 0x" << std::hex << _owner << "." << std::dec); +LOG_DBG("#" << _fd << " Thread affinity set to 0x" << std::hex << +_owner << "." << std::dec); const int oldSize = getSocketBufferSize(); setSocketBufferSize(0); -LOG_TRC("#" << _fd << ": Buffer size: " << getSendBufferSize() << " (was " << oldSize << ")"); +LOG_TRC("#" << _fd << ": Buffer size: " << getSendBufferSize() << +" (was " << oldSize << ")"); #endif } @@ -323,8 +324,8 @@ public: rc = ::poll(&_pollFds[0], size + 1, std::max(timeoutMaxMs,0)); } while (rc < 0 && errno == EINTR); -LOG_TRC("Poll completed with " << rc << " live polls max (" << timeoutMaxMs << "ms)" -<< ((rc==0) ? "(timedout)" : "")); +LOG_TRC("Poll completed with " << rc << " live polls max (" << +timeoutMaxMs << "ms)" << ((rc==0) ? "(timedout)" : "")); // Fire the callback and remove dead fds. std::chrono::steady_clock::time_point newNow = diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index 05c6e1da..2cc7bf51 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -1322,9 +1322,7 @@ static std::shared_ptr createNewClientSession(const WebSocketHand // In case of WOPI, if this session is not set as readonly, it might be set so // later after making a call to WOPI host which tells us the permission on files // (UserCanWrite param). -auto session = std::make_shared(id, docBroker, uriPublic, isReadOnly); - -return session; +return std::make_shared(id, docBroker, uriPublic, isReadOnly); } catch (const std::exception& exc) { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp
net/Socket.cpp |2 - wsd/DocumentBroker.cpp |2 - wsd/LOOLWSD.cpp| 54 ++--- 3 files changed, 14 insertions(+), 44 deletions(-) New commits: commit fbf3b87626ab67d112813d5a207db5cb780ce701 Author: Ashod Nakashian Date: Tue Mar 28 01:07:07 2017 -0400 wsd: simplify and cleanup session creation Change-Id: I8cc05bc7a8dc89c6a521b81c6d59ff1e9968763a Reviewed-on: https://gerrit.libreoffice.org/35789 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/net/Socket.cpp b/net/Socket.cpp index 008070e3..cb863b1f 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -47,7 +47,7 @@ SocketPoll::SocketPoll(const std::string& threadName) // Create the wakeup fd. if (::pipe2(_wakeup, O_CLOEXEC | O_NONBLOCK) == -1) { -throw std::runtime_error("Failed to allocate pipe for SocketPoll waking."); +throw std::runtime_error("Failed to allocate pipe for SocketPoll [" + threadName + "] waking."); } { diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 83e00329..65e57fed 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -732,7 +732,7 @@ std::string DocumentBroker::getJailRoot() const size_t DocumentBroker::queueSession(std::shared_ptr& session) { -Util::assertIsLocked(_mutex); +std::unique_lock lock(_mutex); _sessions.emplace(session->getId(), session); _poll->wakeup(); diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index f8d6aa03..544901c0 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -1261,9 +1261,7 @@ static std::shared_ptr findOrCreateDocBroker(WebSocketHandler& w LOG_DBG("Found DocumentBroker with docKey [" << docKey << "]."); docBroker = it->second; -// Avoid notifying the client - either we catch and stop the -// destruction when we add the session, -or- the client -// re-connects. +// Destroying the document? Let the client reconnect. if (docBroker->isMarkedToDestroy()) { LOG_WRN("DocBroker with docKey [" << docKey << "] that is marked to be destroyed. Rejecting client request."); @@ -1309,28 +1307,6 @@ static std::shared_ptr findOrCreateDocBroker(WebSocketHandler& w return docBroker; } -/// Remove DocumentBroker session and instance from DocBrokers. -static void removeDocBrokerSession(const std::shared_ptr& docBroker, const std::string& id = "") -{ -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(); - -if (!id.empty()) -docBroker->removeSession(id); - -if (docBroker->getSessionsCount() == 0 || !docBroker->isAlive()) -{ -LOG_INF("Removing unloaded DocumentBroker for docKey [" << docKey << "]."); -DocBrokers.erase(docKey); -docBroker->terminateChild(lock, "", true); -} -} - static std::shared_ptr createNewClientSession(const WebSocketHandler* ws, const std::string& id, const Poco::URI& uriPublic, @@ -1340,10 +1316,14 @@ static std::shared_ptr createNewClientSession(const WebSocketHand LOG_CHECK_RET(docBroker && "Null docBroker instance", nullptr); try { -auto lock = docBroker->getLock(); - -if (docBroker->isMarkedToDestroy()) -LOG_WRN("DocBroker is marked to destroy, attempting to add session anyway."); +const std::string fs = FileUtil::checkDiskSpaceOnRegisteredFileSystems(); +if (!fs.empty()) +{ +LOG_WRN("File system of [" << fs << "] is dangerously low on disk space."); +const std::string diskfullMsg = "error: cmd=internal kind=diskfull"; +// Alert all other existing sessions also +Util::alertAllUsers(diskfullMsg); +} // Now we have a DocumentBroker and we're ready to process client commands. if (ws) @@ -1360,23 +1340,11 @@ static std::shared_ptr createNewClientSession(const WebSocketHand docBroker->queueSession(session); -lock.unlock(); - -const std::string fs = FileUtil::checkDiskSpaceOnRegisteredFileSystems(); -if (!fs.empty()) -{ -LOG_WRN("File system of [" << fs << "] is dangerously low on disk space."); -const std::string diskfullMsg = "error: cmd=internal kind=diskfull"; -// Alert all other existing sessions also -Util::alertAllUsers(diskfullMsg); -} - return session; } catch (const std::exception& exc) { LOG_WRN("Exception while preparing session [" << id << "]: " << exc.what()); -
[Libreoffice-commits] online.git: net/Socket.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp
net/Socket.cpp |2 ++ wsd/DocumentBroker.cpp |8 +++- wsd/DocumentBroker.hpp |4 wsd/LOOLWSD.cpp|7 +++ 4 files changed, 16 insertions(+), 5 deletions(-) New commits: commit ce0dffdc12f22fdae9d937cfbcb58df032b126d9 Author: Michael Meeks Date: Mon Mar 20 17:18:41 2017 + Use callback API to implement alertAllUsers safely and simply. diff --git a/net/Socket.cpp b/net/Socket.cpp index 0e5d6eab..008070e3 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -171,6 +171,8 @@ void SocketPoll::dumpState(std::ostream& os) // FIXME: NOT thread-safe! _pollSockets is modified from the polling thread! os << " Poll [" << _pollSockets.size() << "] - wakeup r: " << _wakeup[0] << " w: " << _wakeup[1] << "\n"; +if (_newCallbacks.size() > 0) +os << "\tcallbacks: " << _newCallbacks.size() << "\n"; os << "\tfd\tevents\trsize\twsize\n"; for (auto &i : _pollSockets) i->dumpState(os); diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index cfdec34a..936fee9a 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -863,6 +863,12 @@ size_t DocumentBroker::removeSessionInternal(const std::string& id) return _sessions.size(); } + +void DocumentBroker::addCallback(SocketPoll::CallbackFn fn) +{ +_poll->addCallback(fn); +} + void DocumentBroker::addSocketToPoll(const std::shared_ptr& socket) { _poll->insertNewSocket(socket); @@ -870,7 +876,7 @@ void DocumentBroker::addSocketToPoll(const std::shared_ptr& socket) void DocumentBroker::alertAllUsers(const std::string& msg) { -Util::assertIsLocked(_mutex); +assert(isCorrectThread()); auto payload = std::make_shared(msg, Message::Dir::Out); diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp index d3b87b8b..526f873d 100644 --- a/wsd/DocumentBroker.hpp +++ b/wsd/DocumentBroker.hpp @@ -270,6 +270,10 @@ public: /// Removes a session by ID. Returns the new number of sessions. size_t removeSession(const std::string& id, bool destroyIfLast = false); +/// Add a callback to be invoked in our polling thread. +void addCallback(SocketPoll::CallbackFn fn); + +/// Transfer this socket into our polling thread / loop. void addSocketToPoll(const std::shared_ptr& socket); void alertAllUsers(const std::string& msg); diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index b93098c6..120671e8 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -215,11 +215,10 @@ void alertAllUsersInternal(const std::string& msg) LOG_INF("Alerting all users: [" << msg << "]"); -//FIXME loolnb: due to thread-affinity of sockets we can't send from here. -// for (auto& brokerIt : DocBrokers) +for (auto& brokerIt : DocBrokers) { -// auto lock = brokerIt.second->getLock(); -// brokerIt.second->alertAllUsers(msg); +std::shared_ptr docBroker = brokerIt.second; +docBroker->addCallback([msg, docBroker](){ docBroker->alertAllUsers(msg); }); } } } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp
net/Socket.cpp |7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) New commits: commit c4d27fd060d93c61e9f475c63c34c828e84a55d6 Author: Ashod Nakashian Date: Sun Mar 12 22:29:58 2017 -0400 wsd: prevent and warn when joining own thread Change-Id: I8405a1aacb1281e52bbd07d32cdcf35bdc484d8b Reviewed-on: https://gerrit.libreoffice.org/35124 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/net/Socket.cpp b/net/Socket.cpp index de41e34..96734d0 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -56,7 +56,12 @@ SocketPoll::~SocketPoll() { stop(); if (_threadStarted && _thread.joinable()) -_thread.join(); +{ +if (_thread.get_id() == std::this_thread::get_id()) +LOG_ERR("DEADLOCK PREVENTED: joining own thread!"); +else +_thread.join(); +} ::close(_wakeup[0]); ::close(_wakeup[1]); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp wsd/DocumentBroker.cpp
net/Socket.cpp |3 ++- net/Socket.hpp |5 + wsd/DocumentBroker.cpp | 12 +--- 3 files changed, 12 insertions(+), 8 deletions(-) New commits: commit 9248107702745f37d321b5b31a22e9dc7a1963ec Author: Ashod Nakashian Date: Sun Mar 12 22:11:25 2017 -0400 wsd: SocketPoll reports thread isAlive and use in DocBroker Now that DocumentBroker has SocketPoll thread, it's isAlive() must be defined by the lifetime of both the SocketPoll thread and the ChildProcess, which it previously did. Change-Id: I093f8774cf4374d01729a383f6c535de4143fec6 Reviewed-on: https://gerrit.libreoffice.org/35122 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/net/Socket.cpp b/net/Socket.cpp index 48bc696..de41e34 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -35,7 +35,8 @@ namespace { SocketPoll::SocketPoll(const std::string& threadName) : _name(threadName), _stop(false), - _threadStarted(false) + _threadStarted(false), + _threadFinished(false) { // Create the wakeup fd. if (::pipe2(_wakeup, O_CLOEXEC | O_NONBLOCK) == -1) diff --git a/net/Socket.hpp b/net/Socket.hpp index c4badea..4fe334b 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -262,6 +262,8 @@ public: wakeup(); } +bool isAlive() const { return _threadStarted && !_threadFinished; } + /// Check if we should continue polling virtual bool continuePolling() { @@ -280,6 +282,8 @@ public: { poll(DefaultPollTimeoutMs); } + +_threadFinished = true; } /// Are we running in either shutdown, or the polling thread. @@ -478,6 +482,7 @@ protected: /// The polling thread. std::thread _thread; std::atomic _threadStarted; +std::atomic _threadFinished; std::thread::id _owner; }; diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 9e2087f..25686bf 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -152,6 +152,7 @@ DocumentBroker::DocumentBroker(const std::string& uri, _cursorWidth(0), _cursorHeight(0), _poll(new DocumentBrokerPoll("docbrk_poll", *this)), +_stop(false), _tileVersion(0), _debugRenderedTileCount(0) { @@ -159,8 +160,6 @@ DocumentBroker::DocumentBroker(const std::string& uri, assert(!_childRoot.empty()); LOG_INF("DocumentBroker [" << _uriPublic.toString() << "] created. DocKey: [" << _docKey << "]"); - -_stop = false; } // The inner heart of the DocumentBroker - our poll loop. @@ -248,12 +247,11 @@ void DocumentBroker::pollThread() bool DocumentBroker::isAlive() const { -if (!_childProcess) -return true; // waiting to get a child. -if (_stop) // we're dead. -return false; +if (_poll->isAlive()) +return true; // Polling thread still running. -return _childProcess->isAlive(); +// Shouldn't have live child process outside of the polling thread. +return _childProcess && _childProcess->isAlive(); } DocumentBroker::~DocumentBroker() ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits