mirror of
https://github.com/xvxx/phetch
synced 2024-11-12 13:10:40 +00:00
try to connect to socket_addrs(), not just 1st
This commit is contained in:
parent
c574844e62
commit
015c7878cc
@ -209,10 +209,10 @@ pub fn request(host: &str, port: &str, selector: &str, tls: bool, tor: bool) ->
|
||||
}
|
||||
|
||||
// no tls or tor, try regular connection
|
||||
let sock = addr
|
||||
.to_socket_addrs()
|
||||
.and_then(|mut socks| socks.next().ok_or_else(|| error!("Can't create socket")))?;
|
||||
let mut stream = TcpStream::connect_timeout(&sock, TCP_TIMEOUT_DURATION)?;
|
||||
let mut stream = addr
|
||||
.to_socket_addrs()?
|
||||
.find_map(|s| TcpStream::connect_timeout(&s, TCP_TIMEOUT_DURATION).ok())
|
||||
.ok_or_else(|| error!("Can't create socket"))?;
|
||||
stream.set_read_timeout(Some(TCP_TIMEOUT_DURATION))?;
|
||||
stream.write_all(selector.as_ref())?;
|
||||
stream.write_all("\r\n".as_ref())?;
|
||||
|
Loading…
Reference in New Issue
Block a user