mirror of
https://git.robbyzambito.me/zaprus
synced 2026-02-04 08:24:52 +00:00
Set timeouts instead of sleeping
This commit is contained in:
@@ -72,10 +72,6 @@ pub fn init() !RawSocket {
|
||||
const bind_ret = std.os.linux.bind(socket, @ptrCast(&sockaddr_ll), @sizeOf(@TypeOf(sockaddr_ll)));
|
||||
if (bind_ret != 0) return error.BindError;
|
||||
|
||||
const timeout: std.os.linux.timeval = .{ .sec = 60 * if (is_debug) 1 else 10, .usec = 0 };
|
||||
const timeout_ret = std.os.linux.setsockopt(socket, std.os.linux.SOL.SOCKET, std.os.linux.SO.RCVTIMEO, @ptrCast(&timeout), @sizeOf(@TypeOf(timeout)));
|
||||
if (timeout_ret != 0) return error.SetTimeoutError;
|
||||
|
||||
return .{
|
||||
.fd = socket,
|
||||
.sockaddr_ll = sockaddr_ll,
|
||||
@@ -83,6 +79,12 @@ pub fn init() !RawSocket {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn setTimeout(self: *RawSocket, sec: isize, usec: i64) !void {
|
||||
const timeout: std.os.linux.timeval = .{ .sec = sec, .usec = usec };
|
||||
const timeout_ret = std.os.linux.setsockopt(self.fd, std.os.linux.SOL.SOCKET, std.os.linux.SO.RCVTIMEO, @ptrCast(&timeout), @sizeOf(@TypeOf(timeout)));
|
||||
if (timeout_ret != 0) return error.SetTimeoutError;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *RawSocket) void {
|
||||
_ = std.os.linux.close(self.fd);
|
||||
self.* = undefined;
|
||||
|
||||
Reference in New Issue
Block a user