Skip to content

Commit 8c1cd34

Browse files
committed
Update http1 an h2 dispatchers to use the new body progress API.
This is a WIP, and the tests are not yet updated.
1 parent 961d221 commit 8c1cd34

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

src/proto/h1/dispatch.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,24 @@ where
385385
}
386386

387387
fn poll_flush(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
388-
self.conn.poll_flush(cx).map_err(|err| {
389-
debug!("error writing: {}", err);
390-
crate::Error::new_body_write(err)
391-
})
388+
if let Poll::Ready(res) = self.conn.poll_flush(cx) {
389+
return Poll::Ready(res.map_err(|err| {
390+
debug!("error writing: {}", err);
391+
crate::Error::new_body_write(err)
392+
}));
393+
}
394+
395+
// Drop the body_rx if it's done.
396+
if let (Some(body), clear_body) =
397+
OptGuard::new(self.body_rx.as_mut()).guard_mut()
398+
{
399+
if let Poll::Ready(Err(e)) = body.poll_progress(cx) {
400+
*clear_body = true;
401+
return Poll::Ready(Err(crate::Error::new_user_body(e)));
402+
}
403+
}
404+
405+
Poll::Pending
392406
}
393407

394408
fn close(&mut self) {

src/proto/h2/mod.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,30 @@ where
128128

129129
if me.body_tx.capacity() == 0 {
130130
loop {
131-
match ready!(me.body_tx.poll_capacity(cx)) {
132-
Some(Ok(0)) => {}
133-
Some(Ok(_)) => break,
134-
Some(Err(e)) => {
131+
match me.body_tx.poll_capacity(cx) {
132+
Poll::Ready(Some(Ok(0))) => continue,
133+
Poll::Ready(Some(Ok(_))) => break,
134+
Poll::Ready(Some(Err(e))) => {
135135
return Poll::Ready(Err(crate::Error::new_body_write(e)))
136136
}
137-
None => {
137+
Poll::Ready(None) => {
138138
// None means the stream is no longer in a
139139
// streaming state, we either finished it
140140
// somehow, or the remote reset us.
141141
return Poll::Ready(Err(crate::Error::new_body_write(
142142
"send stream capacity unexpectedly closed",
143143
)));
144144
}
145+
Poll::Pending => {
146+
// If we're waiting for capacity, poll the body stream
147+
// to see if it's been canceled.
148+
return match me.stream.as_mut().poll_progress(cx) {
149+
Poll::Ready(Err(e)) => {
150+
Poll::Ready(Err(me.body_tx.on_user_err(e)))
151+
}
152+
_ => Poll::Pending,
153+
};
154+
}
145155
}
146156
}
147157
} else if let Poll::Ready(reason) = me

0 commit comments

Comments
 (0)