Skip to content

Commit cea38a1

Browse files
server: rename buf in read_buf
Signed-off-by: Francis Bouvier <[email protected]>
1 parent c8a91d4 commit cea38a1

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/server.zig

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ pub const Ctx = struct {
4949
// internal fields
5050
accept_socket: std.posix.socket_t,
5151
conn_socket: std.posix.socket_t = undefined,
52-
buf: []u8, // only for read operations
53-
err: ?Error = null,
54-
52+
read_buf: []u8, // only for read operations
5553
msg_buf: *MsgBuffer,
54+
err: ?Error = null,
5655

5756
// I/O fields
5857
conn_completion: *Completion,
@@ -86,7 +85,7 @@ pub const Ctx = struct {
8685
self.loop.io.timeout(*Ctx, self, Ctx.timeoutCbk, self.timeout_completion, TimeoutCheck);
8786

8887
// receving incomming messages asynchronously
89-
self.loop.io.recv(*Ctx, self, Ctx.readCbk, self.conn_completion, self.conn_socket, self.buf);
88+
self.loop.io.recv(*Ctx, self, Ctx.readCbk, self.conn_completion, self.conn_socket, self.read_buf);
9089
}
9190

9291
fn readCbk(self: *Ctx, completion: *Completion, result: RecvError!usize) void {
@@ -99,16 +98,16 @@ pub const Ctx = struct {
9998

10099
if (size == 0) {
101100
// continue receving incomming messages asynchronously
102-
self.loop.io.recv(*Ctx, self, Ctx.readCbk, self.conn_completion, self.conn_socket, self.buf);
101+
self.loop.io.recv(*Ctx, self, Ctx.readCbk, self.conn_completion, self.conn_socket, self.read_buf);
103102
return;
104103
}
105104

106105
// input
107-
const input = self.buf[0..size];
108106
if (std.log.defaultLogEnabled(.debug)) {
109107
const content = input[0..@min(MaxStdOutSize, size)];
110108
std.debug.print("\ninput size: {d}, content: {s}\n", .{ size, content });
111109
}
110+
const input = self.read_buf[0..size];
112111

113112
// read and execute input
114113
self.msg_buf.read(self.alloc(), input, self, Ctx.do) catch |err| {
@@ -125,7 +124,7 @@ pub const Ctx = struct {
125124
};
126125

127126
// continue receving incomming messages asynchronously
128-
self.loop.io.recv(*Ctx, self, Ctx.readCbk, self.conn_completion, self.conn_socket, self.buf);
127+
self.loop.io.recv(*Ctx, self, Ctx.readCbk, self.conn_completion, self.conn_socket, self.read_buf);
129128
}
130129

131130
fn timeoutCbk(self: *Ctx, completion: *Completion, result: TimeoutError!void) void {
@@ -224,14 +223,16 @@ pub const Ctx = struct {
224223

225224
if (self.sessionNew) self.sessionNew = false;
226225

227-
// cdp end cmd
228226
const res = cdp.do(self.alloc(), cmd, self) catch |err| {
227+
228+
// cdp end cmd
229229
if (err == error.DisposeBrowserContext) {
230230
// restart a new browser session
231231
std.log.debug("cdp end cmd", .{});
232232
try self.newSession();
233233
return;
234234
}
235+
235236
return err;
236237
};
237238

@@ -366,7 +367,8 @@ pub fn sendSync(ctx: *Ctx, msg: []const u8) !void {
366367

367368
pub fn listen(browser: *Browser, loop: *public.Loop, server_socket: std.posix.socket_t) anyerror!void {
368369

369-
// MsgBuffer
370+
// create buffers
371+
var read_buf: [BufReadSize]u8 = undefined;
370372
var msg_buf = try MsgBuffer.init(loop.alloc, BufReadSize * 256); // 256KB
371373
defer msg_buf.deinit(loop.alloc);
372374

@@ -376,12 +378,11 @@ pub fn listen(browser: *Browser, loop: *public.Loop, server_socket: std.posix.so
376378

377379
// create I/O contexts and callbacks
378380
// for accepting connections and receving messages
379-
var ctxInput: [BufReadSize]u8 = undefined;
380381
var ctx = Ctx{
381382
.loop = loop,
382383
.browser = browser,
383384
.sessionNew = true,
384-
.buf = &ctxInput,
385+
.read_buf = &read_buf,
385386
.msg_buf = &msg_buf,
386387
.accept_socket = server_socket,
387388
.conn_completion = &conn_completion,

0 commit comments

Comments
 (0)