mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 15:41:48 +00:00
msg: fix len for msg.Buffer and encode msg size as binary header
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
const std = @import("std");
|
||||
|
||||
const ws = @import("websocket");
|
||||
const Msg = @import("msg.zig").Msg;
|
||||
|
||||
const log = std.log.scoped(.handler);
|
||||
|
||||
@@ -45,7 +46,7 @@ pub const Stream = struct {
|
||||
}
|
||||
|
||||
fn closeCDP(self: *const Stream) void {
|
||||
const close_msg: []const u8 = "5:close";
|
||||
const close_msg: []const u8 = .{ 5, 0 } ++ "close";
|
||||
self.recv(close_msg) catch |err| {
|
||||
log.err("stream close error: {any}", .{err});
|
||||
};
|
||||
@@ -82,8 +83,10 @@ pub const Handler = struct {
|
||||
self.stream.closeCDP();
|
||||
}
|
||||
|
||||
pub fn clientMessage(self: *Handler, alloc: std.mem.Allocator, data: []const u8) !void {
|
||||
const msg = try std.fmt.allocPrint(alloc, "{d}:{s}", .{ data.len, data });
|
||||
try self.stream.recv(msg);
|
||||
pub fn clientMessage(self: *Handler, data: []const u8) !void {
|
||||
var header: [2]u8 = undefined;
|
||||
Msg.setSize(data.len, &header);
|
||||
try self.stream.recv(&header);
|
||||
try self.stream.recv(data);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user