diff --git a/src/hid_osx.c b/src/hid_osx.c index 9309762f..59aa439a 100644 --- a/src/hid_osx.c +++ b/src/hid_osx.c @@ -537,20 +537,28 @@ fido_hid_read(void *handle, unsigned char *buf, size_t len, int ms) return (-1); } - IOHIDDeviceScheduleWithRunLoop(ctx->ref, CFRunLoopGetCurrent(), - ctx->loop_id); + /* check for pending frame */ + if ((r = read(ctx->report_pipe[0], buf, len)) == -1) { + if (errno != EAGAIN && errno != EWOULDBLOCK) { + fido_log_error(errno, "%s: read", __func__); + return (-1); + } - if (ms == -1) - ms = 5000; /* wait 5 seconds by default */ + IOHIDDeviceScheduleWithRunLoop(ctx->ref, CFRunLoopGetCurrent(), + ctx->loop_id); - CFRunLoopRunInMode(ctx->loop_id, (double)ms/1000.0, true); + if (ms == -1) + ms = 5000; /* wait 5 seconds by default */ - IOHIDDeviceUnscheduleFromRunLoop(ctx->ref, CFRunLoopGetCurrent(), - ctx->loop_id); + CFRunLoopRunInMode(ctx->loop_id, (double)ms/1000.0, true); - if ((r = read(ctx->report_pipe[0], buf, len)) == -1) { - fido_log_error(errno, "%s: read", __func__); - return (-1); + IOHIDDeviceUnscheduleFromRunLoop(ctx->ref, + CFRunLoopGetCurrent(), ctx->loop_id); + + if ((r = read(ctx->report_pipe[0], buf, len)) == -1) { + fido_log_error(errno, "%s: read", __func__); + return (-1); + } } if (r < 0 || (size_t)r != len) {