summaryrefslogtreecommitdiff
path: root/libusb/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'libusb/io.c')
-rw-r--r--libusb/io.c63
1 files changed, 20 insertions, 43 deletions
diff --git a/libusb/io.c b/libusb/io.c
index b23c76b..dd56857 100644
--- a/libusb/io.c
+++ b/libusb/io.c
@@ -1793,7 +1793,7 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv)
{
int r;
struct usbi_pollfd *ipollfd;
- nfds_t nfds = 0;
+ POLL_NFDS_TYPE nfds = 0;
struct pollfd *fds;
int i = -1;
int timeout_ms;
@@ -1937,8 +1937,8 @@ static int get_next_timeout(libusb_context *ctx, struct timeval *tv,
* non-blocking mode
* \returns 0 on success, or a LIBUSB_ERROR code on failure
*/
-int API_EXPORTED libusb_handle_events_timeout_check(libusb_context *ctx,
- struct timeval *tv, int *completed)
+int API_EXPORTED libusb_handle_events_timeout(libusb_context *ctx,
+ struct timeval *tv)
{
int r;
struct timeval poll_timeout;
@@ -1952,12 +1952,8 @@ int API_EXPORTED libusb_handle_events_timeout_check(libusb_context *ctx,
retry:
if (libusb_try_lock_events(ctx) == 0) {
- r = 0;
- if (completed == NULL || !*completed) {
- /* we obtained the event lock: do our own event handling */
- usbi_dbg("doing our own event handling");
- r = handle_events(ctx, &poll_timeout);
- }
+ /* we obtained the event lock: do our own event handling */
+ r = handle_events(ctx, &poll_timeout);
libusb_unlock_events(ctx);
return r;
}
@@ -1966,18 +1962,16 @@ retry:
* notify event completion. */
libusb_lock_event_waiters(ctx);
- if (completed == NULL || !*completed) {
- if (!libusb_event_handler_active(ctx)) {
- /* we hit a race: whoever was event handling earlier finished in the
- * time it took us to reach this point. try the cycle again. */
- libusb_unlock_event_waiters(ctx);
- usbi_dbg("event handler was active but went away, retrying");
- goto retry;
- }
-
- usbi_dbg("another thread is doing event handling, wait for notification");
- r = libusb_wait_for_event(ctx, &poll_timeout);
+ if (!libusb_event_handler_active(ctx)) {
+ /* we hit a race: whoever was event handling earlier finished in the
+ * time it took us to reach this point. try the cycle again. */
+ libusb_unlock_event_waiters(ctx);
+ usbi_dbg("event handler was active but went away, retrying");
+ goto retry;
}
+
+ usbi_dbg("another thread is doing event handling");
+ r = libusb_wait_for_event(ctx, &poll_timeout);
libusb_unlock_event_waiters(ctx);
if (r < 0)
@@ -1988,21 +1982,6 @@ retry:
return 0;
}
-int API_EXPORTED libusb_handle_events_timeout(libusb_context *ctx,
- struct timeval *tv)
-{
- return libusb_handle_events_timeout_check(ctx, tv, NULL);
-}
-
-int API_EXPORTED libusb_handle_events_check(libusb_context *ctx,
- int *completed)
-{
- struct timeval tv;
- tv.tv_sec = 60;
- tv.tv_usec = 0;
- return libusb_handle_events_timeout_check(ctx, &tv, completed);
-}
-
/** \ingroup poll
* Handle any pending events in blocking mode. There is currently a timeout
* hardcoded at 60 seconds but we plan to make it unlimited in future. For
@@ -2017,7 +1996,7 @@ int API_EXPORTED libusb_handle_events(libusb_context *ctx)
struct timeval tv;
tv.tv_sec = 60;
tv.tv_usec = 0;
- return libusb_handle_events_timeout_check(ctx, &tv, NULL);
+ return libusb_handle_events_timeout(ctx, &tv);
}
/** \ingroup poll
@@ -2145,24 +2124,22 @@ int API_EXPORTED libusb_get_next_timeout(libusb_context *ctx,
if (transfer->flags & (USBI_TRANSFER_TIMED_OUT | USBI_TRANSFER_OS_HANDLES_TIMEOUT))
continue;
+ /* no timeout for this transfer? */
+ if (!timerisset(&transfer->timeout))
+ continue;
+
found = 1;
break;
}
usbi_mutex_unlock(&ctx->flying_transfers_lock);
if (!found) {
- usbi_dbg("all URBs have already been processed for timeouts");
+ usbi_dbg("no URB with timeout or all handled by OS; no timeout!");
return 0;
}
next_timeout = &transfer->timeout;
- /* no timeout for next transfer */
- if (!timerisset(next_timeout)) {
- usbi_dbg("no URBs with timeouts, no timeout!");
- return 0;
- }
-
r = usbi_backend->clock_gettime(USBI_CLOCK_MONOTONIC, &cur_ts);
if (r < 0) {
usbi_err(ctx, "failed to read monotonic clock, errno=%d", errno);