Skip to content

Commit 237810b

Browse files
committed
Add support for non-blocking read.
1 parent 3a8e81c commit 237810b

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

ext/io/event/selector/uring.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

@@ -1093,7 +1107,7 @@ unsigned select_process_completions(struct IO_Event_Selector_URing *selector) {
10931107
}
10941108
}
10951109

1096-
if (DEBUG && completed > 0) fprintf(stderr, "select_process_completions(completed=%d)\n", completed);
1110+
if (DEBUG && completed > 0) fprintf(stderr, "select_process_completions: completed=%d\n", completed);
10971111

10981112
return completed;
10991113
}

0 commit comments

Comments
 (0)