mirror of
https://git.robbyzambito.me/zaprus/
synced 2026-02-04 03:34:48 +00:00
Don't create dangling references
Apparently things die at the end of blk scopes.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user