From 515785c6f7c2724f8e95174fbbdbf4208c1135f9 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Penna Date: Mon, 19 Oct 2026 15:57:08 -0300 Subject: [PATCH] nvx-rs: create both guest datagram sockets with UdpSocket::ipv4 guest::sys::socket creates two close-on-exec IPv4 UDP sockets: the one that connect_datagram connects for nvx-device-io's network benchmark, and the unconnected UdpSocket from which nvx-ingress sends its announcements. connect_datagram spelled out the same socket(AF_INET, SOCK_DGRAM, SOCK_CLOEXEC) call as UdpSocket::ipv4, so the module kept two copies of the socket's family, type, and flags. connect_datagram now takes its socket from UdpSocket::ipv4, connects it, and returns it as the FileDescriptor that the benchmark reads and writes, as before. The module creates every datagram socket in one place, so the two programs cannot drift apart. Behavior is unchanged. Both programs make the same socket and connect system calls, with the same arguments and in the same order, and get the same errno when either fails. A socket whose connect fails still closes when its owner drops. The change is confined to the guest binaries' system layer, which only the guest feature builds. The socket module's tests cover UdpSocket::ipv4, the system layer's connected_datagrams_wait_for_and_receive_echoes covers connect_datagram, and the guest-tool test device_io_measures_a_network_round_trip runs the nvx-device-io binary against a local echo server. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- nvx-rs/src/guest/sys/socket.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/nvx-rs/src/guest/sys/socket.rs b/nvx-rs/src/guest/sys/socket.rs index 2154f765e..f1769459c 100644 --- a/nvx-rs/src/guest/sys/socket.rs +++ b/nvx-rs/src/guest/sys/socket.rs @@ -12,12 +12,7 @@ use super::{Errno, FileDescriptor}; /// Connecting fixes the destination of every `write` and the only source from which `read` /// receives, as the `socket` and `connect` calls of `nvx-device-io`'s C program did. pub(crate) fn connect_datagram(peer: SocketAddrV4) -> Result { - let socket = nix::sys::socket::socket( - AddressFamily::Inet, - SockType::Datagram, - SockFlag::SOCK_CLOEXEC, - None, - )?; + let UdpSocket(socket) = UdpSocket::ipv4()?; nix::sys::socket::connect(socket.as_raw_fd(), &SockaddrIn::from(peer))?; Ok(FileDescriptor::from_owned(socket)) }