Skip to content

Commit 8ee4446

Browse files
channel: net: fix module comment (#926)
Summary: Pull Request resolved: #926 update module-level docs in net.rs to reflect the new 64-bit framing format. document both message frames (bincode-serialized payload) and ack frames (raw 8-byte sequence numbers), and add notes on max frame size and `EOF` semantics. no code changes. Reviewed By: mariusae Differential Revision: D80543551 fbshipit-source-id: 681fe319522d488ab8e7cf87203c1f35b3a852d3
1 parent 5bff727 commit 8ee4446

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

hyperactor/src/channel/net.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,40 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

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.
1313
//!
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):
1418
//! ```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+
//! +---------------------------------------------------+----------------------------------------+
1822
//! ```
1923
//!
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)`.
2143
2244
use std::any::type_name;
2345
use std::collections::VecDeque;

0 commit comments

Comments
 (0)