[Libreoffice-commits] online.git: loolwsd/ChildProcessSession.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Sun Dec 27 20:15:20 PST 2015
loolwsd/ChildProcessSession.cpp | 6 +---
loolwsd/LOOLKit.cpp | 48 ++++++++++++++++++++++-----------------
loolwsd/LOOLWSD.cpp | 12 +++++----
loolwsd/MasterProcessSession.cpp | 23 ++++++++----------
4 files changed, 48 insertions(+), 41 deletions(-)
New commits:
commit 6b997c2abfe708b93165e601262b55e073d9ee91
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Dec 27 22:54:52 2015 -0500
loolwsd: threadId -> sessionId in logs and identifiers
Change-Id: Ifbaea2fdded54da0d3528ae449efdbd7fe6d19c0
Reviewed-on: https://gerrit.libreoffice.org/20982
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp
index 7d22070..06b997c 100644
--- a/loolwsd/ChildProcessSession.cpp
+++ b/loolwsd/ChildProcessSession.cpp
@@ -54,14 +54,12 @@ ChildProcessSession::ChildProcessSession(const std::string& id,
_childId(childId),
_clientPart(0)
{
- Log::info() << "ChildProcessSession ctor " << Kind::ToMaster
- << " this:" << this << " ws:" << _ws.get() << Log::end;
+ Log::info("ChildProcessSession ctor [" + getName() + "].");
}
ChildProcessSession::~ChildProcessSession()
{
- Log::info() << "ChildProcessSession dtor " << Kind::ToMaster
- << " this:" << this << " ws:" << _ws.get() << Log::end;
+ Log::info("~ChildProcessSession dtor [" + getName() + "].");
if (_loKitDocument != nullptr)
{
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 5dd5b6a..3a4cd08 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -340,13 +340,13 @@ class Connection: public Runnable
{
public:
Connection(LibreOfficeKit *loKit, LibreOfficeKitDocument *loKitDocument,
- const std::string& childId, const std::string& threadId) :
+ const std::string& childId, const std::string& sessionId) :
_loKit(loKit),
_loKitDocument(loKitDocument),
_childId(childId),
- _threadId(threadId)
+ _sessionId(sessionId)
{
- Log::info("New connection in child: " + childId + ", thread: " + _threadId);
+ Log::info("New connection in child: " + childId + ", thread: " + _sessionId);
}
void start()
@@ -384,12 +384,12 @@ public:
HTTPResponse response;
auto ws = std::make_shared<WebSocket>(cs, request, response);
- _session.reset(new ChildProcessSession(_threadId, ws, _loKit, _loKitDocument, _childId));
+ _session.reset(new ChildProcessSession(_sessionId, ws, _loKit, _loKitDocument, _childId));
ws->setReceiveTimeout(0);
// child Jail TID PID
std::string hello("child " + _childId + " " +
- _threadId + " " + std::to_string(Process::id()));
+ _sessionId + " " + std::to_string(Process::id()));
_session->sendTextFrame(hello);
TileQueue queue;
@@ -438,7 +438,7 @@ public:
~Connection()
{
- Log::info("Closing connection in child: " + _childId + ", thread: " + _threadId);
+ Log::info("Closing connection in child: " + _childId + ", thread: " + _sessionId);
//_thread.stop();
}
@@ -446,7 +446,7 @@ private:
LibreOfficeKit *_loKit;
LibreOfficeKitDocument *_loKitDocument;
const std::string _childId;
- std::string _threadId;
+ std::string _sessionId;
Thread _thread;
std::shared_ptr<ChildProcessSession> _session;
};
@@ -584,41 +584,49 @@ void run_lok_main(const std::string &loSubPath, const std::string& childId, cons
}
else if (tokens[0] == "thread")
{
- const std::string& threadId = tokens[1];
- Log::debug("Thread request for [" + threadId + "]");
- const auto& aItem = _connections.find(threadId);
+ const std::string& sessionId = tokens[1];
+ Log::debug("Thread request for [" + sessionId + "]");
+ const auto& aItem = _connections.find(sessionId);
if (aItem != _connections.end())
{
// found item, check if still running
- Log::debug("Found thread for [" + threadId + "] " +
+ Log::debug("Found thread for [" + sessionId + "] " +
(aItem->second->isRunning() ? "Running" : "Stopped"));
- if ( !aItem->second->isRunning() )
- Log::warn("Thread [" + threadId + "] is not running.");
+ if (!aItem->second->isRunning())
+ {
+ // Restore thread.
+ Log::warn("Thread [" + sessionId + "] is not running. Restoring.");
+ _connections.erase(sessionId);
+
+ auto thread = std::make_shared<Connection>(loKit.get(), aItem->second->getLOKitDocument(), childId, sessionId);
+ _connections.emplace(sessionId, thread);
+ thread->start();
+ }
}
else
{
// new thread id
- Log::debug("Starting new thread for request [" + threadId + "]");
+ Log::debug("Starting new thread for request [" + sessionId + "]");
std::shared_ptr<Connection> thread;
if ( _connections.empty() )
{
- Log::info("Creating main thread for child: " + childId + ", thread: " + threadId);
- thread = std::make_shared<Connection>(loKit.get(), nullptr, childId, threadId);
+ Log::info("Creating main thread for child: " + childId + ", thread: " + sessionId);
+ thread = std::make_shared<Connection>(loKit.get(), nullptr, childId, sessionId);
}
else
{
- Log::info("Creating view thread for child: " + childId + ", thread: " + threadId);
+ Log::info("Creating view thread for child: " + childId + ", thread: " + sessionId);
auto aConnection = _connections.begin();
- thread = std::make_shared<Connection>(loKit.get(), aConnection->second->getLOKitDocument(), childId, threadId);
+ thread = std::make_shared<Connection>(loKit.get(), aConnection->second->getLOKitDocument(), childId, sessionId);
}
- auto aInserted = _connections.emplace(threadId, thread);
+ auto aInserted = _connections.emplace(sessionId, thread);
if ( aInserted.second )
thread->start();
else
- Log::error("Connection already exists for child: " + childId + ", thread: " + threadId);
+ Log::error("Connection already exists for child: " + childId + ", thread: " + sessionId);
Log::debug("Connections: " + std::to_string(_connections.size()));
}
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index fd8085f..09da719 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -318,7 +318,7 @@ public:
{
std::string thread_name;
if (request.serverAddress().port() == MASTER_PORT_NUMBER)
- thread_name = "prision_socket";
+ thread_name = "prison_socket";
else
thread_name = "client_socket";
@@ -492,10 +492,11 @@ public:
}
else if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
{
- std::string firstLine = getFirstLine(buffer, n);
+ const std::string firstLine = getFirstLine(buffer, n);
StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
- if (kind == LOOLSession::Kind::ToClient && firstLine.size() == static_cast<std::string::size_type>(n))
+ if (kind == LOOLSession::Kind::ToClient &&
+ firstLine.size() == static_cast<std::string::size_type>(n))
{
queue.put(firstLine);
}
@@ -504,9 +505,10 @@ public:
// Check if it is a "nextmessage:" and in that case read the large
// follow-up message separately, and handle that only.
int size;
- if (tokens.count() == 2 && tokens[0] == "nextmessage:" && getTokenInteger(tokens[1], "size", size) && size > 0)
+ if (tokens.count() == 2 &&
+ tokens[0] == "nextmessage:" && getTokenInteger(tokens[1], "size", size) && size > 0)
{
- char largeBuffer[size];
+ char largeBuffer[size]; //FIXME: Security risk! Flooding may segfault us.
n = ws->receiveFrame(largeBuffer, size, flags);
if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index c901449..8eb2bf5 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -57,14 +57,12 @@ MasterProcessSession::MasterProcessSession(const std::string& id,
_curPart(0),
_loadPart(-1)
{
- Log::info() << "MasterProcessSession ctor " << _kindString
- << " this:" << this << " ws:" << _ws.get() << Log::end;
+ Log::info("MasterProcessSession ctor [" + getName() + "].");
}
MasterProcessSession::~MasterProcessSession()
{
- Log::info() << "MasterProcessSession dtor " << _kindString
- << " this:" << this << " ws:" << _ws.get() << Log::end;
+ Log::info("~MasterProcessSession dtor [" + getName() + "].");
auto peer = _peer.lock();
if (_kind == Kind::ToClient && peer)
@@ -236,7 +234,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
// Message from child process to be forwarded to client.
// I think we should never get here
- Log::error("Unexpected request [" + tokens[0] + "].");
+ Log::error(getName() + ": Unexpected request [" + tokens[0] + "].");
assert(false);
}
else if (tokens[0] == "load")
@@ -591,7 +589,7 @@ void MasterProcessSession::dispatchChild()
if (nRequest < 0 && !bFound)
{
- Log::error("Failed to connect to child. Shutting down socket.");
+ Log::error(getName() + ": Failed to connect to child. Shutting down socket.");
Util::shutdownWebSocket(*_ws);
return;
}
@@ -617,8 +615,7 @@ void MasterProcessSession::dispatchChild()
}
catch (const Exception& exc)
{
- Log::error(
- "createDirectories(\"" + aDstPath.toString() + "\") failed: " + exc.displayText() );
+ Log::error(getName() + ": createDirectories(\"" + aDstPath.toString() + "\") failed: " + exc.displayText() );
}
// cleanup potential leftovers from the last time
@@ -629,7 +626,7 @@ void MasterProcessSession::dispatchChild()
if (!File(aDstFile).exists() && link(aSrcFile.toString().c_str(), aDstFile.toString().c_str()) == -1)
{
// Failed
- Log::error("link(\"" + aSrcFile.toString() + "\",\"" + aDstFile.toString() + "\") failed.");
+ Log::error(getName() + ": link(\"" + aSrcFile.toString() + "\",\"" + aDstFile.toString() + "\") failed.");
}
#endif
@@ -644,7 +641,7 @@ void MasterProcessSession::dispatchChild()
}
catch (const Exception& exc)
{
- Log::error("copyTo(\"" + aSrcFile.toString() + "\",\"" + aDstFile.toString() + "\") failed: " + exc.displayText());
+ Log::error(getName() + ": copyTo(\"" + aSrcFile.toString() + "\",\"" + aDstFile.toString() + "\") failed: " + exc.displayText());
}
}
@@ -658,11 +655,13 @@ void MasterProcessSession::dispatchChild()
void MasterProcessSession::forwardToPeer(const char *buffer, int length)
{
- Log::trace(_kindString + ",forwardToPeer," + getAbbreviatedMessage(buffer, length));
+ const auto message = getAbbreviatedMessage(buffer, length);
+ Log::trace(_kindString + ",forwardToPeer," + message);
+
auto peer = _peer.lock();
if (!peer)
{
- Log::error("Error: no peer to forward to.");
+ Log::error(getName() + ": no peer to forward to.");
return;
}
peer->sendBinaryFrame(buffer, length);
More information about the Libreoffice-commits
mailing list