Skip to content

Commit 8f938d9

Browse files
committed
fix(conn): handle when pre-emptive flushing closes the write state
Closes #1391
1 parent eb9590e commit 8f938d9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/proto/conn.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,9 @@ where I: AsyncRead + AsyncWrite,
196196
}
197197

198198
},
199-
Reading::Init | Reading::KeepAlive | Reading::Closed => unreachable!()
199+
_ => unreachable!("read_body invalid state: {:?}", self.state.reading),
200200
};
201+
201202
self.state.reading = reading;
202203
ret
203204
}
@@ -324,6 +325,14 @@ where I: AsyncRead + AsyncWrite,
324325

325326
if self.has_queued_body() {
326327
try!(self.flush());
328+
329+
if !self.can_write_body() {
330+
if chunk.as_ref().map(|c| c.as_ref().len()).unwrap_or(0) == 0 {
331+
return Ok(AsyncSink::NotReady(chunk));
332+
} else {
333+
return Ok(AsyncSink::Ready);
334+
}
335+
}
327336
}
328337

329338
let state = match self.state.writing {
@@ -369,8 +378,9 @@ where I: AsyncRead + AsyncWrite,
369378
}
370379
}
371380
},
372-
_ => unreachable!(),
381+
_ => unreachable!("write_body invalid state: {:?}", self.state.writing),
373382
};
383+
374384
self.state.writing = state;
375385
Ok(AsyncSink::Ready)
376386
}

0 commit comments

Comments
 (0)