|
6 | 6 | * LICENSE file in the root directory of this source tree.
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -//! A simple socket channel implementation, using a simple framing |
10 |
| -//! protocol with no multiplexing. TCP channels serialize messages |
11 |
| -//! using bincode, and frames each message with a 32-bit length, |
12 |
| -//! followed by that many bytes of serialized data, e.g.: |
| 9 | +//! A simple socket channel implementation using a single-stream |
| 10 | +//! framing protocol. Each frame is encoded as an 8-byte |
| 11 | +//! **big-endian** length prefix (u64), followed by exactly that many |
| 12 | +//! bytes of payload. |
13 | 13 | //!
|
| 14 | +//! Message frames are serialized with `bincode`; ack frames are |
| 15 | +//! represented directly as an 8-byte big-endian sequence number. |
| 16 | +//! |
| 17 | +//! Message frame (example): |
14 | 18 | //! ```text
|
15 |
| -//! +---- len: u32 ----+---- data --------------------+ |
16 |
| -//! | \x00\x00\x00\x0b | 11-bytes of serialized data | |
17 |
| -//! +------------------+------------------------------+ |
| 19 | +//! +------------------ len: u64 (BE) ------------------+--------------------- data -------------+ |
| 20 | +//! | \x00\x00\x00\x00\x00\x00\x00\x0B | 11 bytes of bincode-serialized message | |
| 21 | +//! +---------------------------------------------------+----------------------------------------+ |
18 | 22 | //! ```
|
19 | 23 | //!
|
20 |
| -//! Thus, each socket connection is a sequence of such framed messages. |
| 24 | +//! ACK frame (wire format): |
| 25 | +//! ```text |
| 26 | +//! +------------------ len: u64 (BE) ------------------+---------------- 8-byte ACK (u64 BE) ---+ |
| 27 | +//! | \x00\x00\x00\x00\x00\x00\x00\x08 | <acknowledged sequence number bytes> | |
| 28 | +//! +---------------------------------------------------+----------------------------------------+ |
| 29 | +//! ``` |
| 30 | +//! |
| 31 | +//! I/O is handled by `FrameReader`/`FrameWrite`, which are |
| 32 | +//! cancellation-safe and avoid extra copies. Helper fns |
| 33 | +//! `serialize_ack(u64) -> Bytes` and `deserialize_ack(Bytes) -> |
| 34 | +//! Result<u64, usize>` convert to/from the ACK payload. |
| 35 | +//! |
| 36 | +//! ### Limits & EOF semantics |
| 37 | +//! * **Max frame size:** frames larger than |
| 38 | +//! `config::CODEC_MAX_FRAME_LENGTH` are rejected with |
| 39 | +//! `io::ErrorKind::InvalidData`. |
| 40 | +//! * **EOF handling:** `FrameReader::next()` returns `Ok(None)` only |
| 41 | +//! when EOF occurs exactly on a frame boundary. If EOF happens |
| 42 | +//! mid-frame, it returns `Err(io::ErrorKind::UnexpectedEof)`. |
21 | 43 |
|
22 | 44 | use std::any::type_name;
|
23 | 45 | use std::collections::VecDeque;
|
|
0 commit comments