aboutsummaryrefslogtreecommitdiff
path: root/src/Connection.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Connection.zig')
-rw-r--r--src/Connection.zig19
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();