Skip to content

Commit 282edd3

Browse files
committed
Add Interest::PRIORITY
This adds a PRIORITY interest, that is supported on linux. This makes priority events work on TcpStream again.
1 parent db776d9 commit 282edd3

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

src/interest.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const AIO: u8 = 0b0100;
3333
#[cfg_attr(not(target_os = "freebsd"), allow(dead_code))]
3434
const LIO: u8 = 0b1000;
3535

36+
const PRIORITY: u8 = 0b10000;
37+
3638
impl Interest {
3739
/// Returns a `Interest` set representing readable interests.
3840
pub const READABLE: Interest = Interest(unsafe { NonZeroU8::new_unchecked(READABLE) });
@@ -53,6 +55,9 @@ impl Interest {
5355
#[cfg(target_os = "freebsd")]
5456
pub const LIO: Interest = Interest(unsafe { NonZeroU8::new_unchecked(LIO) });
5557

58+
/// Returns a `Interest` set representing priority interests.
59+
pub const PRIORITY: Interest = Interest(unsafe { NonZeroU8::new_unchecked(PRIORITY) });
60+
5661
/// Add together two `Interest`.
5762
///
5863
/// This does the same thing as the `BitOr` implementation, but is a
@@ -113,6 +118,11 @@ impl Interest {
113118
pub const fn is_lio(self) -> bool {
114119
(self.0.get() & LIO) != 0
115120
}
121+
122+
/// Returns true if `Interest` contains PRIORITY readiness
123+
pub const fn is_priority(self) -> bool {
124+
(self.0.get() & PRIORITY) != 0
125+
}
116126
}
117127

118128
impl ops::BitOr for Interest {
@@ -173,6 +183,13 @@ impl fmt::Debug for Interest {
173183
one = true
174184
}
175185
}
186+
if self.is_priority() {
187+
if one {
188+
write!(fmt, " | ")?
189+
}
190+
write!(fmt, "PRIORITY")?;
191+
one = true
192+
}
176193
debug_assert!(one, "printing empty interests");
177194
Ok(())
178195
}

src/sys/unix/selector/epoll.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{Interest, Token};
22

3-
use libc::{EPOLLET, EPOLLIN, EPOLLOUT, EPOLLRDHUP};
3+
use libc::{EPOLLET, EPOLLIN, EPOLLOUT, EPOLLPRI, EPOLLRDHUP};
44
use log::error;
55
use std::os::unix::io::{AsRawFd, RawFd};
66
#[cfg(debug_assertions)]
@@ -177,6 +177,10 @@ fn interests_to_epoll(interests: Interest) -> u32 {
177177
kind |= EPOLLOUT;
178178
}
179179

180+
if interests.is_priority() {
181+
kind |= EPOLLPRI;
182+
}
183+
180184
kind as u32
181185
}
182186

tests/tcp_stream.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,11 @@ fn pollpri() {
832832

833833
let (mut sock, _) = listener.accept().unwrap();
834834
poll.registry()
835-
.register(&mut sock, Token(1), Interest::READABLE)
835+
.register(
836+
&mut sock,
837+
Token(1),
838+
Interest::READABLE.add(Interest::PRIORITY),
839+
)
836840
.unwrap();
837841

838842
// MsgFlags::MSG_OOB sends a tcp packet which is received by linux kernel with
@@ -841,6 +845,6 @@ fn pollpri() {
841845
expect_events(
842846
&mut poll,
843847
&mut events,
844-
vec![ExpectEvent::new(Token(1), Readiness::PRIORITY)],
848+
vec![ExpectEvent::new(Token(1), Interest::PRIORITY)],
845849
);
846850
}

tests/util/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ impl From<Interest> for Readiness {
130130
if interests.is_lio() {
131131
readiness.0 |= LIO;
132132
}
133+
if interests.is_priority() {
134+
readiness.0 |= PRIORITY;
135+
}
133136
readiness
134137
}
135138
}

0 commit comments

Comments
 (0)