mctx-core
mctx-core is a runtime-agnostic and portable IPv4 multicast sender library.
It is built for applications and integrations that want a small multicast send core with explicit socket ownership, a non-blocking send path, and optional async or metrics add-ons.
Highlights
- IPv4 multicast send support with configurable interface, loopback, and TTL
- Explicit local source IPv4 and bind-address control for announce-style senders
- Non-blocking send API
- Immediate-ready publications with caller-owned context and socket extraction
- Caller-provided socket support
- Event-loop friendly socket borrowing and extraction APIs
- Optional Tokio adapter via the
tokiofeature - Optional send metrics via the
metricsfeature
Install
With the optional Tokio adapter:
With optional metrics:
Quick Start
use ;
use Ipv4Addr;
let mut ctx = new;
let config = new
.with_source_addr
.with_ttl;
let id = ctx.add_publication?;
let report = ctx.send?;
println!;
println!;
Existing Sockets
Use add_publication_with_socket() when you need to create or bind the socket
yourself:
use ;
use ;
use Ipv4Addr;
let mut ctx = new;
let config = new
.with_source_port;
let socket = new?;
let id = ctx.add_publication_with_socket?;
ctx.send?;
Or hand in a std::net::UdpSocket directly:
use ;
use ;
let mut ctx = new;
let config = new;
let socket = bind?;
let id = ctx.add_publication_with_udp_socket?;
ctx.send?;
Event Loop Integration
Borrow the live socket from a publication:
let publication = ctx.get_publication.unwrap;
let socket = publication.socket;
let raw = publication.as_raw_fd;
Or extract the publication and move it into another loop or runtime:
let publication = ctx.take_publication.unwrap;
let parts = publication.into_parts;
let socket = parts.socket;
If you need the exact announce tuple used by the wire format:
let publication = ctx.get_publication.unwrap;
let = publication.announce_tuple?;
Tokio Integration
With the tokio feature enabled, you can wrap an extracted publication and
send asynchronously:
use TokioPublication;
let publication = ctx.take_publication.unwrap;
let publication = new?;
publication.send.await?;
Run the Tokio example with:
Optional Metrics
If you need send counters, enable the metrics feature and query snapshots:
let publication = ctx.get_publication.unwrap;
let metrics = publication.metrics_snapshot;
println!;
println!;
Demo Binaries
Basic sender:
Burst sender with a fixed count:
Tokio sender:
Documentation
Platform Support
| OS | ASM send | Notes |
|---|---|---|
| macOS | ✅ | Intended support |
| Linux | ✅ | Intended support |
| Windows | ✅ | Intended support |
License
BSD 2-Clause