Rollup merge of #36754 - tmiasko:getaddrinfo-errors, r=alexcrichton

When getaddrinfo returns EAI_SYSTEM retrieve actual error from errno.

Fixes issue #36546. This change also updates libc to earliest version
that includes EAI_SYSTEM constant.

Previously, in cases where `EAI_SYSTEM` has been returned from getaddrinfo, the
resulting `io::Error` would be broadly described as "System error":

    Error { repr: Custom(Custom { kind: Other, error: StringError("failed to lookup address information: System error") }) }

After change a more detailed error is crated based on particular value of
errno, for example:

    Error { repr: Os { code: 64, message: "Machine is not on the network" } }

The only downside is that the prefix "failed to lookup address information" is
no longer included in the error message.
This commit is contained in:
Jonathan Turner 2016-09-26 17:29:49 -07:00 committed by GitHub
commit 5c9fc99520
2 changed files with 8 additions and 3 deletions

@ -1 +1 @@
Subproject commit d4f6a19c55a03e3f9f6fb7377911b37ed807eb6c
Subproject commit eb708c020826a8d792a5a5275be147aabe47fe24

View File

@ -10,7 +10,7 @@
use ffi::CStr;
use io;
use libc::{self, c_int, size_t, sockaddr, socklen_t};
use libc::{self, c_int, size_t, sockaddr, socklen_t, EAI_SYSTEM};
use net::{SocketAddr, Shutdown};
use str;
use sys::fd::FileDesc;
@ -38,7 +38,12 @@
pub fn init() {}
pub fn cvt_gai(err: c_int) -> io::Result<()> {
if err == 0 { return Ok(()) }
if err == 0 {
return Ok(())
}
if err == EAI_SYSTEM {
return Err(io::Error::last_os_error())
}
let detail = unsafe {
str::from_utf8(CStr::from_ptr(libc::gai_strerror(err)).to_bytes()).unwrap()