Clean API and add docs

This commit is contained in:
2026-02-01 19:35:14 -05:00
parent 558f40213b
commit 2c9e648c2c
7 changed files with 248 additions and 215 deletions

View File

@@ -20,17 +20,16 @@ connection: SaprusMessage,
const Connection = @This();
pub fn init(socket: RawSocket, headers: EthIpUdp, connection: SaprusMessage) Connection {
return .{
.socket = socket,
.headers = headers,
.connection = connection,
};
}
// 'p' as base64
const pong = "cA==";
/// Attempts to read from the network, and returns the next message, if any.
///
/// Asserts that `buf` is large enough to store the message that is received.
///
/// This will internally process management messages, and return the message
/// payload for the next non management connection message.
/// This function is ignorant to the message encoding.
pub fn next(self: *Connection, io: Io, buf: []u8) ![]const u8 {
while (true) {
log.debug("Awaiting connection message", .{});
@@ -65,6 +64,10 @@ pub fn next(self: *Connection, io: Io, buf: []u8) ![]const u8 {
}
}
/// Attempts to write a message to the network.
///
/// Clients should pass `.{}` for options unless you know what you are doing.
/// `buf` will be sent over the network as-is; this function is ignorant of encoding.
pub fn send(self: *Connection, io: Io, options: SaprusMessage.Connection.Options, buf: []const u8) !void {
const io_source: std.Random.IoSource = .{ .io = io };
const rand = io_source.interface();