mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-07 00:00:08 +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());
|
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 =====
|
// ===== Test utils =====
|
||||||
|
|
||||||
fn would_block() -> io::Error {
|
fn would_block() -> io::Error {
|
||||||
|
|||||||
@@ -455,7 +455,12 @@ impl<T: AsyncWrite, B: IntoBuf> FramedWrite<T, B> {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
let frame = self.frame.as_mut().unwrap();
|
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() {
|
if !frame.has_remaining() {
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -433,6 +433,16 @@ fn write_max_frame_len() {
|
|||||||
assert!(io.get_ref().calls.is_empty());
|
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]
|
#[test]
|
||||||
fn write_update_max_frame_len_at_rest() {
|
fn write_update_max_frame_len_at_rest() {
|
||||||
let mut io = Builder::new()
|
let mut io = Builder::new()
|
||||||
|
|||||||
Reference in New Issue
Block a user