From 99c9b314b5d678f7f65efc517369b0f904851766 Mon Sep 17 00:00:00 2001 From: Ludvig Michaelsson Date: Thu, 21 Dec 2023 17:33:30 +0100 Subject: [PATCH] osx: add schedule_io_loop() --- src/hid_osx.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/hid_osx.c b/src/hid_osx.c index 9309762f..bd2e1c60 100644 --- a/src/hid_osx.c +++ b/src/hid_osx.c @@ -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) { @@ -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__);