CodeVetter · Repo Unpack · Behavior traces
tokio-rs/tokio
Three principal flows were followed through implementation: runtime startup, TCP connection handling, and filesystem writing. Startup selects an executor and creates its drivers before running user futures. Networking follows resolution, registration, readiness, and socket operations. Filesystem writing branches between blocking and experimental io-uring execution, with additional completion boundaries for buffered File writes.
- Startup: parse_knobs removes asyncness, chooses the configured Builder flavor, applies options, then emits enable_all → build/build_local → expect → block_on.
- Multi-thread startup: build → build_threaded_runtime → Driver::new → create_blocking_pool → MultiThread::new → handle.enter → launch.launch → Runtime::from_parts.
- Execution: Runtime::block_on → block_on_inner → enter → scheduler.block_on; MultiThread enters runtime context and drives the root future on the calling thread.
- TCP bind: TcpListener::bind → to_socket_addrs → sequential bind_addr attempts → Mio bind → TcpListener::new → PollEvented registration; empty resolution returns InvalidInput.
- TCP accept: accept → Registration::async_io(READABLE) → readiness and cooperative budget → Mio accept → new_accepted; WouldBlock clears readiness, and accepted streams initially assume read/write readiness.
- Echo flow: echo_server binds loopback, spawns a client performing write_all/read_exact, accepts and splits the server stream, copies read-to-write, then checks byte count and completion.
- Whole-file persistence: fs::write upgrades contents; eligible Linux builds probe io-uring Write support, otherwise write_spawn_blocking → asyncify → spawn_blocking → std::fs::write.
- Buffered persistence: File::poll_write copies bytes and starts mandatory blocking work before returning; poll_flush joins Busy work, while sync_all first completes in-flight work and calls std.sync_all.