This function flushes the content of the buffer to the out device if it is allowed to, otherwise this is a no-op.
(&mut self)
| 96 | // This function flushes the content of the buffer to the out device if |
| 97 | // it is allowed to, otherwise this is a no-op. |
| 98 | fn flush(&mut self) -> Result<(), std::io::Error> { |
| 99 | if !self.write_out.load(Ordering::Acquire) { |
| 100 | return Ok(()); |
| 101 | } |
| 102 | |
| 103 | while let Some(byte) = self.buffer.pop_front() { |
| 104 | if self.out.write_all(&[byte]).is_err() { |
| 105 | self.buffer.push_front(byte); |
| 106 | break; |
| 107 | } |
| 108 | } |
| 109 | self.out.flush() |
| 110 | } |
| 111 | } |