summaryrefslogtreecommitdiff
path: root/src/serve.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/serve.zig')
-rw-r--r--src/serve.zig16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/serve.zig b/src/serve.zig
index 10c8d01..0311f3d 100644
--- a/src/serve.zig
+++ b/src/serve.zig
@@ -178,7 +178,7 @@ pub fn Runner(comptime Backend: type, comptime opts: fs.Options, comptime limits
c.room = .unset;
// Under the lock: the slot is already visible as live.
c.lock();
- c.engine = .init(.{ .in = &c.in, .out = &c.out, .root = r.root, .seed = r.seed ^ c.index });
+ c.engine.initIn(.{ .in = &c.in, .out = &c.out, .root = r.root, .seed = r.seed ^ c.index });
c.unlock();
if (r.handler.opened) |f| f(r.handler.ctx, c);
}
@@ -308,7 +308,19 @@ pub fn Runner(comptime Backend: type, comptime opts: fs.Options, comptime limits
r.slots = .init;
r.stopping = .init(false);
r.active = .init(0);
- for (&r.conns, 0..) |*c, i| c.* = .{ .runner = r, .index = @intCast(i) };
+ // Field by field: a connection's engine and buffers are written
+ // when a client takes the slot (`start`), so a runner sized for
+ // many connections costs nothing for the ones never used.
+ for (&r.conns, 0..) |*c, i| {
+ c.runner = r;
+ c.index = @intCast(i);
+ c.user = null;
+ c.mutex = .init;
+ c.flags = .init(0);
+ c.signal = .unset;
+ c.room = .unset;
+ c.used = .init(false);
+ }
}
/// Binds `address` and starts accepting on it. Returns the bound