Skip to content

Commit

Permalink
Added print statements to trace execution
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Zak <richard@profian.com>
  • Loading branch information
rjzak committed May 25, 2022
1 parent 2d90ef5 commit daaab6c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 3 additions & 1 deletion tokio/src/io/driver/registration.rs
Expand Up @@ -247,12 +247,14 @@ cfg_io_readiness! {
}

pub(crate) async fn async_io<R>(&self, interest: Interest, mut f: impl FnMut() -> io::Result<R>) -> io::Result<R> {
println!("Tokio Registration::async_io() {}:{}", file!(), line!());
loop {
let event = self.readiness(interest).await?;

println!("Tokio Registration::async_io() self.readiness({:?}) = {:?} returned @ {}:{}", interest, event, file!(), line!());
match f() {
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
self.clear_readiness(event);
println!("Tokio Registration::async_io() self.clear_readiness() {}:{}", file!(), line!());
}
x => return x,
}
Expand Down
23 changes: 22 additions & 1 deletion tokio/src/net/tcp/listener.rs
Expand Up @@ -158,13 +158,34 @@ impl TcpListener {
/// }
/// ```
pub async fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
println!("Tokio TcpListener::accept() {}:{}", file!(), line!());
let (mio, addr) = self
.io
.registration()
.async_io(Interest::READABLE, || self.io.accept())
.await?;

println!("Tokio TcpListener::accept() self.io.registration().async_io().await {}:{}", file!(), line!());
let mut small_buffer = [0u8;200];
match mio.peek(&mut small_buffer) {
Ok(x) => {
let buffer_string = String::from_utf8_lossy(&small_buffer[..x]).to_string();
println!("Tokio TcpListener::accept() buffer {} size {} @ {}:{}", buffer_string, x, file!(), line!());
}
Err(e) => {
println!("Tokio TcpListener::accept() error {} trying to peek() at the buffer {}:{}", e, file!(), line!());
}
}
let stream = TcpStream::new(mio)?;
match stream.try_read(&mut small_buffer) {
Ok(x) => {
let buffer_string = String::from_utf8_lossy(&small_buffer[..x]).to_string();
println!("Tokio TcpListener::accept() buffer after TcpStream::new(): {} size {} @ {}:{}", buffer_string, x, file!(), line!());
}
Err(e) => {
println!("Tokio TcpListener::accept() error {} trying to TcpStream::try_read() at the buffer {}:{}", e, file!(), line!());
}
}
println!("Tokio TcpListener::accept() TcpStream::new() {}:{}", file!(), line!());
Ok((stream, addr))
}

Expand Down

0 comments on commit daaab6c

Please sign in to comment.