Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for vita target #1721

Merged
merged 2 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ net = []
log = { version = "0.4.8", optional = true }

[target.'cfg(unix)'.dependencies]
libc = "0.2.121"
libc = "0.2.149"

[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.48"
Expand All @@ -60,7 +60,7 @@ features = [

[target.'cfg(target_os = "wasi")'.dependencies]
wasi = "0.11.0"
libc = "0.2.121"
libc = "0.2.149"

[dev-dependencies]
env_logger = { version = "0.9.3", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ This uses the Windows AFD system to access socket readiness events.

## Unsupported flags

Mio uses different implementations to support the same functionality dependening
Mio uses different implementations to support the same functionality depending
on the platform. Mio generally uses the "best" implementation possible, where
"best" usually means most efficient for Mio's use case. However this means that
the implementation is often specific to a limited number of platforms, meaning
we often have multiple implemetations for the same functionality. In some cases
we often have multiple implementations for the same functionality. In some cases
it might be required to not use the "best" implementation, but another
implementation Mio supports (on other platforms). **Mio does not officially
support secondary implementations on platforms**, however we do have various cfg
Expand Down
1 change: 1 addition & 0 deletions src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ cfg_os_poll! {
target_os = "netbsd",
target_os = "openbsd",
target_os = "redox",
target_os = "vita",
))]
pub(crate) mod pipe;
}
Expand Down
12 changes: 11 additions & 1 deletion src/sys/unix/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ pub(crate) fn new_socket(domain: libc::c_int, socket_type: libc::c_int) -> io::R
target_os = "tvos",
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
))]
{
if let Err(err) = syscall!(fcntl(socket, libc::F_SETFL, libc::O_NONBLOCK)) {
let _ = syscall!(close(socket));
return Err(err);
}
#[cfg(not(target_os = "espidf"))]
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
if let Err(err) = syscall!(fcntl(socket, libc::F_SETFD, libc::FD_CLOEXEC)) {
let _ = syscall!(close(socket));
return Err(err);
Expand Down Expand Up @@ -97,7 +98,10 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_
sin_family: libc::AF_INET as libc::sa_family_t,
sin_port: addr.port().to_be(),
sin_addr,
#[cfg(not(target_os = "vita"))]
sin_zero: [0; 8],
#[cfg(target_os = "vita")]
sin_zero: [0; 6],
#[cfg(any(
target_os = "aix",
target_os = "dragonfly",
Expand All @@ -109,8 +113,11 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_
target_os = "tvos",
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
))]
sin_len: 0,
#[cfg(target_os = "vita")]
sin_vport: addr.port().to_be(),
};

let sockaddr = SocketAddrCRepr { v4: sockaddr_in };
Expand All @@ -137,8 +144,11 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_
target_os = "tvos",
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
))]
sin6_len: 0,
#[cfg(target_os = "vita")]
sin6_vport: addr.port().to_be(),
#[cfg(target_os = "illumos")]
__sin6_src_id: 0,
};
Expand Down
6 changes: 4 additions & 2 deletions src/sys/unix/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub(crate) fn new_raw() -> io::Result<[RawFd; 2]> {
target_os = "openbsd",
target_os = "illumos",
target_os = "redox",
target_os = "vita",
))]
unsafe {
if libc::pipe2(fds.as_mut_ptr(), libc::O_CLOEXEC | libc::O_NONBLOCK) != 0 {
Expand Down Expand Up @@ -67,6 +68,7 @@ pub(crate) fn new_raw() -> io::Result<[RawFd; 2]> {
target_os = "tvos",
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
)))]
compile_error!("unsupported target for `mio::unix::pipe`");

Expand Down Expand Up @@ -556,7 +558,7 @@ impl IntoRawFd for Receiver {
}
}

#[cfg(not(target_os = "illumos"))]
#[cfg(not(any(target_os = "illumos", target_os = "vita")))]
fn set_nonblocking(fd: RawFd, nonblocking: bool) -> io::Result<()> {
let value = nonblocking as libc::c_int;
if unsafe { libc::ioctl(fd, libc::FIONBIO, &value) } == -1 {
Expand All @@ -566,7 +568,7 @@ fn set_nonblocking(fd: RawFd, nonblocking: bool) -> io::Result<()> {
}
}

#[cfg(target_os = "illumos")]
#[cfg(any(target_os = "illumos", target_os = "vita"))]
fn set_nonblocking(fd: RawFd, nonblocking: bool) -> io::Result<()> {
let flags = unsafe { libc::fcntl(fd, libc::F_GETFL) };
if flags < 0 {
Expand Down
9 changes: 7 additions & 2 deletions src/sys/unix/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub(crate) fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream,
target_os = "tvos",
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
all(target_arch = "x86", target_os = "android"),
))]
let stream = {
Expand All @@ -99,11 +100,15 @@ pub(crate) fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream,
))
.map(|socket| unsafe { net::TcpStream::from_raw_fd(socket) })
.and_then(|s| {
#[cfg(not(target_os = "espidf"))]
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
syscall!(fcntl(s.as_raw_fd(), libc::F_SETFD, libc::FD_CLOEXEC))?;

// See https://github.com/tokio-rs/mio/issues/1450
#[cfg(any(all(target_arch = "x86", target_os = "android"), target_os = "espidf",))]
#[cfg(any(
all(target_arch = "x86", target_os = "android"),
target_os = "espidf",
target_os = "vita",
))]
syscall!(fcntl(s.as_raw_fd(), libc::F_SETFL, libc::O_NONBLOCK))?;

Ok(s)
Expand Down
10 changes: 8 additions & 2 deletions src/sys/unix/uds/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
target_os = "tvos",
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
// Android x86's seccomp profile forbids calls to `accept4(2)`
// See https://github.com/tokio-rs/mio/issues/1445 for details
all(target_arch = "x86", target_os = "android"),
Expand All @@ -76,6 +77,7 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
target_os = "tvos",
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
all(target_arch = "x86", target_os = "android")
))]
let socket = syscall!(accept(
Expand All @@ -87,11 +89,15 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
// Ensure the socket is closed if either of the `fcntl` calls
// error below.
let s = unsafe { net::UnixStream::from_raw_fd(socket) };
#[cfg(not(target_os = "espidf"))]
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
syscall!(fcntl(socket, libc::F_SETFD, libc::FD_CLOEXEC))?;

// See https://github.com/tokio-rs/mio/issues/1450
#[cfg(any(all(target_arch = "x86", target_os = "android"), target_os = "espidf",))]
#[cfg(any(
all(target_arch = "x86", target_os = "android"),
target_os = "espidf",
target_os = "vita",
))]
syscall!(fcntl(socket, libc::F_SETFL, libc::O_NONBLOCK))?;

Ok(s)
Expand Down
7 changes: 5 additions & 2 deletions src/sys/unix/uds/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ cfg_os_poll! {
target_os = "tvos",
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
)))]
let flags = flags | libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC;

Expand All @@ -101,15 +102,17 @@ cfg_os_poll! {
target_os = "tvos",
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
))]
{
syscall!(fcntl(fds[0], libc::F_SETFL, libc::O_NONBLOCK))?;
#[cfg(not(target_os = "espidf"))]
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
syscall!(fcntl(fds[0], libc::F_SETFD, libc::FD_CLOEXEC))?;
syscall!(fcntl(fds[1], libc::F_SETFL, libc::O_NONBLOCK))?;
#[cfg(not(target_os = "espidf"))]
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
syscall!(fcntl(fds[1], libc::F_SETFD, libc::FD_CLOEXEC))?;
}

Ok(pair)
}

Expand Down
1 change: 1 addition & 0 deletions src/sys/unix/waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ mod pipe {
target_os = "netbsd",
target_os = "openbsd",
target_os = "redox",
target_os = "vita",
)
))]
pub(crate) use self::pipe::WakerInternal;
Expand Down