#[cfg(target_os = "fuchsia")]
pub use fuchsia_handles::*;
#[cfg(not(target_os = "fuchsia"))]
pub use non_fuchsia_handles::*;
pub use fuchsia_async::{Channel as AsyncChannel, OnSignalsRef, Socket as AsyncSocket};
#[cfg(target_os = "fuchsia")]
pub mod fuchsia_handles {
pub use zx::{
AsHandleRef, Handle, HandleBased, HandleDisposition, HandleInfo, HandleOp, HandleRef,
MessageBufEtc, ObjectType, Peered, Rights, Signals, Status,
};
pub use fuchsia_async::invoke_for_handle_types;
macro_rules! fuchsia_handle {
($x:tt, $docname:expr, $name:ident, $zx_name:ident, Stub) => {
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(transparent)]
pub struct $x(zx::Handle);
impl zx::AsHandleRef for $x {
fn as_handle_ref(&self) -> HandleRef<'_> {
self.0.as_handle_ref()
}
}
impl From<Handle> for $x {
fn from(handle: Handle) -> Self {
$x(handle)
}
}
impl From<$x> for Handle {
fn from(x: $x) -> Handle {
x.0
}
}
impl zx::HandleBased for $x {}
};
($x:tt, $docname:expr, $name:ident, $value:expr, $availability:tt) => {
pub use zx::$x;
};
}
invoke_for_handle_types!(fuchsia_handle);
pub use zx::SocketOpts;
}
#[cfg(not(target_os = "fuchsia"))]
pub mod non_fuchsia_handles {
pub use fuchsia_async::emulated_handle::{
AsHandleRef, EmulatedHandleRef, Handle, HandleBased, HandleDisposition, HandleInfo,
HandleOp, HandleRef, MessageBufEtc, ObjectType, Peered, Rights, Signals, SocketOpts,
};
pub use zx_status::Status;
pub use fuchsia_async::invoke_for_handle_types;
macro_rules! declare_unsupported_fidl_handle {
($name:ident) => {
#[derive(PartialEq, Eq, Debug, PartialOrd, Ord, Hash)]
pub struct $name;
impl From<$crate::handle::Handle> for $name {
fn from(_: $crate::handle::Handle) -> $name {
$name
}
}
impl From<$name> for Handle {
fn from(_: $name) -> $crate::handle::Handle {
$crate::handle::Handle::invalid()
}
}
impl HandleBased for $name {}
impl AsHandleRef for $name {
fn as_handle_ref(&self) -> HandleRef<'_> {
HandleRef::invalid()
}
}
};
}
macro_rules! declare_fidl_handle {
($name:ident) => {
pub use fuchsia_async::emulated_handle::$name;
};
}
macro_rules! host_handle {
($x:tt, $docname:expr, $name:ident, $zx_name:ident, Everywhere) => {
declare_fidl_handle! {$x}
};
($x:tt, $docname:expr, $name:ident, $zx_name:ident, $availability:ident) => {
declare_unsupported_fidl_handle! {$x}
};
}
invoke_for_handle_types!(host_handle);
}
#[allow(clippy::too_long_first_doc_paragraph)]
pub fn convert_handle_dispositions_to_infos(
handle_dispositions: Vec<HandleDisposition<'_>>,
) -> crate::Result<Vec<HandleInfo>> {
handle_dispositions
.into_iter()
.map(|mut hd| {
Ok(HandleInfo::new(
match hd.take_op() {
HandleOp::Move(h) if hd.rights == Rights::SAME_RIGHTS => h,
HandleOp::Move(h) => {
h.replace(hd.rights).map_err(crate::Error::HandleReplace)?
}
HandleOp::Duplicate(_) => panic!("unexpected HandleOp::Duplicate"),
},
hd.object_type,
hd.rights,
))
})
.collect()
}