From 24a4d76374b0901d2105f6191d0d61979066bb0d Mon Sep 17 00:00:00 2001 From: vikigenius Date: Sun, 15 Sep 2024 21:16:54 -0400 Subject: [PATCH] Added readiness and interest for interrupt --- src/loop_logic.rs | 1 + src/sys.rs | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/loop_logic.rs b/src/loop_logic.rs index a1c5ebaa..5b3d3dc5 100644 --- a/src/loop_logic.rs +++ b/src/loop_logic.rs @@ -1630,6 +1630,7 @@ mod tests { Readiness { readable: true, writable: false, + interrupted: false, error: false, }, token, diff --git a/src/sys.rs b/src/sys.rs index 2efe6ab1..7b20d8cd 100644 --- a/src/sys.rs +++ b/src/sys.rs @@ -56,6 +56,9 @@ pub struct Interest { /// Wait for the FD to be writable pub writable: bool, + + /// Wait for the FD to be interrupted + pub interrupted: bool, } impl Interest { @@ -63,24 +66,35 @@ impl Interest { pub const EMPTY: Interest = Interest { readable: false, writable: false, + interrupted: false, }; /// Shorthand for read interest pub const READ: Interest = Interest { readable: true, writable: false, + interrupted: false, }; /// Shorthand for write interest pub const WRITE: Interest = Interest { readable: false, writable: true, + interrupted: false, + }; + + /// Shorthand for interrupt interest + pub const INTERRUPT: Interest = Interest { + readable: false, + writable: false, + interrupted: true, }; /// Shorthand for read and write interest - pub const BOTH: Interest = Interest { + pub const ALL: Interest = Interest { readable: true, writable: true, + interrupted: true, }; } @@ -93,6 +107,9 @@ pub struct Readiness { /// Is the FD writable pub writable: bool, + /// Is the FD interrupted + pub interrupted: bool, + /// Is the FD in an error state pub error: bool, } @@ -102,6 +119,7 @@ impl Readiness { pub const EMPTY: Readiness = Readiness { readable: false, writable: false, + interrupted: false, error: false, }; } @@ -252,6 +270,7 @@ impl Poll { readiness: Readiness { readable: ev.readable, writable: ev.writable, + interrupted: ev.is_interrupt(), error: false, }, token: Token { @@ -271,6 +290,7 @@ impl Poll { readiness: Readiness { readable: true, writable: false, + interrupted: false, error: false, }, token, @@ -431,6 +451,7 @@ fn cvt_interest(interest: Interest, tok: Token) -> Event { let mut event = Event::none(tok.inner.into()); event.readable = interest.readable; event.writable = interest.writable; + event.set_interrupt(interest.interrupted); event }