diff options
Diffstat (limited to 'src/Client.zig')
| -rw-r--r-- | src/Client.zig | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/src/Client.zig b/src/Client.zig index 3425bba..209f5a3 100644 --- a/src/Client.zig +++ b/src/Client.zig @@ -22,10 +22,8 @@ pub fn deinit(self: *Client) void { } pub fn sendRelay(self: *Client, io: Io, payload: []const u8, dest: [4]u8) !void { - const rand = blk: { - const io_source: std.Random.IoSource = .{ .io = io }; - break :blk io_source.interface(); - }; + const io_source: std.Random.IoSource = .{ .io = io }; + const rand = io_source.interface(); var headers: EthIpUdp = .{ .src_mac = self.socket.mac, @@ -53,22 +51,18 @@ pub fn sendRelay(self: *Client, io: Io, payload: []const u8, dest: [4]u8) !void const relay_bytes = relay.toBytes(&relay_buf); headers.setPayloadLen(relay_bytes.len); - const full_msg = blk: { - var msg_buf: [max_message_size]u8 = undefined; - var msg_w: Writer = .fixed(&msg_buf); - msg_w.writeAll(&headers.toBytes()) catch unreachable; - msg_w.writeAll(relay_bytes) catch unreachable; - break :blk msg_w.buffered(); - }; + var msg_buf: [max_message_size]u8 = undefined; + var msg_w: Writer = .fixed(&msg_buf); + msg_w.writeAll(&headers.toBytes()) catch unreachable; + msg_w.writeAll(relay_bytes) catch unreachable; + const full_msg = msg_w.buffered(); try self.socket.send(full_msg); } pub fn connect(self: Client, io: Io, payload: []const u8) !SaprusConnection { - const rand = blk: { - const io_source: std.Random.IoSource = .{ .io = io }; - break :blk io_source.interface(); - }; + const io_source: std.Random.IoSource = .{ .io = io }; + const rand = io_source.interface(); var headers: EthIpUdp = .{ .src_mac = self.socket.mac, @@ -106,13 +100,11 @@ pub fn connect(self: Client, io: Io, payload: []const u8) !SaprusConnection { headers.setPayloadLen(connection_bytes.len); log.debug("Building full message", .{}); - var full_msg = blk: { - var msg_buf: [2048]u8 = undefined; - var msg_w: Writer = .fixed(&msg_buf); - msg_w.writeAll(&headers.toBytes()) catch unreachable; - msg_w.writeAll(connection_bytes) catch unreachable; - break :blk msg_w.buffered(); - }; + var msg_buf: [2048]u8 = undefined; + var msg_w: Writer = .fixed(&msg_buf); + msg_w.writeAll(&headers.toBytes()) catch unreachable; + msg_w.writeAll(connection_bytes) catch unreachable; + var full_msg = msg_w.buffered(); log.debug("Built full message. Sending message", .{}); try self.socket.send(full_msg); @@ -128,13 +120,13 @@ pub fn connect(self: Client, io: Io, payload: []const u8) !SaprusConnection { headers.setPayloadLen(connection_bytes.len); log.debug("Building final handshake message", .{}); - full_msg = blk: { - var msg_buf: [2048]u8 = undefined; - var msg_w: Writer = .fixed(&msg_buf); - msg_w.writeAll(&headers.toBytes()) catch unreachable; - msg_w.writeAll(connection_bytes) catch unreachable; - break :blk msg_w.buffered(); - }; + + msg_w.end = 0; + + msg_w.writeAll(&headers.toBytes()) catch unreachable; + msg_w.writeAll(connection_bytes) catch unreachable; + full_msg = msg_w.buffered(); + try self.socket.send(full_msg); return .init(self.socket, headers, connection); |
