chore(connlib): report UDP socket buffer sizes (#6564)

The actual size of the send and receive buffers is OS-dependent. To aid
debugging with customer-submitted logs, we now print the size of the
send and receive buffers of each UDP socket.
This commit is contained in:
Thomas Eizinger
2024-09-12 00:00:50 -04:00
committed by GitHub
parent 7adbf9c6af
commit 0939068492

View File

@@ -8,7 +8,6 @@ use std::{
task::{ready, Context, Poll},
};
use socket2::SockAddr;
use std::any::Any;
use std::collections::hash_map::Entry;
use std::pin::Pin;
@@ -32,8 +31,8 @@ pub fn tcp(addr: &SocketAddr) -> io::Result<TcpSocket> {
})
}
pub fn udp(addr: &SocketAddr) -> io::Result<UdpSocket> {
let addr: SockAddr = (*addr).into();
pub fn udp(std_addr: &SocketAddr) -> io::Result<UdpSocket> {
let addr = socket2::SockAddr::from(*std_addr);
let socket = socket2::Socket::new(addr.domain(), socket2::Type::DGRAM, None)?;
// Note: for AF_INET sockets IPV6_V6ONLY is not a valid flag
@@ -44,6 +43,11 @@ pub fn udp(addr: &SocketAddr) -> io::Result<UdpSocket> {
socket.set_nonblocking(true)?;
socket.bind(&addr)?;
let send_buf_size = socket.send_buffer_size()?;
let recv_buf_size = socket.recv_buffer_size()?;
tracing::info!(addr = %std_addr, %send_buf_size, %recv_buf_size, "Created new UDP socket");
let socket = std::net::UdpSocket::from(socket);
let socket = tokio::net::UdpSocket::try_from(socket)?;
let socket = UdpSocket::new(socket)?;