This commit is contained in:
vfs committed 2026-01-06 16:36:11 +01:00
1 parent 5dad7572b7
commit 01144b2bd4
3 files changed
+59

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
const std = @import("std");
const ConnectState = union(enum) {
disconnected,
connecting,
connected: std.net.Stream,
err: anyerror,
};
const Client = struct {
state: ConnectState = .disconnected,
pub fn startConnect(self: *Client, addr: std.net.Address) void {
if (self.state == .connecting or self.state == .connected)
return;
self.state = .connecting;
const stream = std.net.tcpConnectToAddress(addr) catch |err| {
self.state = .{ .err = err };
return;
};
self.state = .{ .connected = stream };
}
};