Skip to content

Address name resolver blocks the UI #3

@osa1

Description

@osa1

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions