mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-16 00:00:12 +02:00
Fix non-terminating loop in tokio_io::length_delimited::FramedWrite (#576)
* tokio-io: fix non-terminating loop in length_delimited::FramedWrite (#497)
This commit is contained in:
committed by
Toby Lawrence
parent
a7b053372f
commit
bc91bc5022
@@ -473,6 +473,16 @@ fn write_update_max_frame_len_in_flight() {
|
||||
assert!(io.get_ref().calls.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_zero() {
|
||||
let mut io = length_delimited::Builder::new()
|
||||
.new_write(mock! { });
|
||||
|
||||
assert!(io.start_send(Bytes::from("abcdef")).unwrap().is_ready());
|
||||
assert_eq!(io.poll_complete().unwrap_err().kind(), io::ErrorKind::WriteZero);
|
||||
assert!(io.get_ref().calls.is_empty());
|
||||
}
|
||||
|
||||
// ===== Test utils =====
|
||||
|
||||
fn would_block() -> io::Error {
|
||||
|
||||
@@ -455,7 +455,12 @@ impl<T: AsyncWrite, B: IntoBuf> FramedWrite<T, B> {
|
||||
|
||||
loop {
|
||||
let frame = self.frame.as_mut().unwrap();
|
||||
try_ready!(self.inner.write_buf(frame));
|
||||
if try_ready!(self.inner.write_buf(frame)) == 0 {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::WriteZero,
|
||||
"failed to write frame to transport",
|
||||
));
|
||||
}
|
||||
|
||||
if !frame.has_remaining() {
|
||||
break;
|
||||
|
||||
@@ -433,6 +433,16 @@ fn write_max_frame_len() {
|
||||
assert!(io.get_ref().calls.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_zero() {
|
||||
let mut io = Builder::new()
|
||||
.new_write(mock! { });
|
||||
|
||||
assert!(io.start_send("abcdef").unwrap().is_ready());
|
||||
assert_eq!(io.poll_complete().unwrap_err().kind(), io::ErrorKind::WriteZero);
|
||||
assert!(io.get_ref().calls.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_update_max_frame_len_at_rest() {
|
||||
let mut io = Builder::new()
|
||||
|
||||
Reference in New Issue
Block a user