Files
zzz/src/client/client.zig
T
2026-02-08 15:22:31 +01:00

28 lines
648 B
Zig

const std = @import("std");
const shared = @import("shared");
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 };
}
};