Zig implementation of SCTP (Stream Control Transmission Protocol) RFC 9260.
This library implement a subset of the SCTP protocol, focusing on the parts needed by WebRTC data channels.
This is a sans-IO implementation of SCTP, meaning that it does not handle any I/O operations. Instead, it provides a set of functions to encode and decode SCTP packets, as well as to manage the state of an SCTP association.
Requires Zig 0.16.0.
zig fetch --save git+https://github.com/zigouat/sctpIn build.zig:
const sctp = b.dependency("sctp", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("sctp", sctp.module("sctp"));sctp.Association is a state machine. The caller owns the transport and the clock. now is a monotonic timestamp in milliseconds (i64).
handleRead(packet, now): feeds one received SCTP packet (common header + chunks).handleWrite(data, options): queues a user message.datais copied.handleTimeout(now): handle expired timers.
Drain every output after each input call.
pollEvent() ?Event: returns the next application event, ornullwhen none is left.pollTransmit(buffer, now) TransmitError!?[]const u8: returns the next packet to send as a slice ofbufferornullwhen nothing is left.pollTimeout() ?i64: returns the earliest absolute deadline, ornullwhen no timer is armed.
Association is not thread-safe, so serialize all calls.