mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-05 18:20:34 +00:00
sys_util: impl From<UnixSeqpacket> for SafeDescriptor
BUG=b:177267762 TEST=run vk and gl apps on volteer Change-Id: Icfd3994ef62f0c27b817a3824da18977a943cc00 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3315233 Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chia-I Wu <olv@google.com>
This commit is contained in:
parent
64ba89ac84
commit
2bcec5c3d9
2 changed files with 17 additions and 2 deletions
|
@ -13,7 +13,7 @@ use std::os::unix::net::{UnixDatagram, UnixStream};
|
|||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::net::UnlinkUnixSeqpacketListener;
|
||||
use crate::net::{UnixSeqpacket, UnlinkUnixSeqpacketListener};
|
||||
use crate::{errno_result, PollToken, Result};
|
||||
|
||||
pub type RawDescriptor = RawFd;
|
||||
|
@ -168,6 +168,13 @@ impl From<SafeDescriptor> for UnixStream {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<UnixSeqpacket> for SafeDescriptor {
|
||||
fn from(s: UnixSeqpacket) -> Self {
|
||||
// Safe because we own the UnixSeqpacket at this point.
|
||||
unsafe { SafeDescriptor::from_raw_descriptor(s.into_raw_descriptor()) }
|
||||
}
|
||||
}
|
||||
|
||||
/// For use cases where a simple wrapper around a RawDescriptor is needed.
|
||||
/// This is a simply a wrapper and does not manage the lifetime of the descriptor.
|
||||
/// Most usages should prefer SafeDescriptor or using a RawDescriptor directly
|
||||
|
|
|
@ -27,7 +27,7 @@ use crate::{
|
|||
sock_ctrl_msg::{ScmSocket, SCM_SOCKET_MAX_FD_COUNT},
|
||||
FromRawDescriptor,
|
||||
};
|
||||
use crate::{AsRawDescriptor, RawDescriptor};
|
||||
use crate::{AsRawDescriptor, IntoRawDescriptor, RawDescriptor};
|
||||
|
||||
/// Assist in handling both IP version 4 and IP version 6.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
|
@ -614,6 +614,14 @@ impl FromRawDescriptor for UnixSeqpacket {
|
|||
}
|
||||
}
|
||||
|
||||
impl IntoRawDescriptor for UnixSeqpacket {
|
||||
fn into_raw_descriptor(self) -> RawDescriptor {
|
||||
let fd = self.fd;
|
||||
mem::forget(self);
|
||||
fd
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRawFd for UnixSeqpacket {
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
self.fd
|
||||
|
|
Loading…
Reference in a new issue