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

Method onSdEventPrepare

src/Connection.cpp:434–462  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

432}
433
434int Connection::onSdEventPrepare(sd_event_source */*s*/, void *userdata)
435{
436 auto *connection = static_cast<Connection*>(userdata);
437 assert(connection != nullptr);
438
439 auto sdbusPollData = connection->getEventLoopPollData();
440
441 // Set poll events to watch out for on I/O fd
442 auto* sdIoEventSource = static_cast<sd_event_source*>(connection->sdEvent_->sdIoEventSource.get());
443 auto r = sd_event_source_set_io_events(sdIoEventSource, sdbusPollData.events);
444 SDBUS_THROW_ERROR_IF(r < 0, "Failed to set poll events for IO event source", -r);
445
446 // Set poll events to watch out for on internal event fd
447 auto* sdInternalEventSource = static_cast<sd_event_source*>(connection->sdEvent_->sdInternalEventSource.get());
448 r = sd_event_source_set_io_events(sdInternalEventSource, POLLIN);
449 SDBUS_THROW_ERROR_IF(r < 0, "Failed to set poll events for internal event source", -r);
450
451 // Set current timeout to the time event source (it may be zero if there are messages in the sd-bus queues to be processed)
452 auto* sdTimeEventSource = static_cast<sd_event_source*>(connection->sdEvent_->sdTimeEventSource.get());
453 r = sd_event_source_set_time(sdTimeEventSource, static_cast<uint64_t>(sdbusPollData.timeout.count()));
454 SDBUS_THROW_ERROR_IF(r < 0, "Failed to set timeout for time event source", -r);
455 // In case the timeout is infinite, we disable the timer in the sd_event loop.
456 // This prevents a syscall error, where `timerfd_settime` returns `EINVAL`,
457 // because the value is too big. See #324 for details
458 r = sd_event_source_set_enabled(sdTimeEventSource, sdbusPollData.timeout != std::chrono::microseconds::max() ? SD_EVENT_ONESHOT : SD_EVENT_OFF);
459 SDBUS_THROW_ERROR_IF(r < 0, "Failed to enable time event source", -r);
460
461 return 1;
462}
463
464void Connection::deleteSdEventSource(sd_event_source *source)
465{

Callers

nothing calls this directly

Calls 2

getEventLoopPollDataMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected