- while (session->running) {
- ret = g_poll(session->pollfds, session->num_sources, session->source_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 timeout 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->sources[i].poll_object);
- }
+ ret = g_poll(session->pollfds, session->num_sources,
+ block ? session->source_timeout : 0);
+ 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);
+ }
+ /*
+ * We want to take as little time as possible to stop
+ * the session if we have been told to do so. Therefore,
+ * we check the flag after processing every source, not
+ * just once per main event loop.
+ */
+ g_mutex_lock(&session->stop_mutex);
+ if (session->abort_session) {
+ sr_session_stop_sync(session);
+ /* But once is enough. */
+ session->abort_session = FALSE;