File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed
Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -31,8 +31,9 @@ pub(crate) const WRITABLE: u32 = c::EPOLLOUT as u32;
3131pub ( crate ) const ERROR : u32 = ( c:: EPOLLERR | c:: EPOLLHUP ) as u32 ;
3232
3333const ONESHOT : u32 = c:: EPOLLONESHOT as u32 ;
34+ const ET : u32 = c:: EPOLLET as u32 ;
3435
35- const ALL : u32 = READABLE | WRITABLE | ERROR | ONESHOT ;
36+ const ALL : u32 = READABLE | WRITABLE | ERROR | ONESHOT | ET ;
3637
3738#[ derive( Copy , Clone , Default ) ]
3839pub ( crate ) struct PollEvent {
@@ -127,4 +128,24 @@ impl Poller {
127128 )
128129 . map_err ( |e| PollError :: Update ( e. into ( ) ) )
129130 }
131+
132+ #[ cfg_attr( not( test) , expect( dead_code) ) ]
133+ pub ( crate ) fn register_edge_triggered (
134+ & self ,
135+ id : u64 ,
136+ fd : BorrowedFd < ' _ > ,
137+ events : u32 ,
138+ ) -> Result < ( ) , PollError > {
139+ let event = c:: epoll_event {
140+ events : events | ET ,
141+ u64 : id,
142+ } ;
143+ uapi:: epoll_ctl (
144+ self . epoll . as_raw_fd ( ) ,
145+ c:: EPOLL_CTL_ADD ,
146+ fd. as_raw_fd ( ) ,
147+ Some ( & event) ,
148+ )
149+ . map_err ( |e| PollError :: Add ( e. into ( ) ) )
150+ }
130151}
Original file line number Diff line number Diff line change @@ -63,3 +63,28 @@ fn many() {
6363 assert ! ( seen_ids. contains( & ( i as u64 ) ) ) ;
6464 }
6565}
66+
67+ #[ test]
68+ fn edge_trigger ( ) {
69+ let epoll = Poller :: new ( ) . unwrap ( ) ;
70+ let ( r, mut w) = pipe ( ) . unwrap ( ) ;
71+ let r: OwnedFd = r. into ( ) ;
72+ epoll
73+ . register_edge_triggered ( 1 , r. as_fd ( ) , READABLE )
74+ . unwrap ( ) ;
75+ let mut events = [ PollEvent :: default ( ) ; MAX_EVENTS ] ;
76+ let n = epoll. read_events ( 0 , & mut events) . unwrap ( ) ;
77+ assert_eq ! ( n, 0 ) ;
78+ w. write_all ( & [ 0 ] ) . unwrap ( ) ;
79+ let n = epoll. read_events ( 0 , & mut events) . unwrap ( ) ;
80+ assert_eq ! ( n, 1 ) ;
81+ assert_eq ! ( events[ 0 ] . u64 , 1 ) ;
82+ let n = epoll. read_events ( 0 , & mut events) . unwrap ( ) ;
83+ assert_eq ! ( n, 0 ) ;
84+ w. write_all ( & [ 0 ] ) . unwrap ( ) ;
85+ let n = epoll. read_events ( 0 , & mut events) . unwrap ( ) ;
86+ assert_eq ! ( n, 1 ) ;
87+ assert_eq ! ( events[ 0 ] . u64 , 1 ) ;
88+ let n = epoll. read_events ( 0 , & mut events) . unwrap ( ) ;
89+ assert_eq ! ( n, 0 ) ;
90+ }
You can’t perform that action at this time.
0 commit comments