mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
server: fix cancel
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
@@ -45,6 +45,10 @@ pub const Stream = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn closeCDP(self: *const Stream) void {
|
fn closeCDP(self: *const Stream) void {
|
||||||
|
const close_msg: []const u8 = .{ 5, 0 } ++ "close";
|
||||||
|
self.recv(close_msg) catch |err| {
|
||||||
|
log.err("stream close error: {any}", .{err});
|
||||||
|
};
|
||||||
std.posix.close(self.socket);
|
std.posix.close(self.socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,8 +120,8 @@ pub const Ctx = struct {
|
|||||||
std.debug.assert(completion == self.conn_completion);
|
std.debug.assert(completion == self.conn_completion);
|
||||||
|
|
||||||
const size = result catch |err| {
|
const size = result catch |err| {
|
||||||
if (err == error.Canceled) {
|
if (self.isClosed() and err == error.FileDescriptorInvalid) {
|
||||||
log.debug("read canceled", .{});
|
log.debug("read has been canceled", .{});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.err("read error: {any}", .{err});
|
log.err("read error: {any}", .{err});
|
||||||
@@ -202,7 +202,7 @@ pub const Ctx = struct {
|
|||||||
if (now.since(self.last_active.?) > self.timeout) {
|
if (now.since(self.last_active.?) > self.timeout) {
|
||||||
// close current connection
|
// close current connection
|
||||||
log.debug("conn timeout, closing...", .{});
|
log.debug("conn timeout, closing...", .{});
|
||||||
self.cancelAndClose();
|
self.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,19 +216,6 @@ pub const Ctx = struct {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cancelCbk(self: *Ctx, completion: *Completion, result: CancelError!void) void {
|
|
||||||
std.debug.assert(completion == self.accept_completion);
|
|
||||||
|
|
||||||
_ = result catch |err| {
|
|
||||||
log.err("cancel error: {any}", .{err});
|
|
||||||
self.err = err;
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
log.debug("cancel done", .{});
|
|
||||||
|
|
||||||
self.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// shortcuts
|
// shortcuts
|
||||||
// ---------
|
// ---------
|
||||||
|
|
||||||
@@ -265,7 +252,7 @@ pub const Ctx = struct {
|
|||||||
if (std.mem.eql(u8, cmd, "close")) {
|
if (std.mem.eql(u8, cmd, "close")) {
|
||||||
// close connection
|
// close connection
|
||||||
log.info("close cmd, closing conn...", .{});
|
log.info("close cmd, closing conn...", .{});
|
||||||
self.cancelAndClose();
|
self.close();
|
||||||
return error.Closed;
|
return error.Closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,26 +288,12 @@ pub const Ctx = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cancelAndClose(self: *Ctx) void {
|
|
||||||
if (isLinux) { // cancel is only available on Linux
|
|
||||||
self.loop.io.cancel(
|
|
||||||
*Ctx,
|
|
||||||
self,
|
|
||||||
Ctx.cancelCbk,
|
|
||||||
self.accept_completion,
|
|
||||||
self.conn_completion,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
self.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn close(self: *Ctx) void {
|
fn close(self: *Ctx) void {
|
||||||
std.posix.close(self.conn_socket);
|
|
||||||
|
|
||||||
// conn is closed
|
// conn is closed
|
||||||
log.debug("connection closed", .{});
|
|
||||||
self.last_active = null;
|
self.last_active = null;
|
||||||
|
std.posix.close(self.conn_socket);
|
||||||
|
log.debug("connection closed", .{});
|
||||||
|
|
||||||
// restart a new browser session in case of re-connect
|
// restart a new browser session in case of re-connect
|
||||||
if (!self.sessionNew) {
|
if (!self.sessionNew) {
|
||||||
|
|||||||
Reference in New Issue
Block a user