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

@@ -44,6 +44,10 @@
.url = "git+https://github.com/Hejsil/zig-clap?ref=0.10.0#e47028deaefc2fb396d3d9e9f7bd776ae0b2a43a",
.hash = "clap-0.10.0-oBajB434AQBDh-Ei3YtoKIRxZacVPF1iSwp3IX_ZB8f0",
},
.gatorcat = .{
.url = "git+https://github.com/kj4tmp/gatorcat#bb1847f6c95852e7a0ec8c07870a948c171d5f98",
.hash = "gatorcat-0.3.2-WcrpTf1mBwDrmPaIhKCfLJO064v8Sjjn7DBq4CKZSgHH",
},
},
.paths = .{
"build.zig",

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");