server: formatting

Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2024-10-09 12:10:54 +02:00
parent 9400dd799e
commit c564702eac

View File

@@ -69,7 +69,11 @@ pub const Ctx = struct {
// callbacks // callbacks
// --------- // ---------
fn acceptCbk(self: *Ctx, completion: *Completion, result: AcceptError!std.posix.socket_t) void { fn acceptCbk(
self: *Ctx,
completion: *Completion,
result: AcceptError!std.posix.socket_t,
) void {
std.debug.assert(completion == self.conn_completion); std.debug.assert(completion == self.conn_completion);
self.conn_socket = result catch |err| { self.conn_socket = result catch |err| {
@@ -82,10 +86,23 @@ pub const Ctx = struct {
std.log.err("accept timestamp error: {any}", .{err}); std.log.err("accept timestamp error: {any}", .{err});
return; return;
}; };
self.loop.io.timeout(*Ctx, self, Ctx.timeoutCbk, self.timeout_completion, TimeoutCheck); self.loop.io.timeout(
*Ctx,
self,
Ctx.timeoutCbk,
self.timeout_completion,
TimeoutCheck,
);
// receving incomming messages asynchronously // receving incomming messages asynchronously
self.loop.io.recv(*Ctx, self, Ctx.readCbk, self.conn_completion, self.conn_socket, self.read_buf); self.loop.io.recv(
*Ctx,
self,
Ctx.readCbk,
self.conn_completion,
self.conn_socket,
self.read_buf,
);
} }
fn readCbk(self: *Ctx, completion: *Completion, result: RecvError!usize) void { fn readCbk(self: *Ctx, completion: *Completion, result: RecvError!usize) void {
@@ -98,7 +115,14 @@ pub const Ctx = struct {
if (size == 0) { if (size == 0) {
// continue receving incomming messages asynchronously // continue receving incomming messages asynchronously
self.loop.io.recv(*Ctx, self, Ctx.readCbk, self.conn_completion, self.conn_socket, self.read_buf); self.loop.io.recv(
*Ctx,
self,
Ctx.readCbk,
self.conn_completion,
self.conn_socket,
self.read_buf,
);
return; return;
} }
@@ -124,7 +148,14 @@ pub const Ctx = struct {
}; };
// continue receving incomming messages asynchronously // continue receving incomming messages asynchronously
self.loop.io.recv(*Ctx, self, Ctx.readCbk, self.conn_completion, self.conn_socket, self.read_buf); self.loop.io.recv(
*Ctx,
self,
Ctx.readCbk,
self.conn_completion,
self.conn_socket,
self.read_buf,
);
} }
fn timeoutCbk(self: *Ctx, completion: *Completion, result: TimeoutError!void) void { fn timeoutCbk(self: *Ctx, completion: *Completion, result: TimeoutError!void) void {
@@ -155,12 +186,24 @@ pub const Ctx = struct {
// (and cancel does not work on MacOS) // (and cancel does not work on MacOS)
// close current connection // close current connection
self.loop.io.close(*Ctx, self, Ctx.closeCbk, self.timeout_completion, self.conn_socket); self.loop.io.close(
*Ctx,
self,
Ctx.closeCbk,
self.timeout_completion,
self.conn_socket,
);
return; return;
} }
// continue checking timeout // continue checking timeout
self.loop.io.timeout(*Ctx, self, Ctx.timeoutCbk, self.timeout_completion, TimeoutCheck); self.loop.io.timeout(
*Ctx,
self,
Ctx.timeoutCbk,
self.timeout_completion,
TimeoutCheck,
);
} }
fn closeCbk(self: *Ctx, completion: *Completion, result: CloseError!void) void { fn closeCbk(self: *Ctx, completion: *Completion, result: CloseError!void) void {
@@ -187,7 +230,13 @@ pub const Ctx = struct {
std.log.debug("accepting new conn...", .{}); std.log.debug("accepting new conn...", .{});
// continue accepting incoming requests // continue accepting incoming requests
self.loop.io.accept(*Ctx, self, Ctx.acceptCbk, self.conn_completion, self.accept_socket); self.loop.io.accept(
*Ctx,
self,
Ctx.acceptCbk,
self.conn_completion,
self.accept_socket,
);
} }
// shortcuts // shortcuts
@@ -217,7 +266,13 @@ pub const Ctx = struct {
if (std.mem.eql(u8, cmd, "close")) { if (std.mem.eql(u8, cmd, "close")) {
// close connection // close connection
std.log.debug("close cmd, closing...", .{}); std.log.debug("close cmd, closing...", .{});
self.loop.io.close(*Ctx, self, Ctx.closeCbk, self.conn_completion, self.conn_socket); self.loop.io.close(
*Ctx,
self,
Ctx.closeCbk,
self.conn_completion,
self.conn_socket,
);
return error.Closed; return error.Closed;
} }
@@ -245,7 +300,11 @@ pub const Ctx = struct {
fn newSession(self: *Ctx) !void { fn newSession(self: *Ctx) !void {
try self.browser.newSession(self.alloc(), self.loop); try self.browser.newSession(self.alloc(), self.loop);
try self.browser.currentSession().setInspector(self, Ctx.onInspectorResp, Ctx.onInspectorNotif); try self.browser.currentSession().setInspector(
self,
Ctx.onInspectorResp,
Ctx.onInspectorNotif,
);
self.sessionNew = true; self.sessionNew = true;
std.log.debug("new session", .{}); std.log.debug("new session", .{});
} }
@@ -268,7 +327,11 @@ pub const Ctx = struct {
// inject sessionID in cdp msg // inject sessionID in cdp msg
const tpl = "{s},\"sessionId\":\"{s}\"}}"; const tpl = "{s},\"sessionId\":\"{s}\"}}";
const msg_open = msg[0 .. msg.len - 1]; // remove closing bracket const msg_open = msg[0 .. msg.len - 1]; // remove closing bracket
const s = try std.fmt.allocPrint(allocator, tpl, .{ msg_open, cdp.ContextSessionID }); const s = try std.fmt.allocPrint(
allocator,
tpl,
.{ msg_open, cdp.ContextSessionID },
);
defer ctx.alloc().free(s); defer ctx.alloc().free(s);
try sendSync(ctx, s); try sendSync(ctx, s);
@@ -363,7 +426,11 @@ pub fn listen(
.conn_completion = &conn_completion, .conn_completion = &conn_completion,
.timeout_completion = &timeout_completion, .timeout_completion = &timeout_completion,
}; };
try browser.currentSession().setInspector(&ctx, Ctx.onInspectorResp, Ctx.onInspectorNotif); try browser.currentSession().setInspector(
&ctx,
Ctx.onInspectorResp,
Ctx.onInspectorNotif,
);
// accepting connection asynchronously on internal server // accepting connection asynchronously on internal server
std.log.debug("accepting new conn...", .{}); std.log.debug("accepting new conn...", .{});