Skip to content

Commit

Permalink
Add Solaris operating system support (using flag mio_unsupported_forc…
Browse files Browse the repository at this point in the history
…e_poll_poll)
  • Loading branch information
psumbera committed Sep 1, 2023
1 parent 9f21ce1 commit 48eceef
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 6 deletions.
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 = "solaris",
))]
pub(crate) mod pipe;
}
Expand Down
3 changes: 2 additions & 1 deletion src/sys/unix/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub(crate) fn new_socket(domain: libc::c_int, socket_type: libc::c_int) -> io::R
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
))]
let socket_type = socket_type | libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC;

Expand Down Expand Up @@ -139,7 +140,7 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_
target_os = "espidf",
))]
sin6_len: 0,
#[cfg(target_os = "illumos")]
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
__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 = "solaris",
))]
unsafe {
if libc::pipe2(fds.as_mut_ptr(), libc::O_CLOEXEC | libc::O_NONBLOCK) != 0 {
Expand Down Expand Up @@ -64,6 +65,7 @@ pub(crate) fn new_raw() -> io::Result<[RawFd; 2]> {
target_os = "netbsd",
target_os = "openbsd",
target_os = "redox",
target_os = "solaris",
target_os = "tvos",
target_os = "watchos",
target_os = "espidf",
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 = "solaris")))]
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 = "solaris"))]
fn set_nonblocking(fd: RawFd, nonblocking: bool) -> io::Result<()> {
let flags = unsafe { libc::fcntl(fd, libc::F_GETFL) };
if flags < 0 {
Expand Down
1 change: 1 addition & 0 deletions src/sys/unix/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub(crate) fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream,
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
))]
let stream = {
syscall!(accept4(
Expand Down
3 changes: 3 additions & 0 deletions src/sys/unix/waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mod fdbased {
target_os = "netbsd",
target_os = "openbsd",
target_os = "redox",
target_os = "solaris",
))]
use crate::sys::unix::waker::pipe::WakerInternal;
use crate::sys::Selector;
Expand Down Expand Up @@ -205,6 +206,7 @@ pub use self::kqueue::Waker;
target_os = "netbsd",
target_os = "openbsd",
target_os = "redox",
target_os = "solaris",
))]
mod pipe {
use crate::sys::unix::pipe;
Expand Down Expand Up @@ -285,6 +287,7 @@ mod pipe {
target_os = "netbsd",
target_os = "openbsd",
target_os = "redox",
target_os = "solaris",
)
))]
pub(crate) use self::pipe::WakerInternal;
Expand Down
9 changes: 8 additions & 1 deletion tests/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ fn connect_error() {
for event in &events {
if event.token() == Token(0) {
assert!(event.is_writable());
// Solaris poll(2) says POLLHUP and POLLOUT are mutually exclusive.
#[cfg(not(target_os = "solaris"))]
assert!(event.is_write_closed());
break 'outer;
}
Expand Down Expand Up @@ -698,7 +700,12 @@ fn write_shutdown() {
// Now, shutdown the write half of the socket.
socket.shutdown(Shutdown::Write).unwrap();

wait!(poll, is_readable, true);
// POLLRDHUP isn't supported on Solaris
if cfg!(target_os = "solaris") {
wait!(poll, is_readable, false);
} else {
wait!(poll, is_readable, true);
}
}

struct MyHandler {
Expand Down
16 changes: 14 additions & 2 deletions tests/tcp_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ fn no_events_after_deregister() {
windows,
ignore = "fails on Windows; client read closed events are not triggered"
)]
#[cfg_attr(
target_os = "solaris",
ignore = "POLLRDHUP isn't supported on Solaris"
)]
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 @@ -547,7 +551,7 @@ fn tcp_shutdown_client_read_close_event() {
#[test]
#[cfg_attr(windows, ignore = "fails; client write_closed events are not found")]
#[cfg_attr(
any(target_os = "android", target_os = "illumos", target_os = "linux"),
any(target_os = "android", target_os = "illumos", target_os = "linux", target_os = "solaris"),
ignore = "fails; client write_closed events are not found"
)]
fn tcp_shutdown_client_write_close_event() {
Expand Down Expand Up @@ -581,6 +585,10 @@ fn tcp_shutdown_client_write_close_event() {
}

#[test]
#[cfg_attr(
target_os = "solaris",
ignore = "POLLRDHUP isn't supported on Solaris"
)]
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 @@ -611,6 +619,10 @@ fn tcp_shutdown_server_write_close_event() {
}

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

Expand Down Expand Up @@ -659,7 +671,7 @@ fn tcp_reset_close_event() {
ignore = "fails on Windows; client close events are not found"
)]
#[cfg_attr(
any(target_os = "illumos"),
any(target_os = "illumos", target_os = "solaris"),
ignore = "fails; client write_closed events are not found"
)]
fn tcp_shutdown_client_both_close_event() {
Expand Down
4 changes: 4 additions & 0 deletions tests/unix_datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ fn unix_datagram_pair() {
}

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

#[test]
#[cfg_attr(
target_os = "solaris",
ignore = "POLLRDHUP isn't supported on Solaris"
)]
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 @@ -326,6 +330,8 @@ fn unix_stream_shutdown_both() {
);

stream.shutdown(Shutdown::Both).unwrap();
// Solaris never returns POLLHUP for sockets.
#[cfg(not(target_os = "solaris"))]
expect_events(
&mut poll,
&mut events,
Expand Down Expand Up @@ -361,6 +367,10 @@ fn unix_stream_shutdown_both() {
}

#[test]
#[cfg_attr(
target_os = "solaris",
ignore = "POLLRDHUP isn't supported on Solaris"
)]
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 48eceef

Please sign in to comment.