base: upstream Tube cross platform support.
Upstreams support for Tubes on Windows, splitting Tube into platform
specific files. This contains several critical enhancements:
* POSIX Tubes support multi producer multi consumer configurations, but
Windows has remained strictly SPSC for each direction. Windows cannot
support MPMC, and that configuration is not really something we want
either. To address that, this CL introduces directional Tubes. A
SendTube is clonable, and a RecvTube is not, which gives us MPSC.
* This CL also fixes multiple interface conflicts that have developed
between Linux & Windows:
+ send wasn't async on the Linux AsyncTube.
+ send data wasn't passed as owned on the Linux AsyncTube.
+ Adds the 'static constraint for AsyncTube::send on POSIX. This is an
requirement on Windows.
+ Event::read_timeout doesn't need to take &mut self, and it wasn't
downstream. This CL switches to &self.
* Adds the missing notifier.rs file in base.
Note that this CL does not attempt to remove balloon's usage of
Tube::try_clone. That's a somewhat involved issue that should be tackled in
its own CL.
Test: tested downstream on Windows & Linux bots, upstream on Linux bots.
Bug: b:221484449
Change-Id: I288dbc1d1e42f8ce08258cdaaf85100ca93721ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3536897
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
diff --git a/base/src/unix/eventfd.rs b/base/src/unix/eventfd.rs
index c27e570..0dc861b 100644
--- a/base/src/unix/eventfd.rs
+++ b/base/src/unix/eventfd.rs
@@ -93,7 +93,7 @@
/// a timeout does not occur then the count is returned as a EventReadResult::Count(count),
/// and the count is reset to 0. If a timeout does occur then this function will return
/// EventReadResult::Timeout.
- pub fn read_timeout(&mut self, timeout: Duration) -> Result<EventReadResult> {
+ pub fn read_timeout(&self, timeout: Duration) -> Result<EventReadResult> {
let mut pfd = libc::pollfd {
fd: self.as_raw_descriptor(),
events: POLLIN,
@@ -218,7 +218,7 @@
#[test]
fn timeout() {
- let mut evt = EventFd::new().expect("failed to create eventfd");
+ let evt = EventFd::new().expect("failed to create eventfd");
assert_eq!(
evt.read_timeout(Duration::from_millis(1))
.expect("failed to read from eventfd with timeout"),