Fix blocking-mode tcp listener in auto-reload example (#2558)

This commit is contained in:
Jonas Platte 2024-01-31 15:55:42 +01:00 committed by GitHub
parent 530aa5530c
commit 5f7fcc5866
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,7 +16,10 @@ async fn main() {
let mut listenfd = ListenFd::from_env(); let mut listenfd = ListenFd::from_env();
let listener = match listenfd.take_tcp_listener(0).unwrap() { let listener = match listenfd.take_tcp_listener(0).unwrap() {
// if we are given a tcp listener on listen fd 0, we use that one // if we are given a tcp listener on listen fd 0, we use that one
Some(listener) => TcpListener::from_std(listener).unwrap(), Some(listener) => {
listener.set_nonblocking(true).unwrap();
TcpListener::from_std(listener).unwrap()
}
// otherwise fall back to local listening // otherwise fall back to local listening
None => TcpListener::bind("127.0.0.1:3000").await.unwrap(), None => TcpListener::bind("127.0.0.1:3000").await.unwrap(),
}; };