@@ -145,42 +145,16 @@ fn handle_timeout_event(timeout_event: ClockEventData, events: &mut Vec<types::E
145145
146146fn handle_rw_event ( event : FdEventData , out_events : & mut Vec < types:: Event > ) {
147147 let handle = & event. handle ;
148- let size = if let Some ( file) = handle. as_any ( ) . downcast_ref :: < OsFile > ( ) {
149- if event. r#type == types:: Eventtype :: FdRead {
150- file. as_file ( )
151- . metadata ( )
152- . map ( |m| m. len ( ) )
153- . map_err ( Into :: into)
154- } else {
155- // The spec is unclear what nbytes should actually be for __WASI_EVENTTYPE_FD_WRITE and
156- // the implementation on Unix just returns 0 here, so it's probably fine
157- // to do the same on Windows for now.
158- // cf. https://github.com/WebAssembly/WASI/issues/148
159- Ok ( 0 )
160- }
161- } else if let Some ( dir) = handle. as_any ( ) . downcast_ref :: < OsDir > ( ) {
162- if event. r#type == types:: Eventtype :: FdRead {
163- dir. as_file ( )
164- . metadata ( )
165- . map ( |m| m. len ( ) )
166- . map_err ( Into :: into)
167- } else {
168- // The spec is unclear what nbytes should actually be for __WASI_EVENTTYPE_FD_WRITE and
169- // the implementation on Unix just returns 0 here, so it's probably fine
170- // to do the same on Windows for now.
171- // cf. https://github.com/WebAssembly/WASI/issues/148
172- Ok ( 0 )
173- }
174- } else if let Some ( stdio) = handle. as_any ( ) . downcast_ref :: < Stdio > ( ) {
148+ let size = if let Some ( stdio) = handle. as_any ( ) . downcast_ref :: < Stdio > ( ) {
175149 match stdio {
176150 // We return the only universally correct lower bound, see the comment later in the function.
177151 Stdio :: In { .. } => Ok ( 1 ) ,
178152 // On Unix, ioctl(FIONREAD) will return 0 for stdout/stderr. Emulate the same behavior on Windows.
179153 Stdio :: Out { .. } | Stdio :: Err { .. } => Ok ( 0 ) ,
180154 }
181- } else if let Some ( other ) = handle . as_any ( ) . downcast_ref :: < OsOther > ( ) {
155+ } else {
182156 if event. r#type == types:: Eventtype :: FdRead {
183- other
157+ handle
184158 . as_file ( )
185159 . metadata ( )
186160 . map ( |m| m. len ( ) )
@@ -192,10 +166,7 @@ fn handle_rw_event(event: FdEventData, out_events: &mut Vec<types::Event>) {
192166 // cf. https://github.com/WebAssembly/WASI/issues/148
193167 Ok ( 0 )
194168 }
195- } else {
196- panic ! ( "can poll FdEvent for OS resources only" )
197169 } ;
198-
199170 let new_event = make_rw_event ( & event, size) ;
200171 out_events. push ( new_event) ;
201172}
0 commit comments