diff options
Diffstat (limited to 'src/Connection.zig')
| -rw-r--r-- | src/Connection.zig | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/src/Connection.zig b/src/Connection.zig index 0c33f1a..95805de 100644 --- a/src/Connection.zig +++ b/src/Connection.zig @@ -17,10 +17,8 @@ pub fn next(self: Connection, io: Io, buf: []u8) ![]const u8 { log.debug("Awaiting connection message", .{}); const res = try self.socket.receive(buf); log.debug("Received {} byte connection message", .{res.len}); - const connection_res = blk: { - const msg: SaprusMessage = try .parse(res[42..]); - break :blk msg.connection; - }; + const msg: SaprusMessage = try .parse(res[42..]); + const connection_res = msg.connection; log.debug("Payload was {s}", .{connection_res.payload}); @@ -28,29 +26,23 @@ pub fn next(self: Connection, io: Io, buf: []u8) ![]const u8 { } pub fn send(self: *Connection, io: Io, buf: []const 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(); log.debug("Sending connection message", .{}); self.connection.connection.payload = buf; - const connection_bytes = blk: { - var connection_bytes: [2048]u8 = undefined; - break :blk self.connection.toBytes(&connection_bytes); - }; + var connection_bytes_buf: [2048]u8 = undefined; + const connection_bytes = self.connection.toBytes(&connection_bytes_buf); self.headers.ip.id = rand.int(u16); self.headers.setPayloadLen(connection_bytes.len); - const full_msg = blk: { - var msg_buf: [2048]u8 = undefined; - var msg_w: Writer = .fixed(&msg_buf); - try msg_w.writeAll(&self.headers.toBytes()); - try msg_w.writeAll(connection_bytes); - break :blk msg_w.buffered(); - }; + var msg_buf: [2048]u8 = undefined; + var msg_w: Writer = .fixed(&msg_buf); + try msg_w.writeAll(&self.headers.toBytes()); + try msg_w.writeAll(connection_bytes); + const full_msg = msg_w.buffered(); try self.socket.send(full_msg); |
