diff --git a/kit/Kit.cpp b/kit/Kit.cpp index a70def8a0fe19..1ab73b692d4a8 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -3001,13 +3001,33 @@ int pollCallback(void* data, int timeoutUs) } // Do we have any pending input events from coolwsd ? -// FIXME: we could helpfully poll our incoming socket too here. bool anyInputCallback(void* data) { auto kitSocketPoll = reinterpret_cast(data); std::shared_ptr document = kitSocketPoll->getDocument(); - return document && document->hasQueueItems(); + if (document) + { + if (document->hasCallbacks()) + { + // Have pending LOK callbacks from core. + return true; + } + + // Poll our incoming socket from wsd. + int ret = kitSocketPoll->poll(std::chrono::microseconds(0), /*justPoll=*/true); + if (ret) + { + return true; + } + + if (document->hasQueueItems()) + { + return true; + } + } + + return false; } /// Called by LOK main-loop diff --git a/net/Socket.cpp b/net/Socket.cpp index 6047263d5377f..442f1adaa15e1 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -475,7 +475,7 @@ void SocketPoll::enableWatchdog() _watchdogTime = Watchdog::getTimestamp(); } -int SocketPoll::poll(int64_t timeoutMaxMicroS) +int SocketPoll::poll(int64_t timeoutMaxMicroS, bool justPoll) { if (_runOnClientThread) checkAndReThread(); @@ -526,6 +526,12 @@ int SocketPoll::poll(int64_t timeoutMaxMicroS) // from now we want to race back to sleep. enableWatchdog(); + if (justPoll && size > 0) + { + // Done with the poll(), don't process anything. + return _pollFds[0].revents; + } + // First process the wakeup pipe (always the last entry). if (_pollFds[size].revents) { diff --git a/net/Socket.hpp b/net/Socket.hpp index 9893800835c2c..c79bec8637a66 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -787,7 +787,7 @@ class SocketPoll /// Poll the sockets for available data to read or buffer to write. /// Returns the return-value of poll(2): 0 on timeout, /// -1 for error, and otherwise the number of events signalled. - int poll(std::chrono::microseconds timeoutMax) { return poll(timeoutMax.count()); } + int poll(std::chrono::microseconds timeoutMax, bool justPoll = false) { return poll(timeoutMax.count(), justPoll); } /// Poll the sockets for available data to read or buffer to write. /// Returns the return-value of poll(2): 0 on timeout, @@ -956,7 +956,7 @@ class SocketPoll } /// Actual poll implementation - int poll(int64_t timeoutMaxMicroS); + int poll(int64_t timeoutMaxMicroS, bool justPoll = false); /// Initialize the poll fds array with the right events void setupPollFds(std::chrono::steady_clock::time_point now,