@@ -132,6 +132,22 @@ impl<'a> Stream where Self: CaptureStream<'a> {
132132 let meta = self . buf_meta [ index] ;
133133 Ok ( ( buf, meta) )
134134 }
135+
136+ /// Waits for a buffer to be ready
137+ pub fn wait ( & self ) -> Result < ( ) , io:: Error > {
138+ if self . handle . poll ( libc:: POLLIN , -1 ) ? == 0 {
139+ // This condition can only happen if there was a timeout.
140+ // A timeout is only possible if the `timeout` value is non-zero, meaning we should
141+ // propagate it to the caller.
142+ return Err ( io:: Error :: new ( io:: ErrorKind :: TimedOut , "Blocking poll" ) ) ;
143+ }
144+ Ok ( ( ) )
145+ }
146+
147+ /// Waits for a buffer to be ready
148+ pub fn is_ready ( & self ) -> Result < bool , io:: Error > {
149+ Ok ( self . handle . poll ( libc:: POLLIN , 0 ) ? > 0 )
150+ }
135151}
136152
137153impl Drop for Stream {
@@ -236,7 +252,7 @@ impl<'a> CaptureStream<'a> for Stream {
236252 Ok ( self . arena_index )
237253 }
238254
239- fn next ( & ' a mut self ) -> io:: Result < ( & Self :: Item , & Metadata ) > {
255+ fn next ( & ' a mut self ) -> io:: Result < ( & Self :: Item , & Metadata , bool ) > {
240256 if !self . active {
241257 // Enqueue all buffers once on stream start
242258 for index in 0 ..self . arena . bufs . len ( ) {
@@ -254,6 +270,6 @@ impl<'a> CaptureStream<'a> for Stream {
254270 // will always be valid.
255271 let bytes = & mut self . arena . bufs [ self . arena_index ] . as_ref ( ) . unwrap ( ) ;
256272 let meta = & self . buf_meta [ self . arena_index ] ;
257- Ok ( ( bytes, meta) )
273+ Ok ( ( bytes, meta, self . is_ready ( ) ? ) )
258274 }
259275}
0 commit comments