mirror of
https://github.com/danog/php-tokio.git
synced 2024-11-26 12:24:58 +01:00
Merge pull request #3 from yoramdelangen/feat/macos-libc-pipe
Added macos support for libc::pipe
This commit is contained in:
commit
3500684490
@ -1,8 +1,6 @@
|
||||
use crate::borrow_unchecked::borrow_unchecked;
|
||||
use ext_php_rs::{boxed::ZBox, call_user_func, prelude::*, types::ZendHashTable, zend::Function};
|
||||
use lazy_static::lazy_static;
|
||||
use ext_php_rs::{
|
||||
boxed::ZBox, call_user_func, prelude::*, types::ZendHashTable, zend::Function,
|
||||
};
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
fs::File,
|
||||
@ -31,6 +29,50 @@ fn sys_pipe() -> io::Result<(RawFd, RawFd)> {
|
||||
Ok((pipefd[0], pipefd[1]))
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "macos"))]
|
||||
fn set_cloexec(fd: RawFd) -> io::Result<()> {
|
||||
use libc::{F_SETFD, FD_CLOEXEC, F_GETFD};
|
||||
use libc::fcntl;
|
||||
|
||||
let flags = unsafe { fcntl(fd, F_GETFD, 0) };
|
||||
if flags == -1 {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
let ret = unsafe { fcntl(fd, F_SETFD, flags | FD_CLOEXEC) };
|
||||
if ret == -1 {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "macos"))]
|
||||
fn set_nonblocking(fd: RawFd) -> io::Result<()> {
|
||||
use libc::{fcntl, F_SETFL, O_NONBLOCK};
|
||||
|
||||
let ret = unsafe { fcntl(fd, F_SETFL, O_NONBLOCK) };
|
||||
if ret == -1 {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "macos"))]
|
||||
fn sys_pipe() -> io::Result<(RawFd, RawFd)> {
|
||||
let mut pipefd = [0; 2];
|
||||
let ret = unsafe { libc::pipe(pipefd.as_mut_ptr()) };
|
||||
|
||||
if ret == -1 {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
|
||||
for fd in &pipefd {
|
||||
set_cloexec(*fd)?;
|
||||
set_nonblocking(*fd)?;
|
||||
}
|
||||
Ok((pipefd[0], pipefd[1]))
|
||||
}
|
||||
|
||||
pub struct EventLoop {
|
||||
fibers: ZBox<ZendHashTable>,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user