Skip to content

Commit

Permalink
Auto merge of #3366 - vita-rust:nonblock, r=JohnTitor
Browse files Browse the repository at this point in the history
Added socketpair and pipe2 for Vita target

As an effort to port `tokio` to Vita, `socketpair` and `pipe2` calls were implemented in Vita newlib.

A PR to newlib with these methods while limitations/implementation details are discussed (vitasdk/newlib/pull/101), but until it is merged there is [vita-newlib-shims](https://crates.io/crates/vita-newlib-shims) crate with these methods implemented.

The implementation may change but methods will certainly remain, and the interface will remain POSIX.

`socketpair` will be needed for `rust-lang/rust` std, `rust-lang/socket2`, `rust-lang/mio`.
`pipe2` will be required for `mio` pipe-based Waker.
  • Loading branch information
bors committed Sep 29, 2023
2 parents 91b54d7 + b106649 commit 5d5a855
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
29 changes: 11 additions & 18 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,17 @@ extern "C" {
value: *const ::c_void,
option_len: socklen_t,
) -> ::c_int;
#[cfg_attr(
all(target_os = "macos", target_arch = "x86"),
link_name = "socketpair$UNIX2003"
)]
#[cfg_attr(target_os = "illumos", link_name = "__xnet_socketpair")]
pub fn socketpair(
domain: ::c_int,
type_: ::c_int,
protocol: ::c_int,
socket_vector: *mut ::c_int,
) -> ::c_int;
#[cfg(not(all(
libc_cfg_target_vendor,
target_arch = "powerpc",
Expand Down Expand Up @@ -1402,24 +1413,6 @@ extern "C" {

}

cfg_if! {
if #[cfg(not(target_os = "vita"))] {
extern "C" {
#[cfg_attr(
all(target_os = "macos", target_arch = "x86"),
link_name = "socketpair$UNIX2003"
)]
#[cfg_attr(target_os = "illumos", link_name = "__xnet_socketpair")]
pub fn socketpair(
domain: ::c_int,
type_: ::c_int,
protocol: ::c_int,
socket_vector: *mut ::c_int,
) -> ::c_int;
}
}
}

cfg_if! {
if #[cfg(not(any(target_os = "emscripten",
target_os = "android",
Expand Down
2 changes: 2 additions & 0 deletions src/unix/newlib/vita/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,6 @@ extern "C" {
pub fn pthread_getprocessorid_np() -> ::c_int;

pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int;

pub fn pipe2(fds: *mut ::c_int, flags: ::c_int) -> ::c_int;
}

0 comments on commit 5d5a855

Please sign in to comment.