[Libreoffice-commits] online.git: 2 commits - loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Thu Dec 24 19:33:06 PST 2015
loolwsd/LOOLBroker.cpp | 29 ++++++++++++++++---------
loolwsd/LOOLKit.cpp | 56 +++++++++++++++++++++++++++----------------------
2 files changed, 50 insertions(+), 35 deletions(-)
New commits:
commit da23160ed16528d464a8a6e89c66139ff26a0de9
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Thu Dec 24 22:24:26 2015 -0500
loolwsd: misc cleanups
Change-Id: I85cdd017ef5b483d34a2aa7e7a2b0c112cbf6e00
Reviewed-on: https://gerrit.libreoffice.org/20933
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 1862aa5..d2bc9fc 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -170,7 +170,7 @@ namespace
cap_value_t cap_list[] = { capability };
caps = cap_get_proc();
- if (caps == NULL)
+ if (caps == nullptr)
{
Log::error("Error: cap_get_proc() failed.");
exit(1);
@@ -189,7 +189,7 @@ namespace
exit(1);
}
- char *capText = cap_to_text(caps, NULL);
+ char *capText = cap_to_text(caps, nullptr);
std::cout << Util::logPrefix() + "Capabilities now: " + capText << std::endl;
cap_free(capText);
@@ -255,7 +255,7 @@ public:
nBytes = Util::readMessage(nPipeReader, _aBuffer, sizeof(_aBuffer));
if ( nBytes < 0 )
{
- _pStart = _pEnd = NULL;
+ _pStart = _pEnd = nullptr;
break;
}
@@ -303,7 +303,6 @@ public:
ssize_t updateURL(Process::PID nPID, const std::string& aURL)
{
- std::string aResponse;
std::string aMessage = "url " + aURL + "\r\n";
return sendMessage(_childProcesses[nPID], aMessage);
}
@@ -370,7 +369,7 @@ public:
std::string aURL = tokens[2];
// check cache
- auto aIterURL = _cacheURL.find(aURL);
+ const auto aIterURL = _cacheURL.find(aURL);
if ( aIterURL != _cacheURL.end() )
{
Log::debug("Cache found URL [" + aURL + "] hosted on child [" + std::to_string(aIterURL->second) +
@@ -532,20 +531,22 @@ static int createLibreOfficeKit(bool sharePages, std::string loSubPath, Poco::UI
Poco::UInt64 pid;
if (!(pid = fork()))
- { // child
+ {
+ // child
run_lok_main(loSubPath, childID, "");
_exit(0);
}
else
- { // parent
+ {
+ // parent
child = pid; // (somehow - switch the hash to use real pids or ?) ...
}
}
else
{
Process::Args args;
- std::string executable = "loolkit";
- std::string pipe = BROKER_PREFIX + std::to_string(childCounter++) + BROKER_SUFIX;
+ const std::string executable = "loolkit";
+ const std::string pipe = BROKER_PREFIX + std::to_string(childCounter++) + BROKER_SUFIX;
if (mkfifo(pipe.c_str(), 0666) < 0)
{
@@ -599,6 +600,14 @@ static int startupLibreOfficeKit(bool sharePages, int nLOKits,
// Broker process
int main(int argc, char** argv)
{
+ if (std::getenv("SLEEPFORDEBUGGER"))
+ {
+ std::cerr << "Sleeping " << std::getenv("SLEEPFORDEBUGGER")
+ << " seconds to attach debugger to process "
+ << Process::id() << std::endl;
+ Thread::sleep(std::stoul(std::getenv("SLEEPFORDEBUGGER")) * 1000);
+ }
+
// Initialization
Log::initialize("brk");
@@ -611,7 +620,7 @@ int main(int argc, char** argv)
for (int i = 0; i < argc; ++i)
{
char *cmd = argv[i];
- char *eq = NULL;
+ char *eq = nullptr;
if (strstr(cmd, "--losubpath=") == cmd)
{
eq = strchrnul(cmd, '=');
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 229eca8..9b0180e 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -251,16 +251,12 @@ FastMutex CallBackWorker::_mutex;
class QueueHandler: public Runnable
{
public:
- QueueHandler(MessageQueue& queue):
- _queue(queue)
+ QueueHandler(MessageQueue& queue, const std::shared_ptr<LOOLSession>& session):
+ _queue(queue),
+ _session(session)
{
}
- void setSession(std::shared_ptr<LOOLSession> session)
- {
- _session = session;
- }
-
void run() override
{
#ifdef __linux
@@ -291,8 +287,8 @@ public:
}
private:
- std::shared_ptr<LOOLSession> _session;
MessageQueue& _queue;
+ std::shared_ptr<LOOLSession> _session;
};
class Connection: public Runnable
@@ -348,10 +344,9 @@ public:
_session->sendTextFrame(hello);
TileQueue queue;
- Thread queueHandlerThread;
- QueueHandler handler(queue);
+ QueueHandler handler(queue, _session);
- handler.setSession(_session);
+ Thread queueHandlerThread;
queueHandlerThread.start(handler);
int flags;
@@ -405,11 +400,19 @@ private:
void run_lok_main(const std::string &loSubPath, Poco::UInt64 _childId, const std::string& pipe)
{
+ if (std::getenv("SLEEPFORDEBUGGER"))
+ {
+ std::cerr << "Sleeping " << std::getenv("SLEEPFORDEBUGGER")
+ << " seconds to attach debugger to process "
+ << Process::id() << std::endl;
+ Thread::sleep(std::stoul(std::getenv("SLEEPFORDEBUGGER")) * 1000);
+ }
+
struct pollfd aPoll;
ssize_t nBytes = -1;
char aBuffer[1024*2];
- char* pStart = NULL;
- char* pEnd = NULL;
+ char* pStart = nullptr;
+ char* pEnd = nullptr;
std::string aURL;
std::map<std::string, std::shared_ptr<Connection>> _connections;
@@ -422,13 +425,6 @@ void run_lok_main(const std::string &loSubPath, Poco::UInt64 _childId, const std
Log::error("Cannot set thread name.");
#endif
- if (std::getenv("SLEEPFORDEBUGGER"))
- {
- std::cout << "Sleeping " << std::getenv("SLEEPFORDEBUGGER") << " seconds, attach process "
- << Process::id() << " in debugger now." << std::endl;
- Thread::sleep(std::stoul(std::getenv("SLEEPFORDEBUGGER")) * 1000);
- }
-
try
{
#ifdef __APPLE__
@@ -550,7 +546,7 @@ void run_lok_main(const std::string &loSubPath, Poco::UInt64 _childId, const std
if ( _connections.empty() )
{
Log::info("Creating main thread for child: " + std::to_string(_childId) + ", thread: " + threadId);
- thread = std::shared_ptr<Connection>(new Connection(loKit, NULL, _childId, threadId));
+ thread = std::shared_ptr<Connection>(new Connection(loKit, nullptr, _childId, threadId));
}
else
{
@@ -619,7 +615,7 @@ int main(int argc, char** argv)
for (int i = 1; i < argc; ++i)
{
char *cmd = argv[i];
- char *eq = NULL;
+ char *eq = nullptr;
if (strstr(cmd, "--losubpath=") == cmd)
{
eq = strchrnul(cmd, '=');
commit c52a19c9bf420c157dcdb005a590cf78209bea39
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Thu Dec 24 22:23:54 2015 -0500
loolwsd: Prevent CPU hogging when pipe breaks
Change-Id: Iec42dbb64354630911a2c555ad55fd6a905db9b8
Reviewed-on: https://gerrit.libreoffice.org/20932
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index b003bfb..229eca8 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -474,9 +474,13 @@ void run_lok_main(const std::string &loSubPath, Poco::UInt64 _childId, const std
aPoll.events = POLLIN;
aPoll.revents = 0;
- (void)poll(&aPoll, 1, -1);
-
- if( (aPoll.revents & POLLIN) != 0 )
+ if (poll(&aPoll, 1, -1) < 0)
+ {
+ Log::error("Failed to poll pipe [" + pipe + "].");
+ continue;
+ }
+ else
+ if (aPoll.revents & POLLIN)
{
nBytes = Util::readFIFO(readerBroker, aBuffer, sizeof(aBuffer));
if (nBytes < 0)
@@ -488,6 +492,12 @@ void run_lok_main(const std::string &loSubPath, Poco::UInt64 _childId, const std
pStart = aBuffer;
pEnd = aBuffer + nBytes;
}
+ else
+ if (aPoll.revents & (POLLERR | POLLHUP))
+ {
+ Log::error("Broken pipe [" + pipe + "] with broker.");
+ break;
+ }
}
if ( pStart != pEnd )
More information about the Libreoffice-commits
mailing list