...
This commit is contained in:
1 parent
5dad7572b7
commit
01144b2bd4
3 files changed
+59
No files matched your search
@@ -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 };
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user