mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
mcp: use io poll for stdin and integrate message loop
Replaces blocking stdin reads with `std.io.poll` to allow macrotasks to run. Removes the stdout mutex as I/O is now serialized.
This commit is contained in:
@@ -18,8 +18,6 @@ page: *lp.Page,
|
||||
|
||||
is_running: std.atomic.Value(bool) = .init(false),
|
||||
|
||||
stdout_mutex: std.Thread.Mutex = .{},
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, app: *App) !*Self {
|
||||
const self = try allocator.create(Self);
|
||||
errdefer allocator.destroy(self);
|
||||
@@ -55,13 +53,9 @@ pub fn deinit(self: *Self) void {
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn sendResponse(self: *Self, response: anytype) !void {
|
||||
self.stdout_mutex.lock();
|
||||
defer self.stdout_mutex.unlock();
|
||||
|
||||
var stdout_file = std.fs.File.stdout();
|
||||
var stdout_buf: [8192]u8 = undefined;
|
||||
var stdout = stdout_file.writer(&stdout_buf);
|
||||
pub fn sendResponse(_: *Self, response: anytype) !void {
|
||||
var buffer: [8192]u8 = undefined;
|
||||
var stdout = std.fs.File.stdout().writer(&buffer);
|
||||
try std.json.Stringify.value(response, .{ .emit_null_optional_fields = false }, &stdout.interface);
|
||||
try stdout.interface.writeByte('\n');
|
||||
try stdout.interface.flush();
|
||||
|
||||
Reference in New Issue
Block a user