MCPcopy Create free account
hub / github.com/Kistler-Group/sdbus-cpp / waitForNextEvent

Method waitForNextEvent

src/Connection.cpp:830–869  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

828}
829
830bool Connection::waitForNextEvent() // NOLINT(misc-no-recursion)
831{
832 assert(bus_ != nullptr);
833 assert(loopExitFd_.fd >= 0);
834 assert(eventFd_.fd >= 0);
835
836 auto sdbusPollData = getEventLoopPollData();
837 struct pollfd fds[] = { {sdbusPollData.fd, sdbusPollData.events, 0}
838 , {eventFd_.fd, POLLIN, 0}
839 , {loopExitFd_.fd, POLLIN, 0} };
840 constexpr auto fdsCount = sizeof(fds)/sizeof(fds[0]);
841
842 // Are there pending messages in the inbound queue? Then sd-bus will set timeout to 0, so poll() will wake up right away.
843 // Are there pending messages in the outbound queue? Then sd-bus will add POLLOUT to events, so poll() will wake up right away.
844 auto timeout = sdbusPollData.getPollTimeout();
845 auto r = poll(fds, fdsCount, timeout);
846
847 if (r < 0 && errno == EINTR)
848 return true; // Try again
849
850 SDBUS_THROW_ERROR_IF(r < 0, "Failed to wait on the bus", -errno);
851
852 // Wake up notification, in order that we re-enter poll with freshly read PollData (namely, new poll timeout thereof)
853 if (fds[1].revents & POLLIN) // NOLINT(readability-implicit-bool-conversion)
854 {
855 auto cleared = eventFd_.clear();
856 SDBUS_THROW_ERROR_IF(!cleared, "Failed to read from the event descriptor", -errno);
857 // Go poll() again, but with freshly calculated, up-to-date timeout and with up-to-date events to watch
858 return waitForNextEvent();
859 }
860 // Loop exit notification
861 if (fds[2].revents & POLLIN) // NOLINT(readability-implicit-bool-conversion)
862 {
863 auto cleared = loopExitFd_.clear();
864 SDBUS_THROW_ERROR_IF(!cleared, "Failed to read from the loop exit descriptor", -errno);
865 return false;
866 }
867
868 return true;
869}
870
871bool Connection::arePendingMessagesInQueues() const
872{

Callers

nothing calls this directly

Calls 2

getPollTimeoutMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected