mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-06-17 02:18:21 +02:00
util: rust: Add a way to create a Tube from an existing OwnedFd
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
4f13941e44
commit
10620bdf21
3 changed files with 29 additions and 0 deletions
|
|
@ -19,6 +19,7 @@ use rustix::net::listen;
|
|||
use rustix::net::recvmsg;
|
||||
use rustix::net::sendmsg;
|
||||
use rustix::net::socket_with;
|
||||
use rustix::net::sockopt::socket_type;
|
||||
use rustix::net::AddressFamily;
|
||||
use rustix::net::RecvAncillaryBuffer;
|
||||
use rustix::net::RecvAncillaryMessage;
|
||||
|
|
@ -43,6 +44,18 @@ pub struct Tube {
|
|||
socket: OwnedDescriptor,
|
||||
}
|
||||
|
||||
impl TryFrom<OwnedDescriptor> for Tube {
|
||||
type Error = MesaError;
|
||||
|
||||
fn try_from(socket: OwnedDescriptor) -> Result<Self, Self::Error> {
|
||||
let ty = socket_type(&socket)?;
|
||||
match ty {
|
||||
SocketType::SEQPACKET | SocketType::STREAM => Ok(Tube { socket }),
|
||||
_ => Err(MesaError::Unsupported),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<SocketType> for TubeType {
|
||||
type Error = std::io::Error;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,14 @@ use crate::TubeType;
|
|||
pub struct Tube;
|
||||
pub struct Listener;
|
||||
|
||||
impl TryFrom<OwnedDescriptor> for Tube {
|
||||
type Error = MesaError;
|
||||
|
||||
fn try_from(_socket: OwnedDescriptor) -> Result<Self, Self::Error> {
|
||||
Err(MesaError::Unsupported)
|
||||
}
|
||||
}
|
||||
|
||||
impl Tube {
|
||||
pub fn new<P: AsRef<Path>>(_path: P, _kind: TubeType) -> MesaResult<Tube> {
|
||||
Err(MesaError::Unsupported)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,14 @@ use crate::TubeType;
|
|||
pub struct Tube;
|
||||
pub struct Listener;
|
||||
|
||||
impl TryFrom<OwnedDescriptor> for Tube {
|
||||
type Error = MesaError;
|
||||
|
||||
fn try_from(_socket: OwnedDescriptor) -> Result<Self, Self::Error> {
|
||||
Err(MesaError::Unsupported)
|
||||
}
|
||||
}
|
||||
|
||||
impl Tube {
|
||||
pub fn new<P: AsRef<Path>>(_path: P, _kind: TubeType) -> MesaResult<Tube> {
|
||||
Err(MesaError::Unsupported)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue