about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorJonathan Turner <jonathandturner@users.noreply.github.com>2016-09-26 17:29:49 -0700
committerGitHub <noreply@github.com>2016-09-26 17:29:49 -0700
commit5c9fc995201420a97db119fa19c8e8d3000dbefa (patch)
tree4bbd170aff91d8537f41fa08eeaae8f47bf4609e /src/libstd/sys
parent816f1477bbcf591c0cce20f92824606412ed3c5b (diff)
parentc52b957b897a049cfe5f7042eed08fb46ca11c2e (diff)
downloadrust-5c9fc995201420a97db119fa19c8e8d3000dbefa.tar.gz
rust-5c9fc995201420a97db119fa19c8e8d3000dbefa.zip
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.
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/unix/net.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs
index f124ea651ec..ec7ccdf5894 100644
--- a/src/libstd/sys/unix/net.rs
+++ b/src/libstd/sys/unix/net.rs
@@ -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 struct Socket(FileDesc);
 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()