@@ -707,6 +707,20 @@ VALUE IO_Event_Selector_URing_io_read(VALUE self, VALUE fiber, VALUE io, VALUE b
707707 off_t from = io_seekable (descriptor );
708708
709709 size_t maximum_size = size - offset ;
710+
711+ // Are we performing a non-blocking read?
712+ if (!length ) {
713+ // If the (maximum) length is zero, that indicates we just want to read whatever is available without blocking.
714+ // If we schedule this read into the URing, it will block until data is available, rather than returning immediately.
715+ int state = IO_Event_Selector_nonblock_set (descriptor );
716+
717+ int result = read (descriptor , (char * )base + offset , maximum_size );
718+ int error = errno ;
719+
720+ IO_Event_Selector_nonblock_restore (descriptor , state );
721+ return rb_fiber_scheduler_io_result (result , errno );
722+ }
723+
710724 while (maximum_size ) {
711725 int result = io_read (selector , fiber , descriptor , (char * )base + offset , maximum_size , from );
712726
@@ -1068,6 +1082,7 @@ unsigned select_process_completions(struct IO_Event_Selector_URing *selector) {
10681082
10691083 // If the operation was cancelled, or the operation has no user data:
10701084 if (cqe -> user_data == 0 || cqe -> user_data == LIBURING_UDATA_TIMEOUT ) {
1085+ if (DEBUG_CQE ) fprintf (stderr , "select_process_completions: cqe res=%d user_data=%p (ignored)\n" , cqe -> res , (void * )cqe -> user_data );
10711086 io_uring_cq_advance (ring , 1 );
10721087 continue ;
10731088 }
@@ -1093,7 +1108,7 @@ unsigned select_process_completions(struct IO_Event_Selector_URing *selector) {
10931108 }
10941109 }
10951110
1096- if (DEBUG && completed > 0 ) fprintf (stderr , "select_process_completions( completed=%d) \n" , completed );
1111+ if (DEBUG && completed > 0 ) fprintf (stderr , "select_process_completions: completed=%d\n" , completed );
10971112
10981113 return completed ;
10991114}
0 commit comments