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

Add support for vita #465

Merged
merged 3 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ jobs:
- uses: taiki-e/install-action@cargo-hack
- name: Run check
run: cargo hack check --feature-powerset --all-targets --examples --bins --tests --target ${{ matrix.target }}
CheckTier3:
name: Check
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: ["armv7-sony-vita-newlibeabihf"]
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
with:
components: "rust-src"
- uses: taiki-e/install-action@cargo-hack
- name: Run check
run: cargo hack check -Z build-std=std,panic_abort --feature-powerset --all-targets --examples --bins --tests --target ${{ matrix.target }}
Clippy:
name: Clippy
runs-on: ubuntu-latest
Expand All @@ -87,3 +102,17 @@ jobs:
targets: ${{ matrix.target }}
- name: Check docs for docs.rs
run: RUSTDOCFLAGS="-D warnings --cfg docsrs" cargo doc --no-deps --all-features --target ${{ matrix.target }}
DocsTier3:
name: Docs
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: ["armv7-sony-vita-newlibeabihf"]
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly # NOTE: need nightly for `doc_cfg` feature.
with:
components: "rust-src"
- name: Check docs for docs.rs
run: RUSTDOCFLAGS="-D warnings --cfg docsrs" cargo doc -Z build-std=std,panic_abort --no-deps --all-features --target ${{ matrix.target }}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ targets = ["aarch64-apple-ios", "aarch64-linux-android", "x86_64-apple-darwin",
features = ["all"]

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

[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.48"
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,15 @@ impl<'a> DerefMut for MaybeUninitSlice<'a> {
/// See [`Socket::set_tcp_keepalive`].
#[derive(Debug, Clone)]
pub struct TcpKeepalive {
#[cfg_attr(target_os = "openbsd", allow(dead_code))]
#[cfg_attr(any(target_os = "openbsd", target_os = "vita"), allow(dead_code))]
time: Option<Duration>,
#[cfg(not(any(
target_os = "openbsd",
target_os = "redox",
target_os = "solaris",
target_os = "nto",
target_os = "espidf",
target_os = "vita",
)))]
interval: Option<Duration>,
#[cfg(not(any(
Expand All @@ -442,6 +443,7 @@ pub struct TcpKeepalive {
target_os = "windows",
target_os = "nto",
target_os = "espidf",
target_os = "vita",
)))]
retries: Option<u32>,
}
Expand All @@ -457,6 +459,7 @@ impl TcpKeepalive {
target_os = "solaris",
target_os = "nto",
target_os = "espidf",
target_os = "vita",
)))]
interval: None,
#[cfg(not(any(
Expand All @@ -466,6 +469,7 @@ impl TcpKeepalive {
target_os = "windows",
target_os = "nto",
target_os = "espidf",
target_os = "vita",
)))]
retries: None,
}
Expand Down Expand Up @@ -680,6 +684,7 @@ impl<'addr, 'bufs, 'control> MsgHdrMut<'addr, 'bufs, 'control> {
///
/// Corresponds to setting `msg_name` and `msg_namelen` on Unix and `name`
/// and `namelen` on Windows.
#[allow(clippy::needless_pass_by_ref_mut)]
pub fn with_addr(mut self, addr: &'addr mut SockAddr) -> Self {
sys::set_msghdr_name(&mut self.inner, addr);
self
Expand Down
23 changes: 21 additions & 2 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ fn set_common_flags(socket: Socket) -> io::Result<Socket> {
target_os = "netbsd",
target_os = "openbsd",
target_os = "espidf",
target_os = "vita",
))
))]
socket._set_cloexec(true)?;
Expand Down Expand Up @@ -1245,6 +1246,7 @@ impl Socket {
target_os = "solaris",
target_os = "nto",
target_os = "espidf",
target_os = "vita",
)))]
pub fn join_multicast_v4_n(
&self,
Expand Down Expand Up @@ -1277,6 +1279,7 @@ impl Socket {
target_os = "solaris",
target_os = "nto",
target_os = "espidf",
target_os = "vita",
)))]
pub fn leave_multicast_v4_n(
&self,
Expand Down Expand Up @@ -1310,6 +1313,7 @@ impl Socket {
target_os = "fuchsia",
target_os = "nto",
target_os = "espidf",
target_os = "vita",
)))]
pub fn join_ssm_v4(
&self,
Expand Down Expand Up @@ -1346,6 +1350,7 @@ impl Socket {
target_os = "fuchsia",
target_os = "nto",
target_os = "espidf",
target_os = "vita",
)))]
pub fn leave_ssm_v4(
&self,
Expand Down Expand Up @@ -1524,6 +1529,7 @@ impl Socket {
target_os = "haiku",
target_os = "nto",
target_os = "espidf",
target_os = "vita",
)))]
pub fn set_recv_tos(&self, recv_tos: bool) -> io::Result<()> {
unsafe {
Expand Down Expand Up @@ -1553,6 +1559,7 @@ impl Socket {
target_os = "haiku",
target_os = "nto",
target_os = "espidf",
target_os = "vita",
)))]
pub fn recv_tos(&self) -> io::Result<bool> {
unsafe {
Expand Down Expand Up @@ -1769,6 +1776,7 @@ impl Socket {
target_os = "solaris",
target_os = "haiku",
target_os = "espidf",
target_os = "vita",
)))]
pub fn recv_tclass_v6(&self) -> io::Result<bool> {
unsafe {
Expand All @@ -1792,6 +1800,7 @@ impl Socket {
target_os = "solaris",
target_os = "haiku",
target_os = "espidf",
target_os = "vita",
)))]
pub fn set_recv_tclass_v6(&self, recv_tclass: bool) -> io::Result<()> {
unsafe {
Expand All @@ -1817,13 +1826,23 @@ impl Socket {
/// supported Unix operating systems.
#[cfg(all(
feature = "all",
not(any(windows, target_os = "haiku", target_os = "openbsd"))
not(any(
windows,
target_os = "haiku",
target_os = "openbsd",
target_os = "vita"
))
))]
#[cfg_attr(
docsrs,
doc(cfg(all(
feature = "all",
not(any(windows, target_os = "haiku", target_os = "openbsd"))
not(any(
windows,
target_os = "haiku",
target_os = "openbsd",
target_os = "vita"
))
)))
)]
pub fn keepalive_time(&self) -> io::Result<Duration> {
Expand Down
58 changes: 52 additions & 6 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub(crate) use libc::ipv6_mreq as Ipv6Mreq;
target_os = "solaris",
target_os = "haiku",
target_os = "espidf",
target_os = "vita",
)))]
pub(crate) use libc::IPV6_RECVTCLASS;
#[cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf"))))]
Expand All @@ -144,6 +145,7 @@ pub(crate) use libc::IP_HDRINCL;
target_os = "haiku",
target_os = "nto",
target_os = "espidf",
target_os = "vita",
)))]
pub(crate) use libc::IP_RECVTOS;
#[cfg(not(any(
Expand Down Expand Up @@ -183,6 +185,7 @@ pub(crate) use libc::{
target_os = "fuchsia",
target_os = "nto",
target_os = "espidf",
target_os = "vita",
)))]
pub(crate) use libc::{
ip_mreq_source as IpMreqSource, IP_ADD_SOURCE_MEMBERSHIP, IP_DROP_SOURCE_MEMBERSHIP,
Expand Down Expand Up @@ -255,6 +258,7 @@ use libc::TCP_KEEPALIVE as KEEPALIVE_TIME;
target_os = "openbsd",
target_os = "tvos",
target_os = "watchos",
target_os = "vita",
)))]
use libc::TCP_KEEPIDLE as KEEPALIVE_TIME;

Expand Down Expand Up @@ -335,6 +339,7 @@ type IovLen = usize;
target_os = "tvos",
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
))]
type IovLen = c_int;

Expand Down Expand Up @@ -928,12 +933,20 @@ pub(crate) fn try_clone(fd: Socket) -> io::Result<Socket> {
syscall!(fcntl(fd, libc::F_DUPFD_CLOEXEC, 0))
}

#[cfg(all(feature = "all", unix))]
#[cfg(all(feature = "all", unix, not(target_os = "vita")))]
pub(crate) fn nonblocking(fd: Socket) -> io::Result<bool> {
let file_status_flags = fcntl_get(fd, libc::F_GETFL)?;
Ok((file_status_flags & libc::O_NONBLOCK) != 0)
}

#[cfg(all(feature = "all", target_os = "vita"))]
pub(crate) fn nonblocking(fd: Socket) -> io::Result<bool> {
unsafe {
getsockopt::<Bool>(fd, libc::SOL_SOCKET, libc::SO_NONBLOCK).map(|non_block| non_block != 0)
}
}

#[cfg(not(target_os = "vita"))]
pub(crate) fn set_nonblocking(fd: Socket, nonblocking: bool) -> io::Result<()> {
if nonblocking {
fcntl_add(fd, libc::F_GETFL, libc::F_SETFL, libc::O_NONBLOCK)
Expand All @@ -942,6 +955,18 @@ pub(crate) fn set_nonblocking(fd: Socket, nonblocking: bool) -> io::Result<()> {
}
}

#[cfg(target_os = "vita")]
pub(crate) fn set_nonblocking(fd: Socket, nonblocking: bool) -> io::Result<()> {
unsafe {
setsockopt(
fd,
libc::SOL_SOCKET,
libc::SO_NONBLOCK,
nonblocking as libc::c_int,
)
}
}

pub(crate) fn shutdown(fd: Socket, how: Shutdown) -> io::Result<()> {
let how = match how {
Shutdown::Write => libc::SHUT_WR,
Expand Down Expand Up @@ -1118,10 +1143,16 @@ fn into_timeval(duration: Option<Duration>) -> libc::timeval {
}
}

#[cfg(all(feature = "all", not(any(target_os = "haiku", target_os = "openbsd"))))]
#[cfg(all(
feature = "all",
not(any(target_os = "haiku", target_os = "openbsd", target_os = "vita"))
))]
#[cfg_attr(
docsrs,
doc(cfg(all(feature = "all", not(any(target_os = "haiku", target_os = "openbsd")))))
doc(cfg(all(
feature = "all",
not(any(target_os = "haiku", target_os = "openbsd", target_os = "vita"))
)))
)]
pub(crate) fn keepalive_time(fd: Socket) -> io::Result<Duration> {
unsafe {
Expand All @@ -1132,7 +1163,12 @@ pub(crate) fn keepalive_time(fd: Socket) -> io::Result<Duration> {

#[allow(unused_variables)]
pub(crate) fn set_tcp_keepalive(fd: Socket, keepalive: &TcpKeepalive) -> io::Result<()> {
#[cfg(not(any(target_os = "haiku", target_os = "openbsd", target_os = "nto")))]
#[cfg(not(any(
target_os = "haiku",
target_os = "openbsd",
target_os = "nto",
target_os = "vita"
)))]
if let Some(time) = keepalive.time {
let secs = into_secs(time);
unsafe { setsockopt(fd, libc::IPPROTO_TCP, KEEPALIVE_TIME, secs)? }
Expand Down Expand Up @@ -1172,17 +1208,24 @@ pub(crate) fn set_tcp_keepalive(fd: Socket, keepalive: &TcpKeepalive) -> io::Res
Ok(())
}

#[cfg(not(any(target_os = "haiku", target_os = "openbsd", target_os = "nto")))]
#[cfg(not(any(
target_os = "haiku",
target_os = "openbsd",
target_os = "nto",
target_os = "vita"
)))]
fn into_secs(duration: Duration) -> c_int {
min(duration.as_secs(), c_int::MAX as u64) as c_int
}

/// Get the flags using `cmd`.
#[cfg(not(target_os = "vita"))]
fn fcntl_get(fd: Socket, cmd: c_int) -> io::Result<c_int> {
syscall!(fcntl(fd, cmd))
}

/// Add `flag` to the current set flags of `F_GETFD`.
#[cfg(not(target_os = "vita"))]
fn fcntl_add(fd: Socket, get_cmd: c_int, set_cmd: c_int, flag: c_int) -> io::Result<()> {
let previous = fcntl_get(fd, get_cmd)?;
let new = previous | flag;
Expand All @@ -1195,6 +1238,7 @@ fn fcntl_add(fd: Socket, get_cmd: c_int, set_cmd: c_int, flag: c_int) -> io::Res
}

/// Remove `flag` to the current set flags of `F_GETFD`.
#[cfg(not(target_os = "vita"))]
fn fcntl_remove(fd: Socket, get_cmd: c_int, set_cmd: c_int, flag: c_int) -> io::Result<()> {
let previous = fcntl_get(fd, get_cmd)?;
let new = previous & !flag;
Expand Down Expand Up @@ -1275,6 +1319,7 @@ pub(crate) fn from_in6_addr(addr: in6_addr) -> Ipv6Addr {
target_os = "solaris",
target_os = "nto",
target_os = "espidf",
target_os = "vita",
)))]
pub(crate) const fn to_mreqn(
multiaddr: &Ipv4Addr,
Expand Down Expand Up @@ -1371,12 +1416,13 @@ impl crate::Socket {
),
allow(rustdoc::broken_intra_doc_links)
)]
#[cfg(feature = "all")]
#[cfg(all(feature = "all", not(target_os = "vita")))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", unix))))]
pub fn set_cloexec(&self, close_on_exec: bool) -> io::Result<()> {
self._set_cloexec(close_on_exec)
}

#[cfg(not(target_os = "vita"))]
pub(crate) fn _set_cloexec(&self, close_on_exec: bool) -> io::Result<()> {
if close_on_exec {
fcntl_add(
Expand Down
Loading