diff options
author | Robby Zambito <contact@robbyzambito.me> | 2025-04-27 16:11:12 -0400 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2025-04-27 18:03:06 -0400 |
commit | cc8438448d3e093d0aabf52d97e11a6514a82765 (patch) | |
tree | 0de8d424c12005e0b3842140af55fc002cf6c1f6 | |
parent | 683a2015b0a2d410d012bef404e891da5f6f261e (diff) |
Staring real connections
-rw-r--r-- | build.zig.zon | 4 | ||||
-rw-r--r-- | src/Client.zig | 8 | ||||
-rw-r--r-- | src/Connection.zig | 0 | ||||
-rw-r--r-- | src/main.zig | 9 | ||||
-rw-r--r-- | src/root.zig | 2 |
5 files changed, 13 insertions, 10 deletions
diff --git a/build.zig.zon b/build.zig.zon index f9d27ef..1a40712 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -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", diff --git a/src/Client.zig b/src/Client.zig index 19f8360..c518c74 100644 --- a/src/Client.zig +++ b/src/Client.zig @@ -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; diff --git a/src/Connection.zig b/src/Connection.zig new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/Connection.zig diff --git a/src/main.zig b/src/main.zig index f60614f..7a8a34f 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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, ¶ms, .{}); diff --git a/src/root.zig b/src/root.zig index 5d93578..71d5b2d 100644 --- a/src/root.zig +++ b/src/root.zig @@ -1,2 +1,4 @@ pub const Client = @import("Client.zig"); +pub const Connection = @import("Connection.zig"); + pub usingnamespace @import("message.zig"); |