wsd/DocumentBroker.cpp | 28 ++-------------------------- wsd/DocumentBroker.hpp | 9 ++------- wsd/LOOLWSD.cpp | 47 +++++++++++++++++++++++++++++------------------ 3 files changed, 33 insertions(+), 51 deletions(-)
New commits: commit 63ab3bcfa49ec9f6efb0fa81657ea64eaf0ab007 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sat Apr 1 19:20:54 2017 -0400 wsd: remove queueSession and simplify session loading Change-Id: Ia03a4ed64b743da8fa7e27de853623126698b9c0 Reviewed-on: https://gerrit.libreoffice.org/36016 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 0a6d2f01..494f21f3 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -223,22 +223,6 @@ void DocumentBroker::pollThread() // Main polling loop goodness. while (!_stop && _poll->continuePolling() && !TerminationFlag && !ShutdownRequestFlag) { - // First, load new sessions. - for (const auto& pair : _sessions) - { - try - { - auto& session = pair.second; - if (!session->isAttached()) - addSession(session); - } - catch (const std::exception& exc) - { - LOG_ERR("Error while adding new session to doc [" << _docKey << "]: " << exc.what()); - //TODO: Send failure to client and remove session. - } - } - _poll->poll(SocketPoll::DefaultPollTimeoutMs); if (!std::getenv("LOOL_NO_AUTOSAVE") && !_stop && @@ -746,16 +730,6 @@ std::string DocumentBroker::getJailRoot() const return Poco::Path(_childRoot, _jailId).toString(); } -size_t DocumentBroker::queueSession(std::shared_ptr<ClientSession>& session) -{ - std::unique_lock<std::mutex> lock(_mutex); - - _sessions.emplace(session->getId(), session); - _poll->wakeup(); - - return _sessions.size(); -} - size_t DocumentBroker::addSession(const std::shared_ptr<ClientSession>& session) { assert(isCorrectThread()); @@ -788,6 +762,8 @@ size_t DocumentBroker::addSession(const std::shared_ptr<ClientSession>& session) _markToDestroy = false; _stop = false; + // Add and attach the session. + _sessions.emplace(session->getId(), session); session->setAttached(); const auto id = session->getId(); diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp index a7473531..915db5a6 100644 --- a/wsd/DocumentBroker.hpp +++ b/wsd/DocumentBroker.hpp @@ -266,10 +266,8 @@ public: std::string getJailRoot() const; - /// Queue a new session to be attached asynchronously. - /// @return amount of session we have after all the queued ones will be - /// created. - size_t queueSession(std::shared_ptr<ClientSession>& session); + /// Add a new session. Returns the new number of sessions. + size_t addSession(const std::shared_ptr<ClientSession>& session); /// Removes a session by ID. Returns the new number of sessions. size_t removeSession(const std::string& id, bool destroyIfLast = false); @@ -354,9 +352,6 @@ private: /// Forward a message from child session to its respective client session. bool forwardToClient(const std::shared_ptr<Message>& payload); - /// Add a new session. Returns the new number of sessions. - size_t addSession(const std::shared_ptr<ClientSession>& session); - /// The thread function that all of the I/O for all sessions /// associated with this document. void pollThread(); diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index db5f55a2..05c6e1da 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -1324,8 +1324,6 @@ static std::shared_ptr<ClientSession> createNewClientSession(const WebSocketHand // (UserCanWrite param). auto session = std::make_shared<ClientSession>(id, docBroker, uriPublic, isReadOnly); - docBroker->queueSession(session); - return session; } catch (const std::exception& exc) @@ -1860,17 +1858,18 @@ private: auto clientSession = createNewClientSession(nullptr, _id, uriPublic, docBroker, isReadOnly); if (clientSession) { + clientSession->setSaveAsSocket(socket); + // Transfer the client socket to the DocumentBroker. // Move the socket into DocBroker. docBroker->addSocketToPoll(socket); socketOwnership = SocketHandlerInterface::SocketOwnership::MOVED; - clientSession->setSaveAsSocket(socket); - - docBroker->startThread(); - - docBroker->addCallback([&]() + docBroker->addCallback([&, clientSession]() { + // First add and load the session. + docBroker->addSession(clientSession); + // Load the document manually and request saving in the target format. std::string encodedFrom; URI::encode(docBroker->getPublicUri().getPath(), "", encodedFrom); @@ -1891,6 +1890,8 @@ private: clientSession->handleMessage(true, WebSocketHandler::WSOpCode::Text, saveasRequest); }); + docBroker->startThread(); + sent = true; } else @@ -2026,8 +2027,14 @@ private: SocketHandlerInterface::SocketOwnership handleClientWsUpgrade(const Poco::Net::HTTPRequest& request, const std::string& url) { - // requestHandler = new ClientRequestHandler(); - LOG_INF("Client WS request: " << request.getURI() << ", url: " << url); + auto socket = _socket.lock(); + if (!socket) + { + LOG_WRN("No socket to handle client WS upgrade for request: " << request.getURI() << ", url: " << url); + return SocketHandlerInterface::SocketOwnership::UNCHANGED; + } + + LOG_INF("Client WS request: " << request.getURI() << ", url: " << url << ", socket #" << socket->getFD()); // First Upgrade. WebSocketHandler ws(_socket, request); @@ -2074,17 +2081,21 @@ private: if (clientSession) { // Transfer the client socket to the DocumentBroker. - auto socket = _socket.lock(); - if (socket) + + // Set the ClientSession to handle Socket events. + socket->setHandler(clientSession); + LOG_DBG("Socket #" << socket->getFD() << " handler is " << clientSession->getName()); + + // Move the socket into DocBroker. + docBroker->addSocketToPoll(socket); + socketOwnership = SocketHandlerInterface::SocketOwnership::MOVED; + + docBroker->addCallback([docBroker, clientSession]() { - // Set the ClientSession to handle Socket events. - socket->setHandler(clientSession); - LOG_DBG("Socket #" << socket->getFD() << " handler is " << clientSession->getName()); + // Add and load the session. + docBroker->addSession(clientSession); + }); - // Move the socket into DocBroker. - docBroker->addSocketToPoll(socket); - socketOwnership = SocketHandlerInterface::SocketOwnership::MOVED; - } docBroker->startThread(); } else _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits