mirror of
https://git.robbyzambito.me/zaprus
synced 2026-02-04 16:34:51 +00:00
Clean API and add docs
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user