diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-25 17:14:07 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-26 00:20:05 +0900 |
| commit | 0dd510dbc3a5b6e888abcc104ae8c4a4eeb1e42b (patch) | |
| tree | 8b6e7663c82bd7c4bbe91f4594940aa780376d77 /crates/shirabe-php-shim/src/lib.rs | |
| parent | 6c137a28151f5ef05c9e22d3232e9ba7b81f6abe (diff) | |
| download | php-shirabe-0dd510dbc3a5b6e888abcc104ae8c4a4eeb1e42b.tar.gz php-shirabe-0dd510dbc3a5b6e888abcc104ae8c4a4eeb1e42b.tar.zst php-shirabe-0dd510dbc3a5b6e888abcc104ae8c4a4eeb1e42b.zip | |
feat(shim): implement stream_select/stream_set_blocking via libc
Add fcntl/select extern "C" declarations and a PhpResource::raw_fd seam so the
symfony Process pipe loop can read a live child's stdout/stderr. Fix fread on a
non-blocking fd (WouldBlock -> "") and the Process null-cwd default. Real
subprocess output capture now works; un-ignore the process_executor tests.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-shim/src/lib.rs')
| -rw-r--r-- | crates/shirabe-php-shim/src/lib.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index 113c9d7..8c8073f 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -349,6 +349,32 @@ pub enum PhpResource { Process(std::rc::Rc<std::cell::RefCell<process::ProcessState>>), } +impl PhpResource { + /// Returns the underlying OS file descriptor backing this resource, when it has one. + /// Used by `stream_set_blocking`/`stream_select` to drive `fcntl(2)`/`select(2)`. In-memory + /// streams (`php://memory`/`php://temp`) and process handles have no fd and return `None`. + pub(crate) fn raw_fd(&self) -> Option<std::os::unix::io::RawFd> { + use std::os::unix::io::AsRawFd; + match self { + PhpResource::Stdin => Some(std::io::stdin().as_raw_fd()), + PhpResource::Stdout => Some(std::io::stdout().as_raw_fd()), + PhpResource::Stderr => Some(std::io::stderr().as_raw_fd()), + PhpResource::Process(_) => None, + PhpResource::Stream(state) => { + let state = state.borrow(); + if state.closed { + return None; + } + match &state.backing { + StreamBacking::File(f) => Some(f.as_raw_fd()), + StreamBacking::Pipe(p) => Some(p.as_raw_fd()), + StreamBacking::Memory(_) => None, + } + } + } + } +} + /// Combined capability of every seekable byte stream backing. Both `std::fs::File` /// and `std::io::Cursor<Vec<u8>>` satisfy it, so a stream can be driven uniformly. pub trait ReadWriteSeek: std::io::Read + std::io::Write + std::io::Seek {} @@ -420,6 +446,16 @@ impl std::io::Seek for ChildPipe { } } +impl std::os::unix::io::AsRawFd for ChildPipe { + fn as_raw_fd(&self) -> std::os::unix::io::RawFd { + match self { + ChildPipe::In(i) => i.as_raw_fd(), + ChildPipe::Out(o) => o.as_raw_fd(), + ChildPipe::Err(e) => e.as_raw_fd(), + } + } +} + #[derive(Debug)] pub struct StreamState { pub(crate) backing: StreamBacking, |
