Skip to content

Commit 44f9a2d

Browse files
authored
Enable rustix::net on Redox. (#1302)
Redox supports most of the socket APIs, so enable `rustix::net` on Redox.
1 parent fb30a30 commit 44f9a2d

19 files changed

Lines changed: 200 additions & 127 deletions

File tree

src/backend/libc/conv.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub(super) fn ret_discarded_char_ptr(raw: *mut c::c_char) -> io::Result<()> {
151151
}
152152

153153
/// Convert the buffer-length argument value of a `send` or `recv` call.
154-
#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))]
154+
#[cfg(not(any(windows, target_os = "wasi")))]
155155
#[inline]
156156
pub(super) fn send_recv_len(len: usize) -> usize {
157157
len
@@ -168,7 +168,7 @@ pub(super) fn send_recv_len(len: usize) -> i32 {
168168
}
169169

170170
/// Convert the return value of a `send` or `recv` call.
171-
#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))]
171+
#[cfg(not(any(windows, target_os = "wasi")))]
172172
#[inline]
173173
pub(super) fn ret_send_recv(len: isize) -> io::Result<usize> {
174174
ret_usize(len)
@@ -183,7 +183,7 @@ pub(super) fn ret_send_recv(len: i32) -> io::Result<usize> {
183183

184184
/// Convert the value to the `msg_iovlen` field of a `msghdr` struct.
185185
#[cfg(all(
186-
not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")),
186+
not(any(windows, target_os = "espidf", target_os = "wasi")),
187187
any(
188188
target_os = "android",
189189
all(

src/backend/libc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub(crate) mod mm;
117117
#[cfg(linux_kernel)]
118118
#[cfg(feature = "mount")]
119119
pub(crate) mod mount;
120-
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
120+
#[cfg(not(target_os = "wasi"))]
121121
#[cfg(feature = "net")]
122122
pub(crate) mod net;
123123
#[cfg(not(any(windows, target_os = "espidf")))]

src/backend/libc/net/mod.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
pub(crate) mod addr;
22
pub(crate) mod ext;
3-
#[cfg(not(any(
4-
windows,
5-
target_os = "espidf",
6-
target_os = "redox",
7-
target_os = "vita",
8-
target_os = "wasi"
9-
)))]
3+
#[cfg(not(any(windows, target_os = "espidf", target_os = "redox", target_os = "vita")))]
104
pub(crate) mod msghdr;
115
#[cfg(linux_kernel)]
126
pub(crate) mod netdevice;
137
pub(crate) mod read_sockaddr;
148
pub(crate) mod send_recv;
15-
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
169
pub(crate) mod sockopt;
1710
pub(crate) mod syscalls;
1811
pub(crate) mod write_sockaddr;

src/backend/libc/net/send_recv.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ bitflags! {
2020
target_os = "nto",
2121
target_os = "haiku",
2222
target_os = "hurd",
23+
target_os = "redox",
2324
target_os = "vita",
2425
)))]
2526
const CONFIRM = bitcast!(c::MSG_CONFIRM);
@@ -40,10 +41,11 @@ bitflags! {
4041
target_os = "haiku",
4142
target_os = "hurd",
4243
target_os = "nto",
44+
target_os = "redox",
4345
target_os = "vita",
4446
)))]
4547
const MORE = bitcast!(c::MSG_MORE);
46-
#[cfg(not(any(apple, windows, target_os = "vita")))]
48+
#[cfg(not(any(apple, windows, target_os = "redox", target_os = "vita")))]
4749
/// `MSG_NOSIGNAL`
4850
const NOSIGNAL = bitcast!(c::MSG_NOSIGNAL);
4951
/// `MSG_OOB`
@@ -72,6 +74,7 @@ bitflags! {
7274
target_os = "espidf",
7375
target_os = "haiku",
7476
target_os = "nto",
77+
target_os = "redox",
7578
target_os = "vita",
7679
)))]
7780
const CMSG_CLOEXEC = bitcast!(c::MSG_CMSG_CLOEXEC);
@@ -88,6 +91,7 @@ bitflags! {
8891
target_os = "haiku",
8992
target_os = "hurd",
9093
target_os = "nto",
94+
target_os = "redox",
9195
target_os = "vita",
9296
)))]
9397
const ERRQUEUE = bitcast!(c::MSG_ERRQUEUE);

src/backend/libc/net/sockopt.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ pub(crate) fn ipv6_original_dst(fd: BorrowedFd<'_>) -> io::Result<SocketAddrV6>
844844
windows,
845845
target_os = "espidf",
846846
target_os = "haiku",
847+
target_os = "redox",
847848
target_os = "vita"
848849
)))]
849850
#[inline]
@@ -856,6 +857,7 @@ pub(crate) fn set_ipv6_tclass(fd: BorrowedFd<'_>, value: u32) -> io::Result<()>
856857
windows,
857858
target_os = "espidf",
858859
target_os = "haiku",
860+
target_os = "redox",
859861
target_os = "vita"
860862
)))]
861863
#[inline]
@@ -874,13 +876,23 @@ pub(crate) fn tcp_nodelay(fd: BorrowedFd<'_>) -> io::Result<bool> {
874876
}
875877

876878
#[inline]
877-
#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))]
879+
#[cfg(not(any(
880+
target_os = "openbsd",
881+
target_os = "haiku",
882+
target_os = "nto",
883+
target_os = "redox"
884+
)))]
878885
pub(crate) fn set_tcp_keepcnt(fd: BorrowedFd<'_>, count: u32) -> io::Result<()> {
879886
setsockopt(fd, c::IPPROTO_TCP, c::TCP_KEEPCNT, count)
880887
}
881888

882889
#[inline]
883-
#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))]
890+
#[cfg(not(any(
891+
target_os = "openbsd",
892+
target_os = "haiku",
893+
target_os = "nto",
894+
target_os = "redox"
895+
)))]
884896
pub(crate) fn tcp_keepcnt(fd: BorrowedFd<'_>) -> io::Result<u32> {
885897
getsockopt(fd, c::IPPROTO_TCP, c::TCP_KEEPCNT)
886898
}
@@ -900,14 +912,24 @@ pub(crate) fn tcp_keepidle(fd: BorrowedFd<'_>) -> io::Result<Duration> {
900912
}
901913

902914
#[inline]
903-
#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))]
915+
#[cfg(not(any(
916+
target_os = "openbsd",
917+
target_os = "haiku",
918+
target_os = "nto",
919+
target_os = "redox"
920+
)))]
904921
pub(crate) fn set_tcp_keepintvl(fd: BorrowedFd<'_>, duration: Duration) -> io::Result<()> {
905922
let secs: c::c_uint = duration_to_secs(duration)?;
906923
setsockopt(fd, c::IPPROTO_TCP, c::TCP_KEEPINTVL, secs)
907924
}
908925

909926
#[inline]
910-
#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))]
927+
#[cfg(not(any(
928+
target_os = "openbsd",
929+
target_os = "haiku",
930+
target_os = "nto",
931+
target_os = "redox"
932+
)))]
911933
pub(crate) fn tcp_keepintvl(fd: BorrowedFd<'_>) -> io::Result<Duration> {
912934
let secs: c::c_uint = getsockopt(fd, c::IPPROTO_TCP, c::TCP_KEEPINTVL)?;
913935
Ok(Duration::from_secs(secs as u64))

0 commit comments

Comments
 (0)