-
-
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
tokio: Add back poll_* for udp #2981
Conversation
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.
These shouldn't be #[doc(hidden)]
.
Cool, I had them as The only async method that doesn't have a |
e803ced
to
b260e0c
Compare
tokio/src/net/udp/socket.rs
Outdated
/// This function may encounter any standard I/O error except `WouldBlock`. | ||
/// | ||
/// [`connect`]: method@Self::connect | ||
pub fn poll_recv(&self, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> { |
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.
Shouldn't buf
be the new ReadBuf
here?
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.
Good point. Same for poll_recv_from
.
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.
Ah okay. For converting ReadBuf
-> &mut buf
there's a few methods that we could use. initialize_unfilled
which is safe and initializes the buffer, and unfilled_mut
which is unsafe and assumes it's initialized. Methods in TcpStream
use the unsafe version but they are private, if that makes any difference.
edit: why exactly do we want ReadBuf
exposed here? UdpSocket
doesn't even implement AsyncRead
which is where ReadBuf
is mainly used/exposed
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.
Well ReadBuf
would allow receiving into uninitialized memory. I'm pretty sure the underlying IO primitives should support that. Even if you prefer to write a version that initializes it first, defining it with ReadBuf
would be necessary for adding that optimization later without a breaking change.
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.
Alright, updated.
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.
My only thought is that we should document that these poll_
methods have a downside of only being able to be associated to one task per read/write direction, as opposed to the async fn
methods, which should be preferred if you don't require polling specifically.
Right, I remember reading this about |
I don't think it decreases the use there. That's a case where |
8418437
to
b2aef3e
Compare
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.
Using the phrasing from Future
.
I was poking around in |
We already have those on |
tokio/src/net/udp/socket.rs
Outdated
pub fn poll_recv( | ||
&self, | ||
cx: &mut Context<'_>, | ||
buf: &mut ReadBuf<'_>, | ||
) -> Poll<io::Result<usize>> { |
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.
Since it uses ReadBuf
, it should return Result<()>
for consistency with AsyncReadExt::read
.
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.
I was going to reply saying poll_peek
on TcpStream
returns the size, but I just noticed it also does not use ReadBuf
. That's something that's been overlooked, yes? I can add a quick fix there also.
edit: It appears the use of &mut [u8]
in TcpStream
poll_ is pervasive and may be deserving of it's own PR. Open to suggestions
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.
Yes, TcpStream::poll_peek
was overlooked. See #2987.
Co-authored-by: Alice Ryhl <alice@ryhl.io>
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.
I think this is ready besides a doc typo.
Co-authored-by: Alice Ryhl <alice@ryhl.io>
As discussed in #2830 the first step to getting
UdpFramed
back is the poll functions. I've added these back, following the new style.I could have just re-enabled
UdpFramed
on this PR too, but I thought we might take the opportunity to discuss any changes that we may want to make to that. In it's current state it still requires a split-like API to do concurrent send/recv