mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-06-11 16:18:18 +02:00
util: rust: Support detecting socket file descriptors
Useful for Pipewire passthrough. Signed-off-by: Val Packett <val@invisiblethingslab.com> Signed-off-by: Gurchetan Singh <gurchetan.singh.foss@gmail.com> Reviewed-by: David Gilhooley <djgilhooley@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41754>
This commit is contained in:
parent
118e48402c
commit
4f13941e44
4 changed files with 38 additions and 1 deletions
|
|
@ -88,6 +88,7 @@ pub enum DescriptorType {
|
|||
Memory(u32, u32), // (size, handle_type)
|
||||
WritePipe,
|
||||
Event,
|
||||
Socket(TubeType),
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
# Copyright © 2024 Google
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
dep_log = dependency('log',
|
||||
version: '>= 0.4.22',
|
||||
fallback: ['log-0.4-rs', 'dep_log'],
|
||||
required: true,
|
||||
)
|
||||
|
||||
dep_cfg_if = dependency('cfg-if',
|
||||
version: '>= 1.0.0',
|
||||
fallback: ['cfg-if-1-rs', 'dep_cfg_if'],
|
||||
|
|
@ -25,7 +31,8 @@ dep_zerocopy = dependency('zerocopy',
|
|||
required: true,
|
||||
)
|
||||
|
||||
dep_mesa3d_util = [dep_cfg_if, dep_thiserror, dep_remain, dep_zerocopy]
|
||||
dep_mesa3d_util = [dep_cfg_if, dep_thiserror, dep_remain, dep_zerocopy,
|
||||
dep_log]
|
||||
|
||||
supported_systems = ['linux', 'windows', 'darwin', 'macos']
|
||||
supported_host_machine = host_machine.system() in supported_systems
|
||||
|
|
|
|||
|
|
@ -16,11 +16,14 @@ use std::os::unix::io::RawFd;
|
|||
|
||||
use rustix::fs::fcntl_get_seals;
|
||||
use rustix::fs::fcntl_getfl;
|
||||
use rustix::fs::fstat;
|
||||
use rustix::fs::seek;
|
||||
use rustix::fs::FileType;
|
||||
use rustix::fs::OFlags;
|
||||
use rustix::fs::SealFlags;
|
||||
use rustix::fs::SeekFrom;
|
||||
use rustix::io::Errno;
|
||||
use rustix::net::sockopt::socket_type;
|
||||
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
|
|
@ -55,6 +58,15 @@ impl OwnedDescriptor {
|
|||
}
|
||||
}
|
||||
|
||||
if let Ok(fd_stat) = fstat(&self.owned) {
|
||||
let fd_type = FileType::from_raw_mode(fd_stat.st_mode);
|
||||
if fd_type == FileType::Socket {
|
||||
return Ok(DescriptorType::Socket(
|
||||
socket_type(&self.owned)?.try_into()?,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
match seek(&self.owned, SeekFrom::End(0)) {
|
||||
Ok(seek_size) => {
|
||||
let size: u32 = seek_size
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
// Copyright 2025 Google
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use std::io::Error;
|
||||
use std::io::ErrorKind;
|
||||
use std::io::IoSlice;
|
||||
use std::io::IoSliceMut;
|
||||
use std::mem::MaybeUninit;
|
||||
|
|
@ -41,6 +43,21 @@ pub struct Tube {
|
|||
socket: OwnedDescriptor,
|
||||
}
|
||||
|
||||
impl TryFrom<SocketType> for TubeType {
|
||||
type Error = std::io::Error;
|
||||
|
||||
fn try_from(ty: SocketType) -> Result<Self, Self::Error> {
|
||||
match ty {
|
||||
SocketType::SEQPACKET => Ok(TubeType::Packet),
|
||||
SocketType::STREAM => Ok(TubeType::Stream),
|
||||
ty => {
|
||||
log::warn!("Unsupported socket type {ty:?}");
|
||||
Err(Error::from(ErrorKind::Unsupported))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Tube {
|
||||
pub fn new<P: AsRef<Path> + Arg>(path: P, kind: TubeType) -> MesaResult<Tube> {
|
||||
let socket = match kind {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue