base: Upstream unix net set_nonblocking fn

Bug: b:231641496
Upstream-Crate: base/src/sys/unix
Change-Id: I62b07f2fc3f7a02c1b72da735ac41d6dc73416f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3708762
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Clarissa Garvey <clarissagarvey@chromium.org>
This commit is contained in:
Clarissa Garvey 2022-06-16 20:09:33 +00:00 committed by Chromeos LUCI
parent ac1b5734be
commit 21445b1b83
2 changed files with 16 additions and 0 deletions

View file

@ -27,6 +27,9 @@ tempfile = "3"
thiserror = "1.0.20" thiserror = "1.0.20"
uuid = { version = "0.8.2", features = ["v4"] } uuid = { version = "0.8.2", features = ["v4"] }
[target.'cfg(unix)'.dependencies]
cvt = "*"
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
lazy_static = "*" lazy_static = "*"
rand = "*" rand = "*"

View file

@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
use cvt::cvt;
use std::{ use std::{
cmp::Ordering, cmp::Ordering,
convert::TryFrom, convert::TryFrom,
@ -594,6 +595,12 @@ impl UnixSeqpacket {
pub fn set_write_timeout(&self, timeout: Option<Duration>) -> io::Result<()> { pub fn set_write_timeout(&self, timeout: Option<Duration>) -> io::Result<()> {
self.set_timeout(timeout, libc::SO_SNDTIMEO) self.set_timeout(timeout, libc::SO_SNDTIMEO)
} }
/// Sets the blocking mode for this socket.
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
let mut nonblocking = nonblocking as libc::c_int;
cvt(unsafe { libc::ioctl(self.fd, libc::FIONBIO, &mut nonblocking) }).map(drop)
}
} }
impl Drop for UnixSeqpacket { impl Drop for UnixSeqpacket {
@ -787,6 +794,12 @@ impl UnixSeqpacketListener {
); );
Ok(path_os_str.into()) Ok(path_os_str.into())
} }
/// Sets the blocking mode for this socket.
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
let mut nonblocking = nonblocking as libc::c_int;
cvt(unsafe { libc::ioctl(self.fd, libc::FIONBIO, &mut nonblocking) }).map(drop)
}
} }
impl Drop for UnixSeqpacketListener { impl Drop for UnixSeqpacketListener {