Handle network blocking well

This commit is contained in:
2025-04-06 11:03:16 -04:00
parent c0c7b505e9
commit ab793f69d1
2 changed files with 7 additions and 6 deletions

View File

@@ -98,13 +98,13 @@ pub fn connect(payload: []const u8, allocator: Allocator) !?SaprusMessage {
};
// timeout 1s
try sock.setReadTimeout(1_000_000);
try sock.setReadTimeout(1 * std.time.us_per_s);
try sock.bind(bind_addr);
const msg = try sendInitialConnection(payload, initial_port, allocator);
var response_buf: [4096]u8 = undefined;
_ = try sock.receive(&response_buf);
_ = try sock.receive(&response_buf); // Ignore message that I sent.
const len = try sock.receive(&response_buf);
initial_conn_res = try SaprusMessage.fromBytes(response_buf[0..len], allocator);
@@ -115,7 +115,7 @@ pub fn connect(payload: []const u8, allocator: Allocator) !?SaprusMessage {
return initial_conn_res;
}
const SaprusMessage = @import("./saprus_message.zig").SaprusMessage;
pub const SaprusMessage = @import("./saprus_message.zig").SaprusMessage;
const std = @import("std");
const Random = std.Random;