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
net: add buffer size methods to UdpSocket #4363
Conversation
This adds: - UdpSocket::set_send_buffer_size - UdpSocket::send_buffer_size - UdpSocket::set_recv_buffer_size - UdpSocket::recv_buffer_size
tokio/src/net/udp.rs
Outdated
fn to_socket(&self) -> socket2::SockRef<'_> { | ||
socket2::SockRef::from(self) | ||
} |
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.
According to the API guidelines, this should be called as_socket
. It's not an expensive conversion.
fn to_socket(&self) -> socket2::SockRef<'_> { | |
socket2::SockRef::from(self) | |
} | |
fn as_socket(&self) -> socket2::SockRef<'_> { | |
socket2::SockRef::from(self) | |
} |
tokio/src/net/udp.rs
Outdated
pub fn set_send_buffer_size(&self, size: u32) -> io::Result<()> { | ||
self.to_socket().set_send_buffer_size(size as 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.
Why the casts?
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.
- socket2's set_send_buffer_size uses usize.
- tokio::net::TcpSocket's set_send_buffer_size uses u32.
This PR (tokio::net::UdpSocket) uses u32 for consistency with TcpSocket's methods, so we need casts here.
And as I said in #4270 (comment), these casts are fine.
- set_send_buffer_size,set_recv_buffer_size (cast u32 as usize): on tokio, usize is always at least 32 bits.
- send_buffer_size,recv_buffer_size (cast usize as u32): socket2 gets these values as c_int (always i32) and then cast them to usize (1, 2).
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.
Thanks.
This was removed in aea26b3. Any chance we could bring it back? Or is there another alternative available already? |
Open an issue about that. |
This adds:
Closes #3542
The first commit is from #4361.
Refs: