aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--base/src/descriptor.rs18
-rw-r--r--base/src/lib.rs24
-rw-r--r--base/src/unix/mod.rs6
3 files changed, 26 insertions, 22 deletions
diff --git a/base/src/descriptor.rs b/base/src/descriptor.rs
index 2723d8e3e..0b840eae9 100644
--- a/base/src/descriptor.rs
+++ b/base/src/descriptor.rs
@@ -1,3 +1,7 @@
+// Copyright 2022 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
use crate::{PollToken, RawDescriptor};
use serde::{Deserialize, Serialize};
use std::{
@@ -24,6 +28,11 @@ pub trait AsRawDescriptor {
fn as_raw_descriptor(&self) -> RawDescriptor;
}
+/// A trait similar to `AsRawDescriptor` but supports an arbitrary number of descriptors.
+pub trait AsRawDescriptors {
+ fn as_raw_descriptors(&self) -> Vec<RawDescriptor>;
+}
+
pub trait FromRawDescriptor {
/// # Safety
/// Safe only if the caller ensures nothing has access to the descriptor after passing it to
@@ -37,6 +46,15 @@ impl AsRawDescriptor for SafeDescriptor {
}
}
+impl<T> AsRawDescriptors for T
+where
+ T: AsRawDescriptor,
+{
+ fn as_raw_descriptors(&self) -> Vec<RawDescriptor> {
+ vec![self.as_raw_descriptor()]
+ }
+}
+
impl IntoRawDescriptor for SafeDescriptor {
fn into_raw_descriptor(self) -> RawDescriptor {
let descriptor = self.descriptor;
diff --git a/base/src/lib.rs b/base/src/lib.rs
index 36472fc34..7de12306e 100644
--- a/base/src/lib.rs
+++ b/base/src/lib.rs
@@ -57,27 +57,7 @@ cfg_if::cfg_if! {
}
pub use crate::descriptor::{
- AsRawDescriptor, Descriptor, FromRawDescriptor, IntoRawDescriptor, SafeDescriptor,
+ AsRawDescriptor, AsRawDescriptors, Descriptor, FromRawDescriptor, IntoRawDescriptor,
+ SafeDescriptor,
};
pub use platform::*;
-
-/// Verifies that |raw_descriptor| is actually owned by this process and duplicates it
-/// to ensure that we have a unique handle to it.
-#[cfg(unix)]
-pub fn validate_raw_descriptor(raw_descriptor: RawDescriptor) -> Result<RawDescriptor> {
- validate_raw_fd(raw_descriptor)
-}
-
-/// A trait similar to `AsRawDescriptor` but supports an arbitrary number of descriptors.
-pub trait AsRawDescriptors {
- fn as_raw_descriptors(&self) -> Vec<RawDescriptor>;
-}
-
-impl<T> AsRawDescriptors for T
-where
- T: AsRawDescriptor,
-{
- fn as_raw_descriptors(&self) -> Vec<RawDescriptor> {
- vec![self.as_raw_descriptor()]
- }
-}
diff --git a/base/src/unix/mod.rs b/base/src/unix/mod.rs
index 7bac9b8f9..16576e0f0 100644
--- a/base/src/unix/mod.rs
+++ b/base/src/unix/mod.rs
@@ -484,6 +484,12 @@ impl Drop for UnlinkUnixListener {
}
}
+/// Verifies that |raw_descriptor| is actually owned by this process and duplicates it
+/// to ensure that we have a unique handle to it.
+pub fn validate_raw_descriptor(raw_descriptor: RawDescriptor) -> Result<RawDescriptor> {
+ validate_raw_fd(raw_descriptor)
+}
+
/// Verifies that |raw_fd| is actually owned by this process and duplicates it to ensure that
/// we have a unique handle to it.
pub fn validate_raw_fd(raw_fd: RawFd) -> Result<RawFd> {