X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibstd%2Fsys%2Fvxworks%2Fnet.rs;h=85f5fcff2c259e3dd9c60d58e4761f53dc453b25;hb=c34fbfaad38cf5829ef5cfe780dc9d58480adeaa;hp=56962e11dcf95a4c646e13827f6732bf1c86b0de;hpb=88629778e6faeda18409ffaa9a00291e3605bae3;p=rust.git diff --git a/src/libstd/sys/vxworks/net.rs b/src/libstd/sys/vxworks/net.rs index 56962e11dcf..85f5fcff2c2 100644 --- a/src/libstd/sys/vxworks/net.rs +++ b/src/libstd/sys/vxworks/net.rs @@ -1,15 +1,15 @@ +use crate::cmp; use crate::ffi::CStr; use crate::io; use crate::io::{IoSlice, IoSliceMut}; -use libc::{self, c_int, c_void, size_t, sockaddr, socklen_t, EAI_SYSTEM, MSG_PEEK}; use crate::mem; -use crate::net::{SocketAddr, Shutdown}; +use crate::net::{Shutdown, SocketAddr}; use crate::str; use crate::sys::fd::FileDesc; -use crate::sys_common::{AsInner, FromInner, IntoInner}; use crate::sys_common::net::{getsockopt, setsockopt, sockaddr_to_addr}; +use crate::sys_common::{AsInner, FromInner, IntoInner}; use crate::time::{Duration, Instant}; -use crate::cmp; +use libc::{self, c_int, c_void, size_t, sockaddr, socklen_t, EAI_SYSTEM, MSG_PEEK}; pub use crate::sys::{cvt, cvt_r}; @@ -18,7 +18,6 @@ pub type wrlen_t = size_t; - const SOCK_CLOEXEC: c_int = 0; const SO_NOSIGPIPE: c_int = 0; @@ -28,23 +27,23 @@ pub fn init() {} pub fn cvt_gai(err: c_int) -> io::Result<()> { if err == 0 { - return Ok(()) + return Ok(()); } // We may need to trigger a glibc workaround. See on_resolver_failure() for details. on_resolver_failure(); if err == EAI_SYSTEM { - return Err(io::Error::last_os_error()) + return Err(io::Error::last_os_error()); } let detail = unsafe { - str::from_utf8(CStr::from_ptr(libc::gai_strerror(err)).to_bytes()).unwrap() - .to_owned() + str::from_utf8(CStr::from_ptr(libc::gai_strerror(err)).to_bytes()).unwrap().to_owned() }; - Err(io::Error::new(io::ErrorKind::Other, - &format!("failed to lookup address information: {}", - detail)[..])) + Err(io::Error::new( + io::ErrorKind::Other, + &format!("failed to lookup address information: {}", detail)[..], + )) } impl Socket { @@ -67,7 +66,7 @@ pub fn new_raw(fam: c_int, ty: c_int) -> io::Result { } pub fn new_pair(_fam: c_int, _ty: c_int) -> io::Result<(Socket, Socket)> { - unimplemented!(); + unimplemented!(); } pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> { @@ -85,15 +84,13 @@ pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Resul Err(e) => return Err(e), } - let mut pollfd = libc::pollfd { - fd: self.0.raw(), - events: libc::POLLOUT, - revents: 0, - }; + let mut pollfd = libc::pollfd { fd: self.0.raw(), events: libc::POLLOUT, revents: 0 }; if timeout.as_secs() == 0 && timeout.subsec_nanos() == 0 { - return Err(io::Error::new(io::ErrorKind::InvalidInput, - "cannot set a 0 duration timeout")); + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + "cannot set a 0 duration timeout", + )); } let start = Instant::now(); @@ -105,7 +102,8 @@ pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Resul } let timeout = timeout - elapsed; - let mut timeout = timeout.as_secs() + let mut timeout = timeout + .as_secs() .saturating_mul(1_000) .saturating_add(timeout.subsec_nanos() as u64 / 1_000_000); if timeout == 0 { @@ -126,10 +124,9 @@ pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Resul // linux returns POLLOUT|POLLERR|POLLHUP for refused connections (!), so look // for POLLHUP rather than read readiness if pollfd.revents & libc::POLLHUP != 0 { - let e = self.take_error()? - .unwrap_or_else(|| { - io::Error::new(io::ErrorKind::Other, "no error set after POLLHUP") - }); + let e = self.take_error()?.unwrap_or_else(|| { + io::Error::new(io::ErrorKind::Other, "no error set after POLLHUP") + }); return Err(e); } @@ -139,11 +136,8 @@ pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Resul } } - pub fn accept(&self, storage: *mut sockaddr, len: *mut socklen_t) - -> io::Result { - let fd = cvt_r(|| unsafe { - libc::accept(self.0.raw(), storage, len) - })?; + pub fn accept(&self, storage: *mut sockaddr, len: *mut socklen_t) -> io::Result { + let fd = cvt_r(|| unsafe { libc::accept(self.0.raw(), storage, len) })?; let fd = FileDesc::new(fd); fd.set_cloexec()?; Ok(Socket(fd)) @@ -155,10 +149,7 @@ pub fn duplicate(&self) -> io::Result { fn recv_with_flags(&self, buf: &mut [u8], flags: c_int) -> io::Result { let ret = cvt(unsafe { - libc::recv(self.0.raw(), - buf.as_mut_ptr() as *mut c_void, - buf.len(), - flags) + libc::recv(self.0.raw(), buf.as_mut_ptr() as *mut c_void, buf.len(), flags) })?; Ok(ret as usize) } @@ -175,18 +166,23 @@ pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.0.read_vectored(bufs) } - fn recv_from_with_flags(&self, buf: &mut [u8], flags: c_int) - -> io::Result<(usize, SocketAddr)> { + fn recv_from_with_flags( + &self, + buf: &mut [u8], + flags: c_int, + ) -> io::Result<(usize, SocketAddr)> { let mut storage: libc::sockaddr_storage = unsafe { mem::zeroed() }; let mut addrlen = mem::size_of_val(&storage) as libc::socklen_t; let n = cvt(unsafe { - libc::recvfrom(self.0.raw(), - buf.as_mut_ptr() as *mut c_void, - buf.len(), - flags, - &mut storage as *mut _ as *mut _, - &mut addrlen) + libc::recvfrom( + self.0.raw(), + buf.as_mut_ptr() as *mut c_void, + buf.len(), + flags, + &mut storage as *mut _ as *mut _, + &mut addrlen, + ) })?; Ok((n as usize, sockaddr_to_addr(&storage, addrlen as usize)?)) } @@ -211,8 +207,10 @@ pub fn set_timeout(&self, dur: Option, kind: libc::c_int) -> io::Resul let timeout = match dur { Some(dur) => { if dur.as_secs() == 0 && dur.subsec_nanos() == 0 { - return Err(io::Error::new(io::ErrorKind::InvalidInput, - "cannot set a 0 duration timeout")); + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + "cannot set a 0 duration timeout", + )); } let secs = if dur.as_secs() > libc::time_t::max_value() as u64 { @@ -229,12 +227,7 @@ pub fn set_timeout(&self, dur: Option, kind: libc::c_int) -> io::Resul } timeout } - None => { - libc::timeval { - tv_sec: 0, - tv_usec: 0, - } - } + None => libc::timeval { tv_sec: 0, tv_usec: 0 }, }; setsockopt(self, libc::SOL_SOCKET, kind, timeout) } @@ -276,24 +269,26 @@ pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { pub fn take_error(&self) -> io::Result> { let raw: c_int = getsockopt(self, libc::SOL_SOCKET, libc::SO_ERROR)?; - if raw == 0 { - Ok(None) - } else { - Ok(Some(io::Error::from_raw_os_error(raw as i32))) - } + if raw == 0 { Ok(None) } else { Ok(Some(io::Error::from_raw_os_error(raw as i32))) } } } impl AsInner for Socket { - fn as_inner(&self) -> &c_int { self.0.as_inner() } + fn as_inner(&self) -> &c_int { + self.0.as_inner() + } } impl FromInner for Socket { - fn from_inner(fd: c_int) -> Socket { Socket(FileDesc::new(fd)) } + fn from_inner(fd: c_int) -> Socket { + Socket(FileDesc::new(fd)) + } } impl IntoInner for Socket { - fn into_inner(self) -> c_int { self.0.into_raw() } + fn into_inner(self) -> c_int { + self.0.into_raw() + } } // In versions of glibc prior to 2.26, there's a bug where the DNS resolver @@ -314,7 +309,7 @@ fn into_inner(self) -> c_int { self.0.into_raw() } // believe it's thread-safe). #[cfg(target_env = "gnu")] fn on_resolver_failure() { -/* + /* use crate::sys; // If the version fails to parse, we treat it the same as "not glibc".