File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -223,13 +223,17 @@ impl io::Read for COMPort {
223223 fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
224224 let mut read_size = buf. len ( ) ;
225225
226- let bytes_to_read = self . bytes_to_read ( ) ? as usize ;
227-
228- if self . timeout . as_millis ( ) == 0 && bytes_to_read < read_size {
229- read_size = bytes_to_read;
230- }
231- if read_size == 0 {
232- return Ok ( 0 ) ;
226+ if self . timeout . as_secs ( ) == 0 && self . timeout . subsec_nanos ( ) == 0 {
227+ //If zero timeout then make sure we can read, before proceeding
228+ //Note that zero timeout will make read operation to wait until at least
229+ //1 byte becomes available.
230+ let bytes_to_read = self . bytes_to_read ( ) ? as usize ;
231+ if bytes_to_read < read_size {
232+ read_size = bytes_to_read;
233+ }
234+ if read_size == 0 {
235+ return Ok ( 0 ) ;
236+ }
233237 }
234238
235239 let evt_handle = OverlappedHandle :: new ( ) ?;
You can’t perform that action at this time.
0 commit comments