Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to IO::Buffer read/write/pread/pwrite. #7826

Merged
merged 1 commit into from
May 24, 2023

Conversation

ioquatix
Copy link
Member

As discussed in socketry/async#224.

@ioquatix ioquatix force-pushed the io-buffer-write branch 4 times, most recently from b6ebbbe to 11b415d Compare May 21, 2023 13:39
@ioquatix
Copy link
Member Author

#7827

@ioquatix
Copy link
Member Author

I want to write some more tests.

@ioquatix ioquatix force-pushed the io-buffer-write branch 2 times, most recently from d6354ec to 243f1b5 Compare May 22, 2023 10:37
@ioquatix ioquatix merged commit 135a0d2 into ruby:master May 24, 2023
@ioquatix ioquatix deleted the io-buffer-write branch May 24, 2023 01:17
@@ -2508,23 2617,12 @@ rb_io_buffer_read(VALUE self, VALUE io, size_t length, size_t offset)
static VALUE
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think documentation needs update (at least length bytes, length is optional).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the documentation for read/write/pread/pwrite and it should be more consistent: #7860

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, it looks alright.

@@ -2629,41 2727,55 @@ rb_io_buffer_pread(VALUE self, VALUE io, rb_off_t from, size_t length, size_t of
static VALUE
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation

ssize_t result = read(argument->descriptor, argument->base, argument->size);

if (result < 0) {
return rb_fiber_scheduler_io_result(result, errno);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rb_fiber_scheduler_io_result returns either the read bytes or errno but not both, which can be problematic if a read fails in the second or later iteration. But as a workaround the caller can call read with length=0 and manually handle the retries if it needs this info, so I think this is a good trade-off, because the alternative would be to return both the read bytes and the errno, which would make an ugly api (errors would no longer be exceptions).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you and I'm not sure if there is a better way to return "partial read or partial write error". I think if you ask to read or write at least N bytes, if you don't get N bytes, it's an error. Otherwise, as you say, you should just manage the read/write process yourself.

nagachika pushed a commit to nagachika/ruby that referenced this pull request May 16, 2024
)

- Fix IO::Buffer `read`/`write` to use a minimum length.
nagachika pushed a commit that referenced this pull request May 18, 2024
- Fix IO::Buffer `read`/`write` to use a minimum length.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants