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 27, 2022
1 parent 2d90ef5 commit 0f9dff3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
3 changes: 1 addition & 2 deletions tokio/Cargo.toml
Expand Up @@ -97,8 +97,7 @@ bytes = { version = "1.0.0", optional = true }
once_cell = { version = "1.5.2", optional = true }
memchr = { version = "2.2", optional = true }
#mio = { version = "0.8.1", optional = true }
mio = { path = "../../mio", optional = true }
#socket2 = { version = "0.4.4", optional = true, features = [ "all" ] }
mio = { git = "https://github.com/rjzak/mio/", branch = "wasi_wip", optional = true }
num_cpus = { version = "1.8.0", optional = true }
parking_lot = { version = "0.12.0", optional = true }

Expand Down
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 0f9dff3

Please sign in to comment.