diff --git a/src/gossip/service.zig b/src/gossip/service.zig index 075a813ae..af161fb73 100644 --- a/src/gossip/service.zig +++ b/src/gossip/service.zig @@ -436,12 +436,14 @@ pub const GossipService = struct { defer self.allocator.free(tasks); // pre-allocate all the tasks - for (tasks) |*task| task.entry = .{ - .allocator = task_allocator, - .verified_incoming_channel = self.verified_incoming_channel, - .packet_batch = undefined, - .logger = self.logger, - }; + for (tasks) |*task| { + task.entry = .{ + .allocator = task_allocator, + .verified_incoming_channel = self.verified_incoming_channel, + .packet_batch = undefined, + .logger = self.logger, + }; + } while (!self.exit.load(.unordered)) { const maybe_packet_batches = try self.packet_incoming_channel.try_drain(); diff --git a/src/net/socket_utils.zig b/src/net/socket_utils.zig index fa05a7e98..22e94fde4 100644 --- a/src/net/socket_utils.zig +++ b/src/net/socket_utils.zig @@ -27,8 +27,6 @@ pub fn readSocket( while (!exit.load(.unordered)) { // init a new batch - // var count: usize = 0; - // const capacity = PACKETS_PER_BATCH; var packet_batch = try std.ArrayList(Packet).initCapacity( allocator, PACKETS_PER_BATCH, @@ -72,12 +70,11 @@ pub fn sendSocket( while (!exit.load(.unordered)) { const maybe_packet_batches = try outgoing_channel.try_drain(); - if (maybe_packet_batches == null) { + const packet_batches = maybe_packet_batches orelse { // sleep for 1ms // std.time.sleep(std.time.ns_per_ms * 1); continue; - } - const packet_batches = maybe_packet_batches.?; + }; defer { for (packet_batches) |*packet_batch| { packet_batch.deinit();