-
- ret = g_poll(session->pollfds, session->num_sources, timeout);
- for (i = 0; i < session->num_sources; i++) {
- if (session->pollfds[i].revents > 0 || (ret == 0
- && session->source_timeout == session->sources[i].timeout)) {
- /*
- * Invoke the source's callback on an event,
- * or if the poll timed out and this source
- * asked for that timeout.
- */
- if (!session->sources[i].cb(session->pollfds[i].fd,
- session->pollfds[i].revents,
- session->sources[i].cb_data))
- sr_session_source_remove(session,
- session->sources[i].poll_object);
+ if (min_due == INT64_MAX)
+ timeout_ms = -1;
+ else if (min_due > start_time)
+ timeout_ms = MIN((min_due - start_time + 999) / 1000, INT_MAX);
+ else
+ timeout_ms = 0;
+
+ ret = g_poll((GPollFD *)session->pollfds->data,
+ session->pollfds->len, timeout_ms);
+#ifdef G_OS_UNIX
+ if (ret < 0 && errno != EINTR) {
+ sr_err("Error in poll: %s", g_strerror(errno));
+ return SR_ERR;
+ }
+#else
+ if (ret < 0) {
+ sr_err("Error in poll: %d", ret);
+ return SR_ERR;
+ }
+#endif
+ stop_time = g_get_monotonic_time();
+ triggered = FALSE;
+ stopped = FALSE;
+
+ for (i = 0; i < session->sources->len; ++i) {
+ source = &g_array_index(session->sources, struct source, i);
+ if (source->triggered)
+ continue; /* already handled */
+
+ poll_object = source->poll_object;
+ fd = (int)poll_object;
+ revents = 0;
+
+ if (i < session->pollfds->len) {
+ pollfd = &g_array_index(session->pollfds, GPollFD, i);
+ fd = pollfd->fd;
+ if (ret > 0)
+ revents = pollfd->revents;