1# @ajax/mesh-chan
23A channel of fixed-size messages between threads with the semantics meshd's Rust relied on
4(`std::sync::mpsc`): many senders and one receiver, messages in send order, unbounded or bounded
5(`try_send` refuses when full, as `sync_channel`), sends fail once the receiver is gone, receives report
6"disconnected" once every sender is gone and nothing is queued, and receives can wait forever, for a
7timeout on the monotonic clock, or not at all. A reference count keeps the channel alive for its last
8holder; messages left behind go to an optional `drop` function so what they own is freed.
910Also `mesh_mono_ms`, `mesh_mono_us` and `mesh_sleep_us` (the monotonic clock the deadlines use).
1112## Ported from
1314[alpha-rust-mesh](https://github.com/rsafier/alpha-rust-mesh) (Richard Safier, MIT): meshd's threads talk
15through `std::sync::mpsc` channels (`crates/mesh-host/src/shared.rs`: `Cmd`, `PeerEvent`, `JobEvent`, the
16link queues); this is that, in C over pthreads.
1718## Tests
1920- `tests/chan.c`: order and growth, a producer thread (10 000 messages, in order, then disconnected),
21 timeouts, bounded `try_send`, a closed receiver, and messages dropped at release.
2223## Licence
2425MIT. See the repository's LICENSE.