1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! Async network primitives.
//!
//! Wraps mio's TCP and UDP types with async read/write backed by the
//! runtime's IO driver. Sockets register with mio lazily on first poll
//! (edge-triggered — register once, no reregistration).
//!
//! # IO Traits
//!
//! [`AsyncRead`] and [`AsyncWrite`] are the core abstractions. They
//! mirror `std::io::Read`/`Write` but return `Poll` and take a `Context`
//! for waker registration. nexus-net codecs program against these traits.
use io;
use Pin;
use ;
pub use ;
pub use UdpSocket;
// =============================================================================
// AsyncRead / AsyncWrite
// =============================================================================
/// Async read half of a byte stream.
///
/// Mirrors `std::io::Read` but returns `Poll` for non-blocking use
/// with the executor.
///
/// # Contract
///
/// - `Poll::Ready(Ok(0))` means EOF — the peer closed its write half.
/// - `Poll::Ready(Ok(n))` means `n` bytes were read into `buf[..n]`.
/// - `Poll::Pending` means no data is available yet — the waker will
/// be notified when the stream becomes readable.
/// - `Poll::Ready(Err(e))` is a fatal IO error.
/// Async write half of a byte stream.
///
/// Mirrors `std::io::Write` but returns `Poll` for non-blocking use.
///
/// # Contract
///
/// - `Poll::Ready(Ok(n))` means `n` bytes from `buf[..n]` were written.
/// - `Poll::Pending` means the write buffer is full — the waker will
/// be notified when the stream becomes writable.
/// - `poll_flush` ensures all buffered data reaches the OS send buffer.
/// - `poll_shutdown` signals that no more data will be written (TCP FIN).
// =============================================================================
// Helper: extract task pointer from waker
// =============================================================================
/// Extract the task pointer from a `Context`'s waker.
///
/// Our wakers store the task pointer as the `RawWaker` data field.
/// `Waker` layout is `[vtable, data]` — data is at offset 8.
/// Validated by the build script at compile time.
pub