Skip to content

Commit

Permalink
Log from all buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
anhcuky committed Jan 29, 2023
1 parent 1550899 commit 09d6903
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions 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 @@ -906,13 +907,9 @@ mod verbose {
bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, io::Error>> {
match Pin::new(&mut self.inner).poll_write_vectored(cx, bufs) {
Poll::Ready(Ok(n)) => {
let buf = bufs
.iter()
.find(|b| !b.is_empty())
.map_or(&[][..], |b| &**b);
log::trace!("{:08x} write: {:?}", self.id, Escape(&buf[..n]));
Poll::Ready(Ok(n))
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,
Expand Down Expand Up @@ -966,6 +963,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 09d6903

Please sign in to comment.