Skip to content

Commit beeb126

Browse files
phekiThomasdezeeuw
authored andcommitted
Add support for vita
Don't run tests for properties not available Added CI, fixed tests
1 parent 1f70523 commit beeb126

File tree

6 files changed

+164
-33
lines changed

6 files changed

+164
-33
lines changed

.github/workflows/main.yml

+29
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ jobs:
6565
- uses: taiki-e/install-action@cargo-hack
6666
- name: Run check
6767
run: cargo hack check --feature-powerset --all-targets --examples --bins --tests --target ${{ matrix.target }}
68+
CheckTier3:
69+
name: Check
70+
runs-on: ubuntu-latest
71+
strategy:
72+
fail-fast: false
73+
matrix:
74+
target: ["armv7-sony-vita-newlibeabihf"]
75+
steps:
76+
- uses: actions/checkout@v3
77+
- uses: dtolnay/rust-toolchain@nightly
78+
with:
79+
components: "rust-src"
80+
- uses: taiki-e/install-action@cargo-hack
81+
- name: Run check
82+
run: cargo hack check -Z build-std=std,panic_abort --feature-powerset --all-targets --examples --bins --tests --target ${{ matrix.target }}
6883
Clippy:
6984
name: Clippy
7085
runs-on: ubuntu-latest
@@ -87,3 +102,17 @@ jobs:
87102
targets: ${{ matrix.target }}
88103
- name: Check docs for docs.rs
89104
run: RUSTDOCFLAGS="-D warnings --cfg docsrs" cargo doc --no-deps --all-features --target ${{ matrix.target }}
105+
DocsTier3:
106+
name: Docs
107+
runs-on: ubuntu-latest
108+
strategy:
109+
fail-fast: false
110+
matrix:
111+
target: ["armv7-sony-vita-newlibeabihf"]
112+
steps:
113+
- uses: actions/checkout@v3
114+
- uses: dtolnay/rust-toolchain@nightly # NOTE: need nightly for `doc_cfg` feature.
115+
with:
116+
components: "rust-src"
117+
- name: Check docs for docs.rs
118+
run: RUSTDOCFLAGS="-D warnings --cfg docsrs" cargo doc -Z build-std=std,panic_abort --no-deps --all-features --target ${{ matrix.target }}

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ targets = ["aarch64-apple-ios", "aarch64-linux-android", "x86_64-apple-darwin",
3535
features = ["all"]
3636

3737
[target."cfg(unix)".dependencies]
38-
libc = "0.2.141"
38+
libc = "0.2.149"
3939

4040
[target.'cfg(windows)'.dependencies.windows-sys]
4141
version = "0.48"

src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,15 @@ impl<'a> DerefMut for MaybeUninitSlice<'a> {
425425
/// See [`Socket::set_tcp_keepalive`].
426426
#[derive(Debug, Clone)]
427427
pub struct TcpKeepalive {
428-
#[cfg_attr(target_os = "openbsd", allow(dead_code))]
428+
#[cfg_attr(any(target_os = "openbsd", target_os = "vita"), allow(dead_code))]
429429
time: Option<Duration>,
430430
#[cfg(not(any(
431431
target_os = "openbsd",
432432
target_os = "redox",
433433
target_os = "solaris",
434434
target_os = "nto",
435435
target_os = "espidf",
436+
target_os = "vita",
436437
)))]
437438
interval: Option<Duration>,
438439
#[cfg(not(any(
@@ -442,6 +443,7 @@ pub struct TcpKeepalive {
442443
target_os = "windows",
443444
target_os = "nto",
444445
target_os = "espidf",
446+
target_os = "vita",
445447
)))]
446448
retries: Option<u32>,
447449
}
@@ -457,6 +459,7 @@ impl TcpKeepalive {
457459
target_os = "solaris",
458460
target_os = "nto",
459461
target_os = "espidf",
462+
target_os = "vita",
460463
)))]
461464
interval: None,
462465
#[cfg(not(any(
@@ -466,6 +469,7 @@ impl TcpKeepalive {
466469
target_os = "windows",
467470
target_os = "nto",
468471
target_os = "espidf",
472+
target_os = "vita",
469473
)))]
470474
retries: None,
471475
}
@@ -680,7 +684,7 @@ impl<'addr, 'bufs, 'control> MsgHdrMut<'addr, 'bufs, 'control> {
680684
///
681685
/// Corresponds to setting `msg_name` and `msg_namelen` on Unix and `name`
682686
/// and `namelen` on Windows.
683-
pub fn with_addr(mut self, addr: &'addr mut SockAddr) -> Self {
687+
pub fn with_addr(mut self, addr: &SockAddr) -> Self {
684688
sys::set_msghdr_name(&mut self.inner, addr);
685689
self
686690
}

src/socket.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl Socket {
368368
/// `O_NONBLOCK`.
369369
///
370370
/// On Windows it is not possible retrieve the nonblocking mode status.
371-
#[cfg(all(feature = "all", unix))]
371+
#[cfg(any(target_os = "vita", all(feature = "all", unix)))]
372372
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", unix))))]
373373
pub fn nonblocking(&self) -> io::Result<bool> {
374374
sys::nonblocking(self.as_raw())
@@ -791,6 +791,7 @@ fn set_common_flags(socket: Socket) -> io::Result<Socket> {
791791
target_os = "netbsd",
792792
target_os = "openbsd",
793793
target_os = "espidf",
794+
target_os = "vita",
794795
))
795796
))]
796797
socket._set_cloexec(true)?;
@@ -1245,6 +1246,7 @@ impl Socket {
12451246
target_os = "solaris",
12461247
target_os = "nto",
12471248
target_os = "espidf",
1249+
target_os = "vita",
12481250
)))]
12491251
pub fn join_multicast_v4_n(
12501252
&self,
@@ -1277,6 +1279,7 @@ impl Socket {
12771279
target_os = "solaris",
12781280
target_os = "nto",
12791281
target_os = "espidf",
1282+
target_os = "vita",
12801283
)))]
12811284
pub fn leave_multicast_v4_n(
12821285
&self,
@@ -1310,6 +1313,7 @@ impl Socket {
13101313
target_os = "fuchsia",
13111314
target_os = "nto",
13121315
target_os = "espidf",
1316+
target_os = "vita",
13131317
)))]
13141318
pub fn join_ssm_v4(
13151319
&self,
@@ -1346,6 +1350,7 @@ impl Socket {
13461350
target_os = "fuchsia",
13471351
target_os = "nto",
13481352
target_os = "espidf",
1353+
target_os = "vita",
13491354
)))]
13501355
pub fn leave_ssm_v4(
13511356
&self,
@@ -1524,6 +1529,7 @@ impl Socket {
15241529
target_os = "haiku",
15251530
target_os = "nto",
15261531
target_os = "espidf",
1532+
target_os = "vita",
15271533
)))]
15281534
pub fn set_recv_tos(&self, recv_tos: bool) -> io::Result<()> {
15291535
unsafe {
@@ -1553,6 +1559,7 @@ impl Socket {
15531559
target_os = "haiku",
15541560
target_os = "nto",
15551561
target_os = "espidf",
1562+
target_os = "vita",
15561563
)))]
15571564
pub fn recv_tos(&self) -> io::Result<bool> {
15581565
unsafe {
@@ -1769,6 +1776,7 @@ impl Socket {
17691776
target_os = "solaris",
17701777
target_os = "haiku",
17711778
target_os = "espidf",
1779+
target_os = "vita",
17721780
)))]
17731781
pub fn recv_tclass_v6(&self) -> io::Result<bool> {
17741782
unsafe {
@@ -1792,6 +1800,7 @@ impl Socket {
17921800
target_os = "solaris",
17931801
target_os = "haiku",
17941802
target_os = "espidf",
1803+
target_os = "vita",
17951804
)))]
17961805
pub fn set_recv_tclass_v6(&self, recv_tclass: bool) -> io::Result<()> {
17971806
unsafe {
@@ -1817,13 +1826,23 @@ impl Socket {
18171826
/// supported Unix operating systems.
18181827
#[cfg(all(
18191828
feature = "all",
1820-
not(any(windows, target_os = "haiku", target_os = "openbsd"))
1829+
not(any(
1830+
windows,
1831+
target_os = "haiku",
1832+
target_os = "openbsd",
1833+
target_os = "vita"
1834+
))
18211835
))]
18221836
#[cfg_attr(
18231837
docsrs,
18241838
doc(cfg(all(
18251839
feature = "all",
1826-
not(any(windows, target_os = "haiku", target_os = "openbsd"))
1840+
not(any(
1841+
windows,
1842+
target_os = "haiku",
1843+
target_os = "openbsd",
1844+
target_os = "vita"
1845+
))
18271846
)))
18281847
)]
18291848
pub fn keepalive_time(&self) -> io::Result<Duration> {

src/sys/unix.rs

+52-6
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ pub(crate) use libc::ipv6_mreq as Ipv6Mreq;
128128
target_os = "solaris",
129129
target_os = "haiku",
130130
target_os = "espidf",
131+
target_os = "vita",
131132
)))]
132133
pub(crate) use libc::IPV6_RECVTCLASS;
133134
#[cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf"))))]
@@ -144,6 +145,7 @@ pub(crate) use libc::IP_HDRINCL;
144145
target_os = "haiku",
145146
target_os = "nto",
146147
target_os = "espidf",
148+
target_os = "vita",
147149
)))]
148150
pub(crate) use libc::IP_RECVTOS;
149151
#[cfg(not(any(
@@ -183,6 +185,7 @@ pub(crate) use libc::{
183185
target_os = "fuchsia",
184186
target_os = "nto",
185187
target_os = "espidf",
188+
target_os = "vita",
186189
)))]
187190
pub(crate) use libc::{
188191
ip_mreq_source as IpMreqSource, IP_ADD_SOURCE_MEMBERSHIP, IP_DROP_SOURCE_MEMBERSHIP,
@@ -255,6 +258,7 @@ use libc::TCP_KEEPALIVE as KEEPALIVE_TIME;
255258
target_os = "openbsd",
256259
target_os = "tvos",
257260
target_os = "watchos",
261+
target_os = "vita",
258262
)))]
259263
use libc::TCP_KEEPIDLE as KEEPALIVE_TIME;
260264

@@ -335,6 +339,7 @@ type IovLen = usize;
335339
target_os = "tvos",
336340
target_os = "watchos",
337341
target_os = "espidf",
342+
target_os = "vita",
338343
))]
339344
type IovLen = c_int;
340345

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

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

942+
#[cfg(target_os = "vita")]
943+
pub(crate) fn nonblocking(fd: Socket) -> io::Result<bool> {
944+
unsafe {
945+
getsockopt::<Bool>(fd, libc::SOL_SOCKET, libc::SO_NONBLOCK).map(|non_block| non_block != 0)
946+
}
947+
}
948+
949+
#[cfg(not(target_os = "vita"))]
937950
pub(crate) fn set_nonblocking(fd: Socket, nonblocking: bool) -> io::Result<()> {
938951
if nonblocking {
939952
fcntl_add(fd, libc::F_GETFL, libc::F_SETFL, libc::O_NONBLOCK)
@@ -942,6 +955,18 @@ pub(crate) fn set_nonblocking(fd: Socket, nonblocking: bool) -> io::Result<()> {
942955
}
943956
}
944957

958+
#[cfg(target_os = "vita")]
959+
pub(crate) fn set_nonblocking(fd: Socket, nonblocking: bool) -> io::Result<()> {
960+
unsafe {
961+
setsockopt(
962+
fd,
963+
libc::SOL_SOCKET,
964+
libc::SO_NONBLOCK,
965+
nonblocking as libc::c_int,
966+
)
967+
}
968+
}
969+
945970
pub(crate) fn shutdown(fd: Socket, how: Shutdown) -> io::Result<()> {
946971
let how = match how {
947972
Shutdown::Write => libc::SHUT_WR,
@@ -1118,10 +1143,16 @@ fn into_timeval(duration: Option<Duration>) -> libc::timeval {
11181143
}
11191144
}
11201145

1121-
#[cfg(all(feature = "all", not(any(target_os = "haiku", target_os = "openbsd"))))]
1146+
#[cfg(all(
1147+
feature = "all",
1148+
not(any(target_os = "haiku", target_os = "openbsd", target_os = "vita"))
1149+
))]
11221150
#[cfg_attr(
11231151
docsrs,
1124-
doc(cfg(all(feature = "all", not(any(target_os = "haiku", target_os = "openbsd")))))
1152+
doc(cfg(all(
1153+
feature = "all",
1154+
not(any(target_os = "haiku", target_os = "openbsd", target_os = "vita"))
1155+
)))
11251156
)]
11261157
pub(crate) fn keepalive_time(fd: Socket) -> io::Result<Duration> {
11271158
unsafe {
@@ -1132,7 +1163,12 @@ pub(crate) fn keepalive_time(fd: Socket) -> io::Result<Duration> {
11321163

11331164
#[allow(unused_variables)]
11341165
pub(crate) fn set_tcp_keepalive(fd: Socket, keepalive: &TcpKeepalive) -> io::Result<()> {
1135-
#[cfg(not(any(target_os = "haiku", target_os = "openbsd", target_os = "nto")))]
1166+
#[cfg(not(any(
1167+
target_os = "haiku",
1168+
target_os = "openbsd",
1169+
target_os = "nto",
1170+
target_os = "vita"
1171+
)))]
11361172
if let Some(time) = keepalive.time {
11371173
let secs = into_secs(time);
11381174
unsafe { setsockopt(fd, libc::IPPROTO_TCP, KEEPALIVE_TIME, secs)? }
@@ -1172,17 +1208,24 @@ pub(crate) fn set_tcp_keepalive(fd: Socket, keepalive: &TcpKeepalive) -> io::Res
11721208
Ok(())
11731209
}
11741210

1175-
#[cfg(not(any(target_os = "haiku", target_os = "openbsd", target_os = "nto")))]
1211+
#[cfg(not(any(
1212+
target_os = "haiku",
1213+
target_os = "openbsd",
1214+
target_os = "nto",
1215+
target_os = "vita"
1216+
)))]
11761217
fn into_secs(duration: Duration) -> c_int {
11771218
min(duration.as_secs(), c_int::MAX as u64) as c_int
11781219
}
11791220

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

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

11971240
/// Remove `flag` to the current set flags of `F_GETFD`.
1241+
#[cfg(not(target_os = "vita"))]
11981242
fn fcntl_remove(fd: Socket, get_cmd: c_int, set_cmd: c_int, flag: c_int) -> io::Result<()> {
11991243
let previous = fcntl_get(fd, get_cmd)?;
12001244
let new = previous & !flag;
@@ -1275,6 +1319,7 @@ pub(crate) fn from_in6_addr(addr: in6_addr) -> Ipv6Addr {
12751319
target_os = "solaris",
12761320
target_os = "nto",
12771321
target_os = "espidf",
1322+
target_os = "vita",
12781323
)))]
12791324
pub(crate) const fn to_mreqn(
12801325
multiaddr: &Ipv4Addr,
@@ -1371,12 +1416,13 @@ impl crate::Socket {
13711416
),
13721417
allow(rustdoc::broken_intra_doc_links)
13731418
)]
1374-
#[cfg(feature = "all")]
1419+
#[cfg(all(feature = "all", not(target_os = "vita")))]
13751420
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", unix))))]
13761421
pub fn set_cloexec(&self, close_on_exec: bool) -> io::Result<()> {
13771422
self._set_cloexec(close_on_exec)
13781423
}
13791424

1425+
#[cfg(not(target_os = "vita"))]
13801426
pub(crate) fn _set_cloexec(&self, close_on_exec: bool) -> io::Result<()> {
13811427
if close_on_exec {
13821428
fcntl_add(

0 commit comments

Comments
 (0)