authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-12 20:09:16 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-12 20:09:16 -07:00
log609f31d2e31c1a461ec01e5ac3311b7cdd5a2a54
tree84f56e5af69949f3ebcfb519773314a5e85a409c
parentaf7ad60d8723ce5c97bf09d894318c24866261c1
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add setSendTimeout and setRecvTimeout to Stream


2 files changed, 18 insertions(+), 0 deletions(-)

net.zig+17
......@@ -2,6 +2,7 @@ const std = @import("std");
22const builtin = @import("builtin");
33const nio = @import("nio");
44const nfs = @import("nfs");
5const time = @import("time");
56const sys_linux = @import("sys-linux");
67
78const os = builtin.target.os.tag;
......@@ -188,6 +189,22 @@ pub const Stream = struct {
188189 .state = @ptrFromInt(@intFromEnum(s.socket)),
189190 };
190191 }
192
193 pub fn setSendTimeout(s: Stream, timeout_us: u31) !void {
194 const timeval: sys.struct_timeval = .{
195 .sec = timeout_us / time.us_per_s,
196 .usec = timeout_us % time.us_per_s,
197 };
198 return sys.setsockopt(@intCast(@intFromEnum(s.socket)), sys.SOL.SOCKET, sys.SO.SNDTIMEO, @ptrCast((&timeval)[0..1]));
199 }
200
201 pub fn setRecvTimeout(s: Stream, timeout_us: u31) !void {
202 const timeval: sys.struct_timeval = .{
203 .sec = timeout_us / time.us_per_s,
204 .usec = timeout_us % time.us_per_s,
205 };
206 return sys.setsockopt(@intCast(@intFromEnum(s.socket)), sys.SOL.SOCKET, sys.SO.RCVTIMEO, @ptrCast((&timeval)[0..1]));
207 }
191208};
192209
193210pub const Server = struct {
zigmod.yml+1
......@@ -7,5 +7,6 @@ dependencies:
77 - src: git https://github.com/nektro/zig-nio
88 - src: git https://github.com/nektro/zig-sys-linux
99 - src: git https://github.com/nektro/zig-nfs
10 - src: git https://github.com/nektro/zig-time
1011root_dependencies:
1112 - src: git https://github.com/nektro/zig-expect