From 6fbf73aa6a7fad0ecebbd52287e5608704e323b6 Mon Sep 17 00:00:00 2001
From: Patrick Mooney <pmooney@pfmooney.com>
Date: Tue, 14 Apr 2020 03:23:16 +0000
Subject: [PATCH] Add support for illumos target

---
 Cargo.toml                |  2 +-
 src/sys/unix/mod.rs       | 14 ++++++++++--
 src/sys/unix/ready.rs     | 45 +++++++++++++++++++++++++++++++--------
 test/test_tcp_shutdown.rs | 26 ++++++++++++++++------
 4 files changed, 69 insertions(+), 18 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 948df6556..3c992afa9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -38,7 +38,7 @@ fuchsia-zircon = "0.3.2"
 fuchsia-zircon-sys = "0.3.2"
 
 [target.'cfg(unix)'.dependencies]
-libc   = "0.2.42"
+libc   = "0.2.54"
 
 [target.'cfg(windows)'.dependencies]
 winapi = "0.2.6"
diff --git a/src/sys/unix/mod.rs b/src/sys/unix/mod.rs
index 5bb83070d..c5726c07c 100644
--- a/src/sys/unix/mod.rs
+++ b/src/sys/unix/mod.rs
@@ -3,10 +3,20 @@ use libc::{self, c_int};
 #[macro_use]
 pub mod dlsym;
 
-#[cfg(any(target_os = "linux", target_os = "android", target_os = "solaris"))]
+#[cfg(any(
+    target_os = "android",
+    target_os = "illumos",
+    target_os = "linux",
+    target_os = "solaris"
+))]
 mod epoll;
 
-#[cfg(any(target_os = "linux", target_os = "android", target_os = "solaris"))]
+#[cfg(any(
+    target_os = "android",
+    target_os = "illumos",
+    target_os = "linux",
+    target_os = "solaris"
+))]
 pub use self::epoll::{Events, Selector};
 
 #[cfg(any(target_os = "bitrig", target_os = "dragonfly",
diff --git a/src/sys/unix/ready.rs b/src/sys/unix/ready.rs
index 1780ceae9..ef9014766 100644
--- a/src/sys/unix/ready.rs
+++ b/src/sys/unix/ready.rs
@@ -109,10 +109,20 @@ const LIO: usize   = 0b10_0000;
 #[cfg(not(any(target_os = "freebsd")))]
 const LIO: usize   = 0b00_0000;
 
-#[cfg(any(target_os = "linux", target_os = "android", target_os = "solaris"))]
+#[cfg(any(
+    target_os = "android",
+    target_os = "illumos",
+    target_os = "linux",
+    target_os = "solaris"
+))]
 const PRI: usize = 0b100_0000;
 
-#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "solaris")))]
+#[cfg(not(any(
+    target_os = "android",
+    target_os = "illumos",
+    target_os = "linux",
+    target_os = "solaris"
+)))]
 const PRI: usize = 0;
 
 // Export to support `Ready::all`
@@ -129,7 +139,12 @@ fn test_ready_all() {
     );
 
     // Issue #896.
-    #[cfg(any(target_os = "linux", target_os = "android", target_os = "solaris"))]
+    #[cfg(any(
+        target_os = "android",
+        target_os = "illumos",
+        target_os = "linux",
+        target_os = "solaris"
+    ))]
     assert!(!Ready::from(UnixReady::priority()).is_writable());
 }
 
@@ -258,8 +273,12 @@ impl UnixReady {
     ///
     /// [`Poll`]: struct.Poll.html
     #[inline]
-    #[cfg(any(target_os = "linux",
-        target_os = "android", target_os = "solaris"))]
+    #[cfg(any(
+        target_os = "android",
+        target_os = "illumos",
+        target_os = "linux",
+        target_os = "solaris"
+    ))]
     pub fn priority() -> UnixReady {
         UnixReady(ready_from_usize(PRI))
     }
@@ -385,8 +404,12 @@ impl UnixReady {
     ///
     /// [`Poll`]: struct.Poll.html
     #[inline]
-    #[cfg(any(target_os = "linux",
-        target_os = "android", target_os = "solaris"))]
+    #[cfg(any(
+        target_os = "android",
+        target_os = "illumos",
+        target_os = "linux",
+        target_os = "solaris"
+    ))]
     pub fn is_priority(&self) -> bool {
         self.contains(ready_from_usize(PRI))
     }
@@ -476,8 +499,12 @@ impl fmt::Debug for UnixReady {
             (UnixReady::hup(), "Hup"),
             #[allow(deprecated)]
             (UnixReady::aio(), "Aio"),
-            #[cfg(any(target_os = "linux",
-                target_os = "android", target_os = "solaris"))]
+            #[cfg(any(
+                target_os = "android",
+                target_os = "illumos",
+                target_os = "linux",
+                target_os = "solaris"
+            ))]
             (UnixReady::priority(), "Priority"),
         ];
 
diff --git a/test/test_tcp_shutdown.rs b/test/test_tcp_shutdown.rs
index 9363f8340..d97e6eda2 100644
--- a/test/test_tcp_shutdown.rs
+++ b/test/test_tcp_shutdown.rs
@@ -200,9 +200,16 @@ fn test_graceful_shutdown() {
     drop(socket);
 
     assert_ready!(poll, Token(0), Ready::readable());
-    #[cfg(not(any(target_os = "bitrig", target_os = "dragonfly",
-        target_os = "freebsd", target_os = "ios", target_os = "macos",
-        target_os = "netbsd", target_os = "openbsd")))]
+    #[cfg(not(any(
+        target_os = "bitrig",
+        target_os = "dragonfly",
+        target_os = "freebsd",
+        target_os = "illumos",
+        target_os = "ios",
+        target_os = "macos",
+        target_os = "netbsd",
+        target_os = "openbsd"
+    )))]
     assert_hup_ready!(poll);
 
     let mut buf = [0; 1024];
@@ -236,9 +243,16 @@ fn test_abrupt_shutdown() {
 
     drop(socket);
 
-    #[cfg(not(any(target_os = "bitrig", target_os = "dragonfly",
-        target_os = "freebsd", target_os = "ios", target_os = "macos",
-        target_os = "netbsd", target_os = "openbsd")))]
+    #[cfg(not(any(
+        target_os = "bitrig",
+        target_os = "dragonfly",
+        target_os = "freebsd",
+        target_os = "illumos",
+        target_os = "ios",
+        target_os = "macos",
+        target_os = "netbsd",
+        target_os = "openbsd"
+    )))]
     assert_hup_ready!(poll);
     assert_ready!(poll, Token(0), Ready::writable());
     assert_ready!(poll, Token(0), Ready::readable());