diff options
| author | Robby Zambito <contact@robbyzambito.me> | 2026-02-01 19:35:14 -0500 |
|---|---|---|
| committer | Robby Zambito <contact@robbyzambito.me> | 2026-02-01 21:02:38 -0500 |
| commit | 2c9e648c2c9c487c0239760bff23a70c059f018f (patch) | |
| tree | 0167c13947bfab5349dc705aca555658b5d742ff /src/Connection.zig | |
| parent | 558f40213b895810a78b2bbcbdbb95e88a301fde (diff) | |
Clean API and add docs
Diffstat (limited to 'src/Connection.zig')
| -rw-r--r-- | src/Connection.zig | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/Connection.zig b/src/Connection.zig index bb81c38..19be710 100644 --- a/src/Connection.zig +++ b/src/Connection.zig @@ -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(); |
