diff options
| author | bors <bors@rust-lang.org> | 2021-08-31 16:47:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-08-31 16:47:06 +0000 |
| commit | 0a84708edca7c275cb99ad080317fbc7637516d8 (patch) | |
| tree | e2cc9552e3d5ae365f6c373b60e6f6d87080c1f4 /library/std/src/sys | |
| parent | 76d18cfb8945f824c8777e04981e930d2037954e (diff) | |
| parent | f5cf9678c23bea8a9a865f0ced879714ec107871 (diff) | |
| download | rust-0a84708edca7c275cb99ad080317fbc7637516d8.tar.gz rust-0a84708edca7c275cb99ad080317fbc7637516d8.zip | |
Auto merge of #88535 - m-ou-se:rollup-jeusxbo, r=m-ou-se
Rollup of 10 pull requests Successful merges: - #85017 (Add carrying_add, borrowing_sub, widening_mul, carrying_mul methods to integers) - #86362 (Avoid cloning LocalDecls) - #88391 (Fix json tuple struct enum variant ) - #88399 (Disallow the aapcs CC on Aarch64) - #88418 (Allow `~const` bounds on trait assoc functions) - #88445 (Clean up the lowering of AST items) - #88495 (Add `TcpStream::set_linger` and `TcpStream::linger`) - #88501 (Use right span in prelude collision suggestions with macros. ) - #88504 (Keep turbofish in prelude collision lint.) - #88524 (Remove unnecessary `mut` from udp doctests) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/sys')
| -rw-r--r-- | library/std/src/sys/hermit/net.rs | 8 | ||||
| -rw-r--r-- | library/std/src/sys/sgx/net.rs | 8 | ||||
| -rw-r--r-- | library/std/src/sys/unix/l4re.rs | 16 | ||||
| -rw-r--r-- | library/std/src/sys/unix/net.rs | 23 | ||||
| -rw-r--r-- | library/std/src/sys/unsupported/net.rs | 8 | ||||
| -rw-r--r-- | library/std/src/sys/wasi/net.rs | 8 | ||||
| -rw-r--r-- | library/std/src/sys/windows/c.rs | 8 | ||||
| -rw-r--r-- | library/std/src/sys/windows/net.rs | 17 |
8 files changed, 95 insertions, 1 deletions
diff --git a/library/std/src/sys/hermit/net.rs b/library/std/src/sys/hermit/net.rs index 3f0c99cf742..880ef678a4f 100644 --- a/library/std/src/sys/hermit/net.rs +++ b/library/std/src/sys/hermit/net.rs @@ -182,6 +182,14 @@ impl TcpStream { Ok(self.clone()) } + pub fn set_linger(&self, linger: Option<Duration>) -> io::Result<()> { + unsupported() + } + + pub fn linger(&self) -> io::Result<Option<Duration>> { + unsupported() + } + pub fn set_nodelay(&self, mode: bool) -> io::Result<()> { abi::tcpstream::set_nodelay(*self.0.as_inner(), mode) .map_err(|_| io::Error::new_const(ErrorKind::Uncategorized, &"set_nodelay failed")) diff --git a/library/std/src/sys/sgx/net.rs b/library/std/src/sys/sgx/net.rs index 3a69aa039ef..89c5af6124f 100644 --- a/library/std/src/sys/sgx/net.rs +++ b/library/std/src/sys/sgx/net.rs @@ -183,6 +183,14 @@ impl TcpStream { Ok(self.clone()) } + pub fn set_linger(&self, _: Option<Duration>) -> io::Result<()> { + sgx_ineffective(()) + } + + pub fn linger(&self) -> io::Result<Option<Duration>> { + sgx_ineffective(None) + } + pub fn set_nodelay(&self, _: bool) -> io::Result<()> { sgx_ineffective(()) } diff --git a/library/std/src/sys/unix/l4re.rs b/library/std/src/sys/unix/l4re.rs index 3cf637c8228..ba63b41534c 100644 --- a/library/std/src/sys/unix/l4re.rs +++ b/library/std/src/sys/unix/l4re.rs @@ -98,6 +98,14 @@ pub mod net { unimpl!(); } + pub fn set_linger(&self, _: Option<Duration>) -> io::Result<()> { + unimpl!(); + } + + pub fn linger(&self) -> io::Result<Option<Duration>> { + unimpl!(); + } + pub fn set_nodelay(&self, _: bool) -> io::Result<()> { unimpl!(); } @@ -214,6 +222,14 @@ pub mod net { unimpl!(); } + pub fn set_linger(&self, _: Option<Duration>) -> io::Result<()> { + unimpl!(); + } + + pub fn linger(&self) -> io::Result<Option<Duration>> { + unimpl!(); + } + pub fn set_nodelay(&self, _: bool) -> io::Result<()> { unimpl!(); } diff --git a/library/std/src/sys/unix/net.rs b/library/std/src/sys/unix/net.rs index c2f5da1dbbb..9ae6d12dcb9 100644 --- a/library/std/src/sys/unix/net.rs +++ b/library/std/src/sys/unix/net.rs @@ -12,6 +12,14 @@ use crate::time::{Duration, Instant}; use libc::{c_int, c_void, size_t, sockaddr, socklen_t, MSG_PEEK}; +cfg_if::cfg_if! { + if #[cfg(target_vendor = "apple")] { + use libc::SO_LINGER_SEC as SO_LINGER; + } else { + use libc::SO_LINGER; + } +} + pub use crate::sys::{cvt, cvt_r}; #[allow(unused_extern_crates)] @@ -376,6 +384,21 @@ impl Socket { Ok(()) } + pub fn set_linger(&self, linger: Option<Duration>) -> io::Result<()> { + let linger = libc::linger { + l_onoff: linger.is_some() as libc::c_int, + l_linger: linger.unwrap_or_default().as_secs() as libc::c_int, + }; + + setsockopt(self, libc::SOL_SOCKET, SO_LINGER, linger) + } + + pub fn linger(&self) -> io::Result<Option<Duration>> { + let val: libc::linger = getsockopt(self, libc::SOL_SOCKET, SO_LINGER)?; + + Ok((val.l_onoff != 0).then(|| Duration::from_secs(val.l_linger as u64))) + } + pub fn set_nodelay(&self, nodelay: bool) -> io::Result<()> { setsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY, nodelay as c_int) } diff --git a/library/std/src/sys/unsupported/net.rs b/library/std/src/sys/unsupported/net.rs index 96203c74b57..dbb6ce22c22 100644 --- a/library/std/src/sys/unsupported/net.rs +++ b/library/std/src/sys/unsupported/net.rs @@ -76,6 +76,14 @@ impl TcpStream { self.0 } + pub fn set_linger(&self, _: Option<Duration>) -> io::Result<()> { + self.0 + } + + pub fn linger(&self) -> io::Result<Option<Duration>> { + self.0 + } + pub fn set_nodelay(&self, _: bool) -> io::Result<()> { self.0 } diff --git a/library/std/src/sys/wasi/net.rs b/library/std/src/sys/wasi/net.rs index c7c4a9f6efd..a4dbb225376 100644 --- a/library/std/src/sys/wasi/net.rs +++ b/library/std/src/sys/wasi/net.rs @@ -127,6 +127,14 @@ impl TcpStream { unsupported() } + pub fn set_linger(&self, _: Option<Duration>) -> io::Result<()> { + unsupported() + } + + pub fn linger(&self) -> io::Result<Option<Duration>> { + unsupported() + } + pub fn set_nodelay(&self, _: bool) -> io::Result<()> { unsupported() } diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index 63f9be7b7e3..cedf389fbf5 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -197,6 +197,7 @@ pub const SOCK_DGRAM: c_int = 2; pub const SOCK_STREAM: c_int = 1; pub const SOCKET_ERROR: c_int = -1; pub const SOL_SOCKET: c_int = 0xffff; +pub const SO_LINGER: c_int = 0x0080; pub const SO_RCVTIMEO: c_int = 0x1006; pub const SO_SNDTIMEO: c_int = 0x1005; pub const IPPROTO_IP: c_int = 0; @@ -217,6 +218,13 @@ pub const IPV6_DROP_MEMBERSHIP: c_int = 13; pub const MSG_PEEK: c_int = 0x2; #[repr(C)] +#[derive(Copy, Clone)] +pub struct linger { + pub l_onoff: c_ushort, + pub l_linger: c_ushort, +} + +#[repr(C)] pub struct ip_mreq { pub imr_multiaddr: in_addr, pub imr_interface: in_addr, diff --git a/library/std/src/sys/windows/net.rs b/library/std/src/sys/windows/net.rs index 55aacb38c6f..33152cc97ab 100644 --- a/library/std/src/sys/windows/net.rs +++ b/library/std/src/sys/windows/net.rs @@ -15,7 +15,7 @@ use crate::sys_common::net; use crate::sys_common::{AsInner, FromInner, IntoInner}; use crate::time::Duration; -use libc::{c_int, c_long, c_ulong}; +use libc::{c_int, c_long, c_ulong, c_ushort}; pub type wrlen_t = i32; @@ -446,6 +446,21 @@ impl Socket { cvt(result).map(drop) } + pub fn set_linger(&self, linger: Option<Duration>) -> io::Result<()> { + let linger = c::linger { + l_onoff: linger.is_some() as c_ushort, + l_linger: linger.unwrap_or_default().as_secs() as c_ushort, + }; + + net::setsockopt(self, c::SOL_SOCKET, c::SO_LINGER, linger) + } + + pub fn linger(&self) -> io::Result<Option<Duration>> { + let val: c::linger = net::getsockopt(self, c::SOL_SOCKET, c::SO_LINGER)?; + + Ok((val.l_onoff != 0).then(|| Duration::from_secs(val.l_linger as u64))) + } + pub fn set_nodelay(&self, nodelay: bool) -> io::Result<()> { net::setsockopt(self, c::IPPROTO_TCP, c::TCP_NODELAY, nodelay as c::BYTE) } |
