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:
commit
5c9fc99520
2 changed files with 8 additions and 3 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit d4f6a19c55a03e3f9f6fb7377911b37ed807eb6c
|
Subproject commit eb708c020826a8d792a5a5275be147aabe47fe24
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
use ffi::CStr;
|
use ffi::CStr;
|
||||||
use io;
|
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 net::{SocketAddr, Shutdown};
|
||||||
use str;
|
use str;
|
||||||
use sys::fd::FileDesc;
|
use sys::fd::FileDesc;
|
||||||
|
@ -38,7 +38,12 @@ pub struct Socket(FileDesc);
|
||||||
pub fn init() {}
|
pub fn init() {}
|
||||||
|
|
||||||
pub fn cvt_gai(err: c_int) -> io::Result<()> {
|
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 {
|
let detail = unsafe {
|
||||||
str::from_utf8(CStr::from_ptr(libc::gai_strerror(err)).to_bytes()).unwrap()
|
str::from_utf8(CStr::from_ptr(libc::gai_strerror(err)).to_bytes()).unwrap()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue