Starting real connections

This commit is contained in:
2025-04-27 16:11:12 -04:00
parent 683a2015b0
commit dae66a0039
5 changed files with 13 additions and 10 deletions

View File

@@ -76,7 +76,7 @@ pub fn sendInitialConnection(payload: []const u8, initial_port: u16, allocator:
return msg;
}
pub fn connect(payload: []const u8, allocator: Allocator) !?SaprusMessage {
pub fn connect(payload: []const u8, allocator: Allocator) !?SaprusConnection {
var initial_port: u16 = 0;
if (rand) |r| {
initial_port = r.intRangeAtMost(u16, 1024, 65000);
@@ -109,10 +109,14 @@ pub fn connect(payload: []const u8, allocator: Allocator) !?SaprusMessage {
// Complete handshake after awaiting response
try broadcastSaprusMessage(msg, randomPort(), allocator);
return initial_conn_res;
if (false) {
return initial_conn_res.?;
}
return null;
}
const SaprusMessage = @import("message.zig").Message;
const SaprusConnection = @import("Connection.zig");
const std = @import("std");
const Random = std.Random;

0
src/Connection.zig Normal file
View File

View File

@@ -59,17 +59,10 @@ pub fn main() !void {
// std.debug.print("Sent: {s}\n", .{r});
return;
} else if (res.args.connect) |c| {
const conn_res: ?SaprusMessage = SaprusClient.connect(if (c.len > 0) c else "Hello darkness my old friend", gpa) catch |err| switch (err) {
_ = SaprusClient.connect(if (c.len > 0) c else "Hello darkness my old friend", gpa) catch |err| switch (err) {
error.WouldBlock => null,
else => return err,
};
defer if (conn_res) |r| r.deinit(gpa);
if (conn_res) |r| {
std.debug.print("{s}\n", .{r.connection.payload});
} else {
std.debug.print("No response from connection request\n", .{});
}
return;
}
return clap.help(std.io.getStdErr().writer(), clap.Help, &params, .{});

View File

@@ -1,2 +1,4 @@
pub const Client = @import("Client.zig");
pub const Connection = @import("Connection.zig");
pub usingnamespace @import("message.zig");