@@ -543,6 +543,7 @@ fido_hid_read(void *handle, unsigned char *buf, size_t len, int ms)
543
543
{
544
544
struct hid_osx * ctx = handle ;
545
545
ssize_t r ;
546
+ struct timespec ts ;
546
547
547
548
explicit_bzero (buf , len );
548
549
explicit_bzero (ctx -> report , sizeof (ctx -> report ));
@@ -552,20 +553,20 @@ fido_hid_read(void *handle, unsigned char *buf, size_t len, int ms)
552
553
return (-1 );
553
554
}
554
555
555
- /* check for pending frame */
556
- if ((r = read (ctx -> report_pipe [0 ], buf , len )) == -1 ) {
557
- if (errno != EAGAIN && errno != EWOULDBLOCK ) {
558
- fido_log_error (errno , "%s: read" , __func__ );
559
- return (-1 );
560
- }
561
-
562
- schedule_io_loop (ctx , ms );
556
+ if (fido_time_now (& ts ) != 0 ) {
557
+ fido_log_debug ("%s: fido_time_now" , __func__ );
558
+ return (-1 );
559
+ }
563
560
564
- if ((r = read (ctx -> report_pipe [0 ], buf , len )) == -1 ) {
561
+ do {
562
+ if ((r = read (ctx -> report_pipe [0 ], buf , len )) >= 0 )
563
+ break ;
564
+ if (errno != EAGAIN && errno != EWOULDBLOCK ) {
565
565
fido_log_error (errno , "%s: read" , __func__ );
566
566
return (-1 );
567
567
}
568
- }
568
+ schedule_io_loop (ctx , ms > 100 ? 100 : ms );
569
+ } while (fido_time_delta (& ts , & ms ) == 0 );
569
570
570
571
if (r < 0 || (size_t )r != len ) {
571
572
fido_log_debug ("%s: %zd != %zu" , __func__ , r , len );
0 commit comments