-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
io: impl AsyncSeek for BufReader/BufWriter #3491
Conversation
This comment has been minimized.
This comment has been minimized.
// 1.x AsyncSeek recommends calling poll_complete before start_seek. | ||
// We don't have to guarantee that the value returned by | ||
// poll_complete called without start_seek is correct, | ||
// so we'll return 0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have to guarantee that the value returned by poll_complete called without start_seek is correct,
@carllerche @Darksonn Is this assumption correct? If not, are there rules I need to follow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning Ok(0)
if poll_complete
is called before start_seek
seems reasonable to me.
// We needs to call seek operation multiple times. | ||
// And we should always call both start_seek and poll_complete, | ||
// as start_seek alone cannot guarantee that the operation will be completed. | ||
// poll_complete receives a Context and returns a Poll, so it cannot be called | ||
// inside start_seek. | ||
*self.project().seek_state = SeekState::Start(pos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another reason why this implementation is more complicated than the futures-rs one.
I'm getting some errors from this implementation in the writer when a
I fixed this on a personal fork by having the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine to me.
For some reason, I seemed to have forgotten about BufStream... 😅 |
Motivation
Closes #2291
Solution
The implementation and added tests are basically based on my PRs in futures-rs. (rust-lang/futures-rs#1573, rust-lang/futures-rs#1608)
However, the implementation is complicated than futures-rs due to: