Merge pull request #90 from jadireddi/Smol_60_socket_conn_err_enhance

Enhance tcp socket conn error message.
This commit is contained in:
Stjepan Glavina 2020-05-07 07:31:26 -07:00 committed by GitHub
commit f5224470f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 1 deletions

View File

@ -27,6 +27,9 @@ use socket2::{Domain, Protocol, Socket, Type};
use crate::reactor::{Reactor, Source};
use crate::task::Task;
#[cfg(unix)]
use nix::libc;
/// Async I/O.
///
/// This type converts a blocking I/O type into an async type, provided it is supported by
@ -551,7 +554,19 @@ impl Async<TcpStream> {
// Begin async connect and ignore the inevitable "not yet connected" error.
socket.set_nonblocking(true)?;
let _ = socket.connect(&addr.into());
socket.connect(&addr.into()).or_else(|err| {
//Ignore error EINPROGRESS on Unix or WSAEWOULDBLOCK on windows, as it means connection in progress.
#[cfg(unix)]
let conn_in_prog_err = err.raw_os_error() == Some(libc::EINPROGRESS);
#[cfg(windows)]
let conn_in_prog_err = err.kind() == io::ErrorKind::WouldBlock;
if conn_in_prog_err {
Ok(())
} else {
Err(err)
}
})?;
let stream = Async::new(socket.into_tcp_stream())?;
// Wait for connect to complete.