-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
Trying to recv()
on a UdpSocket
after a send()
to a closed UDP socket fails
I tried this code:
use std::net::UdpSocket;
fn main() {
let client = UdpSocket::bind("127.0.0.1:0").expect("failed to bind");
let server = UdpSocket::bind("127.0.0.1:8080").expect("failed to bind");
client.connect("127.0.0.1:1234").expect("connect function failed"); // no server at this address
client.send(&[0; 10]).expect("couldn't send data"); // no error at this point
let mut buf = [0; 10];
match client.recv(&mut buf) {
Ok(received) => println!("received {received} bytes {:?}", &buf[..received]),
Err(e) => println!("recv function failed: {e:?}"), // we get an error here
}
}
I expected to see this happen:
We should be able to recv()
without any error
Instead, this happened:
recv()
fails
Golang currently handles this using SIO_UDP_CONNRESET
here: https://github.com/golang/go/blob/e8c5bed7ea43e1a533c322e6b928ed06327721db/src/internal/poll/fd_windows.go#L340-L351
Meta
rustc --version --verbose
:
rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-pc-windows-msvc
release: 1.79.0
LLVM version: 18.1.7
Backtrace
recv function failed: Os { code: 10054, kind: ConnectionReset, message: "An existing connection was forcibly closed by the remote host." }
Metadata
Metadata
Assignees
Labels
C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.