-
- if (revents > 0 || (ret == 0
- && session->source_timeout == source->timeout)) {
- /*
- * Invoke the source's callback on an event,
- * or if the poll timed out and this source
- * asked for that timeout.
- */
- if (!source->cb(pollfd->fd, revents, source->cb_data))
- sr_session_source_remove(session,
- source->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.
- */
- if (!stopped) {
- stopped = sr_session_check_aborted(session);
- stop_checked = TRUE;
- }
+ due = source->due;
+#ifdef HAVE_LIBUSB_1_0
+ if (source->is_usb && usb_due < due)
+ due = usb_due;
+#endif
+ if (revents == 0 && stop_time < due)
+ continue;
+ /*
+ * The source may be gone after the callback returns,
+ * so access any data now that needs accessing.
+ */
+ poll_object = source->poll_object;
+ if (source->timeout > 0)
+ source->due = stop_time + INT64_C(1000) * source->timeout;
+ pollfd->revents = 0;
+ /*
+ * Invoke the source's callback on an event or timeout.
+ */
+ if (!source->cb(pollfd->fd, revents, source->cb_data))
+ sr_session_source_remove(session, 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.
+ */
+ if (!stopped) {
+ stopped = sr_session_check_aborted(session);
+ stop_checked = TRUE;