Skip to content

Commit

Permalink
Add support for QNX OS
Browse files Browse the repository at this point in the history
Signed-off-by: Akhil T Thomas <akhilthomasmec@gmail.com>
Co-authored-by: Akhil Thankachan Thomas <Akhil.Thomas@in.bosch.com>
Co-authored-by: Akhil T Thomas <akhilthomasmec@gmail.com>
  • Loading branch information
3 people committed Apr 1, 2024
1 parent 176a9f1 commit 15050b9
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/sys/unix/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub(crate) fn new_socket(domain: libc::c_int, socket_type: libc::c_int) -> io::R
target_os = "hermit",
))]
let socket_type = socket_type | libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC;
#[cfg(target_os = "nto")]
let socket_type = socket_type | libc::SOCK_CLOEXEC;

let socket = syscall!(socket(domain, socket_type, 0))?;

Expand Down Expand Up @@ -54,13 +56,14 @@ pub(crate) fn new_socket(domain: libc::c_int, socket_type: libc::c_int) -> io::R
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
target_os = "nto",
))]
{
if let Err(err) = syscall!(fcntl(socket, libc::F_SETFL, libc::O_NONBLOCK)) {
let _ = syscall!(close(socket));
return Err(err);
}
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "nto")))]
if let Err(err) = syscall!(fcntl(socket, libc::F_SETFD, libc::FD_CLOEXEC)) {
let _ = syscall!(close(socket));
return Err(err);
Expand Down Expand Up @@ -117,6 +120,7 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_
target_os = "espidf",
target_os = "vita",
target_os = "hermit",
target_os = "nto",
))]
sin_len: 0,
#[cfg(target_os = "vita")]
Expand Down Expand Up @@ -148,6 +152,7 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
target_os = "nto",
))]
sin6_len: 0,
#[cfg(target_os = "vita")]
Expand Down
2 changes: 2 additions & 0 deletions src/sys/unix/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub(crate) fn new_raw() -> io::Result<[RawFd; 2]> {
target_os = "tvos",
target_os = "watchos",
target_os = "espidf",
target_os = "nto",
))]
unsafe {
// For platforms that don't have `pipe2(2)` we need to manually set the
Expand Down Expand Up @@ -71,6 +72,7 @@ pub(crate) fn new_raw() -> io::Result<[RawFd; 2]> {
target_os = "espidf",
target_os = "solaris",
target_os = "vita",
target_os = "nto",
)))]
compile_error!("unsupported target for `mio::unix::pipe`");

Expand Down
2 changes: 2 additions & 0 deletions src/sys/unix/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub(crate) fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream,
target_os = "espidf",
target_os = "vita",
target_os = "hermit",
target_os = "nto",
all(target_arch = "x86", target_os = "android"),
))]
let stream = {
Expand All @@ -114,6 +115,7 @@ pub(crate) fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream,
target_os = "espidf",
target_os = "vita",
target_os = "hermit",
target_os = "nto",
))]
syscall!(fcntl(s.as_raw_fd(), libc::F_SETFL, libc::O_NONBLOCK))?;

Expand Down
3 changes: 3 additions & 0 deletions src/sys/unix/uds/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
target_os = "nto",
// 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 @@ -78,6 +79,7 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
target_os = "nto",
all(target_arch = "x86", target_os = "android")
))]
let socket = syscall!(accept(
Expand All @@ -97,6 +99,7 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
all(target_arch = "x86", target_os = "android"),
target_os = "espidf",
target_os = "vita",
target_os = "nto",
))]
syscall!(fcntl(socket, libc::F_SETFL, libc::O_NONBLOCK))?;

Expand Down
8 changes: 6 additions & 2 deletions src/sys/unix/uds/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ cfg_os_poll! {
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
target_os = "nto",
)))]
let flags = flags | libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC;
#[cfg(target_os = "nto")]
let flags = flags | libc::SOCK_CLOEXEC;

let mut fds = [-1; 2];
syscall!(socketpair(libc::AF_UNIX, flags, 0, fds.as_mut_ptr()))?;
Expand All @@ -103,13 +106,14 @@ cfg_os_poll! {
target_os = "watchos",
target_os = "espidf",
target_os = "vita",
target_os = "nto",
))]
{
syscall!(fcntl(fds[0], libc::F_SETFL, libc::O_NONBLOCK))?;
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "nto")))]
syscall!(fcntl(fds[0], libc::F_SETFD, libc::FD_CLOEXEC))?;
syscall!(fcntl(fds[1], libc::F_SETFL, libc::O_NONBLOCK))?;
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "nto")))]
syscall!(fcntl(fds[1], libc::F_SETFD, libc::FD_CLOEXEC))?;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,8 @@ fn write_shutdown() {
// Now, shutdown the write half of the socket.
socket.shutdown(Shutdown::Write).unwrap();

// POLLRDHUP isn't supported on Solaris
if cfg!(target_os = "solaris") {
// POLLRDHUP isn't supported on Solaris,
if cfg!(any(target_os = "solaris", target_os = "nto")) {
wait!(poll, is_readable, false);
} else {
wait!(poll, is_readable, true);
Expand Down
6 changes: 5 additions & 1 deletion tests/tcp_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ fn no_events_after_deregister() {
ignore = "fails on Windows; client read closed events are not triggered"
)]
#[cfg_attr(target_os = "solaris", ignore = "POLLRDHUP isn't supported on Solaris")]
#[cfg_attr(target_os = "nto", ignore = "POLLRDHUP isn't supported on NTO")]
fn tcp_shutdown_client_read_close_event() {
let (mut poll, mut events) = init_with_poll();
let barrier = Arc::new(Barrier::new(2));
Expand Down Expand Up @@ -552,7 +553,8 @@ fn tcp_shutdown_client_read_close_event() {
target_os = "android",
target_os = "illumos",
target_os = "solaris",
target_os = "linux"
target_os = "linux",
target_os = "nto"
),
ignore = "fails; client write_closed events are not found"
)]
Expand Down Expand Up @@ -588,6 +590,7 @@ fn tcp_shutdown_client_write_close_event() {

#[test]
#[cfg_attr(target_os = "solaris", ignore = "POLLRDHUP isn't supported on Solaris")]
#[cfg_attr(target_os = "nto", ignore = "POLLRDHUP isn't supported on NTO")]
fn tcp_shutdown_server_write_close_event() {
let (mut poll, mut events) = init_with_poll();
let barrier = Arc::new(Barrier::new(2));
Expand Down Expand Up @@ -619,6 +622,7 @@ fn tcp_shutdown_server_write_close_event() {

#[test]
#[cfg_attr(target_os = "solaris", ignore = "POLLRDHUP isn't supported on Solaris")]
#[cfg_attr(target_os = "nto", ignore = "POLLRDHUP isn't supported on NTO")]
fn tcp_reset_close_event() {
let (mut poll, mut events) = init_with_poll();

Expand Down
1 change: 1 addition & 0 deletions tests/unix_datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ fn unix_datagram_pair() {

#[test]
#[cfg_attr(target_os = "solaris", ignore = "POLLRDHUP isn't supported on Solaris")]
#[cfg_attr(target_os = "nto", ignore = "POLLRDHUP isn't supported on NTO")]
fn unix_datagram_shutdown() {
let (mut poll, mut events) = init_with_poll();
let path1 = temp_file("unix_datagram_shutdown1");
Expand Down
14 changes: 12 additions & 2 deletions tests/unix_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ fn smoke() {
}

#[test]
#[cfg_attr(
target_os = "nto",
ignore = "Writer fd close events do not trigger POLLHUP on nto target"
)]
fn event_when_sender_is_dropped() {
let mut poll = Poll::new().unwrap();
let mut events = Events::with_capacity(8);
Expand Down Expand Up @@ -91,6 +95,10 @@ fn event_when_sender_is_dropped() {
}

#[test]
#[cfg_attr(
target_os = "nto",
ignore = "Read fd close events do not trigger POLLHUP on nto target"
)]
fn event_when_receiver_is_dropped() {
let mut poll = Poll::new().unwrap();
let mut events = Events::with_capacity(8);
Expand Down Expand Up @@ -124,10 +132,13 @@ fn event_when_receiver_is_dropped() {
}

#[test]
#[cfg_attr(
target_os = "nto",
ignore = "Read/Write close eventsdo not trigger POLLHUP on nto target"
)]
fn from_child_process_io() {
// `cat` simply echo everything that we write via standard in.
let mut child = Command::new("cat")
.env_clear()
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
Expand Down Expand Up @@ -175,7 +186,6 @@ fn from_child_process_io() {
fn nonblocking_child_process_io() {
// `cat` simply echo everything that we write via standard in.
let mut child = Command::new("cat")
.env_clear()
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
Expand Down
2 changes: 2 additions & 0 deletions tests/unix_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ fn unix_stream_peer_addr() {

#[test]
#[cfg_attr(target_os = "solaris", ignore = "POLLRDHUP isn't supported on Solaris")]
#[cfg_attr(target_os = "nto", ignore = "POLLRDHUP isn't supported on NTO")]
fn unix_stream_shutdown_read() {
let (mut poll, mut events) = init_with_poll();
let (handle, remote_addr) = new_echo_listener(1, "unix_stream_shutdown_read");
Expand Down Expand Up @@ -365,6 +366,7 @@ fn unix_stream_shutdown_both() {

#[test]
#[cfg_attr(target_os = "solaris", ignore = "POLLRDHUP isn't supported on Solaris")]
#[cfg_attr(target_os = "nto", ignore = "POLLRDHUP isn't supported on NTO")]
fn unix_stream_shutdown_listener_write() {
let (mut poll, mut events) = init_with_poll();
let barrier = Arc::new(Barrier::new(2));
Expand Down

0 comments on commit 15050b9

Please sign in to comment.