| 269 | /// Try to write all queued bytes without blocking. |
| 270 | /// |
| 271 | /// Returns `true` when the queue is empty. |
| 272 | pub fn flush_pending(&mut self) -> NetResult<bool> { |
| 273 | while let Some(bytes) = self.tx_queue.front() { |
| 274 | match self.stream.write(&bytes[self.tx_cursor..]) { |
| 275 | Ok(0) => { |
| 276 | return Err(NetError::new( |
| 277 | NetErrorKind::Send, |
| 278 | "tcp stream wrote zero bytes", |
| 279 | )); |
| 280 | } |
| 281 | Ok(n) => { |
| 282 | self.tx_cursor += n; |
| 283 | if self.tx_cursor == bytes.len() { |
| 284 | self.tx_queue.pop_front(); |
| 285 | self.tx_cursor = 0; |