fix os_pipe doesn't work with async IO

This commit is contained in:
ningmingxiao 2024-10-11 13:57:52 +08:00 committed by Maksym Pavlenko
parent 7794b07f16
commit a6b4286542
1 changed files with 10 additions and 5 deletions

View File

@ -19,16 +19,19 @@ use std::{
fmt::Debug, fmt::Debug,
fs::{File, OpenOptions}, fs::{File, OpenOptions},
io::Result, io::Result,
os::unix::{fs::OpenOptionsExt, io::AsRawFd}, os::unix::{
fs::OpenOptionsExt,
io::{AsRawFd, OwnedFd},
},
process::Stdio, process::Stdio,
sync::Mutex, sync::Mutex,
}; };
use log::debug; use log::debug;
use nix::unistd::{Gid, Uid}; use nix::unistd::{Gid, Uid};
use os_pipe::{PipeReader, PipeWriter};
#[cfg(feature = "async")] #[cfg(feature = "async")]
use tokio::io::{AsyncRead, AsyncWrite}; use tokio::io::{AsyncRead, AsyncWrite};
use tokio::net::unix::pipe;
use crate::Command; use crate::Command;
@ -100,8 +103,8 @@ impl Default for IOOption {
/// When one side of the pipe is closed, the state will be represented with [`None`]. /// When one side of the pipe is closed, the state will be represented with [`None`].
#[derive(Debug)] #[derive(Debug)]
pub struct Pipe { pub struct Pipe {
rd: PipeReader, rd: OwnedFd,
wr: PipeWriter, wr: OwnedFd,
} }
#[derive(Debug)] #[derive(Debug)]
@ -113,7 +116,9 @@ pub struct PipedIo {
impl Pipe { impl Pipe {
fn new() -> std::io::Result<Self> { fn new() -> std::io::Result<Self> {
let (rd, wr) = os_pipe::pipe()?; let (tx, rx) = pipe::pipe()?;
let rd = tx.into_blocking_fd()?;
let wr = rx.into_blocking_fd()?;
Ok(Self { rd, wr }) Ok(Self { rd, wr })
} }
} }