-
Notifications
You must be signed in to change notification settings - Fork 70
Closed
Description
The code for initializing TcpStreams looks like this:
fn init_stream(serv_addr: &str, serv_port: u16) -> TcpStream {
let stream = TcpBuilder::new_v4().unwrap().to_tcp_stream().unwrap();
stream.set_nonblocking(true).unwrap();
// This will fail with EINPROGRESS
let _ = stream.connect((serv_addr, serv_port));
stream
}Here connect() first calls to_socket_addrs() which does address name resolving by calling getaddrinfo(), which in turn blocks the thread.
One alternative is to use getaddrinfo_a(), but I'm not sure how portable this would be.
Another alternative is to use futures to run getaddrinfo() and poll the results in tick handlers.
Metadata
Metadata
Assignees
Labels
No labels