Skip to content

Commit

Permalink
osx: add schedule_io_loop()
Browse files Browse the repository at this point in the history
  • Loading branch information
LDVG committed Dec 21, 2023
1 parent 9634391 commit 99c9b31
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/hid_osx.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,21 @@ fido_hid_set_sigmask(void *handle, const fido_sigset_t *sigmask)
return (FIDO_ERR_INTERNAL);
}

static void
schedule_io_loop(struct hid_osx *ctx, int ms)
{
IOHIDDeviceScheduleWithRunLoop(ctx->ref, CFRunLoopGetCurrent(),
ctx->loop_id);

if (ms == -1)
ms = 5000; /* wait 5 seconds by default */

CFRunLoopRunInMode(ctx->loop_id, (double)ms/1000.0, true);

IOHIDDeviceUnscheduleFromRunLoop(ctx->ref, CFRunLoopGetCurrent(),
ctx->loop_id);
}

int
fido_hid_read(void *handle, unsigned char *buf, size_t len, int ms)
{
Expand All @@ -537,16 +552,7 @@ fido_hid_read(void *handle, unsigned char *buf, size_t len, int ms)
return (-1);
}

IOHIDDeviceScheduleWithRunLoop(ctx->ref, CFRunLoopGetCurrent(),
ctx->loop_id);

if (ms == -1)
ms = 5000; /* wait 5 seconds by default */

CFRunLoopRunInMode(ctx->loop_id, (double)ms/1000.0, true);

IOHIDDeviceUnscheduleFromRunLoop(ctx->ref, CFRunLoopGetCurrent(),
ctx->loop_id);
schedule_io_loop(ctx, ms);

if ((r = read(ctx->report_pipe[0], buf, len)) == -1) {
fido_log_error(errno, "%s: read", __func__);
Expand Down

0 comments on commit 99c9b31

Please sign in to comment.