@@ -5,6 +5,7 @@ use std::io::{Error, ErrorKind, Read};
55use std:: rc:: { Rc , Weak } ;
66
77use crate :: shims:: unix:: fd:: WeakFileDescriptor ;
8+ use crate :: shims:: unix:: linux:: epoll:: EpollReturn ;
89use crate :: shims:: unix:: * ;
910use crate :: { concurrency:: VClock , * } ;
1011
@@ -37,6 +38,28 @@ impl SocketPair {
3738 fn peer_is_closed ( & mut self ) {
3839 self . peer_closed = true ;
3940 }
41+
42+ /// Functions to update the ready list of an epoll_event.
43+ fn update_readiness ( & self , ready_flags : Vec < u32 > , epoll_events : & Vec < Weak < EpollEvent > > ) {
44+ for event in epoll_events {
45+ // If the current epoll_event contains the flag that is signaled as ready, we add/update
46+ // the epoll_return entry in the ready list.
47+ if let Some ( epoll_event) = event. upgrade ( ) {
48+ if let Some ( flags) = epoll_event. contains_flag ( & ready_flags) {
49+ let weak_file_descriptor = epoll_event. weak_file_descriptor . clone ( ) ;
50+ let epoll_key = ( weak_file_descriptor, epoll_event. file_descriptor ) ;
51+ // Retrieve the epoll return if it is already in the return list.
52+ let ready_list = & mut epoll_event. ready_list . borrow_mut ( ) ;
53+ // Add a new epoll entry if it doesn't exist, or update the event mask if it exists.
54+ let epoll_return = EpollReturn :: new ( flags, epoll_event. data ) ;
55+ let epoll_entry = ready_list. entry ( epoll_key) . or_insert ( epoll_return) ;
56+ // The update here is bitwise or, so it will still be correct if we try to add
57+ // a flag that already exists.
58+ epoll_entry. update_events ( flags) ;
59+ }
60+ }
61+ }
62+ }
4063}
4164
4265#[ derive( Debug ) ]
@@ -91,7 +114,6 @@ impl FileDescription for SocketPair {
91114
92115 fn close < ' tcx > (
93116 self : Box < Self > ,
94- ecx : & mut MiriInterpCx < ' tcx > ,
95117 _communicate_allowed : bool ,
96118 ) -> InterpResult < ' tcx , io:: Result < ( ) > > {
97119 // This is used to signal socketfd of other side that there is no writer to its readbuf.
@@ -107,9 +129,9 @@ impl FileDescription for SocketPair {
107129 let peer_socketpair = binding. downcast_mut :: < SocketPair > ( ) . unwrap ( ) ;
108130 peer_socketpair. peer_is_closed ( ) ;
109131 // When any of the event is happened, we check and update the status of all supported flags.
110- peer_socketpair
111- . check_readiness ( ecx)
112- . map ( |events| ecx. update_readiness ( events, self . return_epoll_events ( ) ?) ) ??;
132+ // peer_socketpair
133+ // .check_readiness(ecx)
134+ // .map(|events| ecx.update_readiness(events, self.return_epoll_events()?))??;
113135 }
114136 }
115137 // TODO: invoke check readiness from other side
@@ -160,7 +182,7 @@ impl FileDescription for SocketPair {
160182 let actual_read_size = readbuf. buf . read ( bytes) . unwrap ( ) ;
161183 // When any of the event is happened, we check and update the status of all supported flags.
162184 self . check_readiness ( ecx)
163- . map ( |events| ecx . update_readiness ( events, self . return_epoll_events ( ) ? ) ) ? ?;
185+ . map ( |events| self . update_readiness ( events, self . return_epoll_events ( ) . unwrap ( ) ) ) ?;
164186 return Ok ( Ok ( actual_read_size) ) ;
165187 }
166188
@@ -203,7 +225,7 @@ impl FileDescription for SocketPair {
203225 writebuf. buf . extend ( & bytes[ ..actual_write_size] ) ;
204226 // When any of the event is happened, we check and update the status of all supported flags.
205227 self . check_readiness ( ecx)
206- . map ( |events| ecx . update_readiness ( events, self . return_epoll_events ( ) ? ) ) ? ?;
228+ . map ( |events| self . update_readiness ( events, self . return_epoll_events ( ) . unwrap ( ) ) ) ?;
207229 return Ok ( Ok ( actual_write_size) ) ;
208230 }
209231}
0 commit comments