Skip to content

Commit

Permalink
Fix connection_verbose to log write_vectored calls (#1737)
Browse files Browse the repository at this point in the history
Closes #1723
  • Loading branch information
phankydn committed Jan 31, 2023
1 parent 3459b89 commit bdd4db0
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/connect.rs
Expand Up @@ -831,6 +831,7 @@ mod socks {

mod verbose {
use hyper::client::connect::{Connected, Connection};
use std::cmp::min;
use std::fmt;
use std::io::{self, IoSlice};
use std::pin::Pin;
Expand Down Expand Up @@ -905,7 +906,18 @@ mod verbose {
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, io::Error>> {
Pin::new(&mut self.inner).poll_write_vectored(cx, bufs)
match Pin::new(&mut self.inner).poll_write_vectored(cx, bufs) {
Poll::Ready(Ok(nwritten)) => {
log::trace!(
"{:08x} write (vectored): {:?}",
self.id,
Vectored { bufs, nwritten }
);
Poll::Ready(Ok(nwritten))
}
Poll::Ready(Err(e)) => Poll::Ready(Err(e)),
Poll::Pending => Poll::Pending,
}
}

fn is_write_vectored(&self) -> bool {
Expand Down Expand Up @@ -955,6 +967,26 @@ mod verbose {
Ok(())
}
}

struct Vectored<'a, 'b> {
bufs: &'a [IoSlice<'b>],
nwritten: usize,
}

impl fmt::Debug for Vectored<'_, '_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut left = self.nwritten;
for buf in self.bufs.iter() {
if left == 0 {
break;
}
let n = min(left, buf.len());
Escape(&buf[..n]).fmt(f)?;
left -= n;
}
Ok(())
}
}
}

#[cfg(feature = "__tls")]
Expand Down

0 comments on commit bdd4db0

Please sign in to comment.