mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
cdp: increase msg size 16KB -> 256KB
And move header size encoding from 2 bytes -> 2 bytes Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
@@ -49,7 +49,7 @@ pub const Stream = struct {
|
||||
}
|
||||
|
||||
fn closeCDP(self: *const Stream) void {
|
||||
const close_msg: []const u8 = .{ 5, 0 } ++ "close";
|
||||
const close_msg: []const u8 = .{ 5, 0, 0, 0 } ++ "close";
|
||||
self.recv(close_msg) catch |err| {
|
||||
log.err("stream close error: {any}", .{err});
|
||||
};
|
||||
@@ -87,7 +87,7 @@ pub const Handler = struct {
|
||||
}
|
||||
|
||||
pub fn clientMessage(self: *Handler, data: []const u8) !void {
|
||||
var header: [2]u8 = undefined;
|
||||
var header: [4]u8 = undefined;
|
||||
Msg.setSize(data.len, &header);
|
||||
try self.stream.recv(&header);
|
||||
try self.stream.recv(data);
|
||||
|
||||
31
src/msg.zig
31
src/msg.zig
@@ -18,17 +18,20 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
pub const MsgSize = 16 * 1204; // 16KB
|
||||
pub const HeaderSize = 2;
|
||||
pub const HeaderSize = 4;
|
||||
pub const MsgSize = 256 * 1204; // 256KB
|
||||
// NOTE: Theorically we could go up to 4GB with a 4 bytes binary encoding
|
||||
// but we prefer to put a lower hard limit for obvious memory size reasons.
|
||||
|
||||
pub const MaxSize = HeaderSize + MsgSize;
|
||||
|
||||
pub const Msg = struct {
|
||||
pub fn getSize(data: []const u8) usize {
|
||||
return std.mem.readInt(u16, data[0..HeaderSize], .little);
|
||||
return std.mem.readInt(u32, data[0..HeaderSize], .little);
|
||||
}
|
||||
|
||||
pub fn setSize(len: usize, header: *[2]u8) void {
|
||||
std.mem.writeInt(u16, header, @intCast(len), .little);
|
||||
pub fn setSize(len: usize, header: *[4]u8) void {
|
||||
std.mem.writeInt(u32, header, @intCast(len), .little);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -121,26 +124,26 @@ test "Buffer" {
|
||||
|
||||
const cases = [_]Case{
|
||||
// simple
|
||||
.{ .input = .{ 2, 0 } ++ "ok", .nb = 1 },
|
||||
.{ .input = .{ 2, 0, 0, 0 } ++ "ok", .nb = 1 },
|
||||
// combined
|
||||
.{ .input = .{ 2, 0 } ++ "ok" ++ .{ 3, 0 } ++ "foo", .nb = 2 },
|
||||
.{ .input = .{ 2, 0, 0, 0 } ++ "ok" ++ .{ 3, 0, 0, 0 } ++ "foo", .nb = 2 },
|
||||
// multipart
|
||||
.{ .input = .{ 9, 0 } ++ "multi", .nb = 0 },
|
||||
.{ .input = .{ 9, 0, 0, 0 } ++ "multi", .nb = 0 },
|
||||
.{ .input = "part", .nb = 1 },
|
||||
// multipart & combined
|
||||
.{ .input = .{ 9, 0 } ++ "multi", .nb = 0 },
|
||||
.{ .input = "part" ++ .{ 2, 0 } ++ "ok", .nb = 2 },
|
||||
.{ .input = .{ 9, 0, 0, 0 } ++ "multi", .nb = 0 },
|
||||
.{ .input = "part" ++ .{ 2, 0, 0, 0 } ++ "ok", .nb = 2 },
|
||||
// multipart & combined with other multipart
|
||||
.{ .input = .{ 9, 0 } ++ "multi", .nb = 0 },
|
||||
.{ .input = "part" ++ .{ 8, 0 } ++ "co", .nb = 1 },
|
||||
.{ .input = .{ 9, 0, 0, 0 } ++ "multi", .nb = 0 },
|
||||
.{ .input = "part" ++ .{ 8, 0, 0, 0 } ++ "co", .nb = 1 },
|
||||
.{ .input = "mbined", .nb = 1 },
|
||||
// several multipart
|
||||
.{ .input = .{ 23, 0 } ++ "multi", .nb = 0 },
|
||||
.{ .input = .{ 23, 0, 0, 0 } ++ "multi", .nb = 0 },
|
||||
.{ .input = "several", .nb = 0 },
|
||||
.{ .input = "complex", .nb = 0 },
|
||||
.{ .input = "part", .nb = 1 },
|
||||
// combined & multipart
|
||||
.{ .input = .{ 2, 0 } ++ "ok" ++ .{ 9, 0 } ++ "multi", .nb = 1 },
|
||||
.{ .input = .{ 2, 0, 0, 0 } ++ "ok" ++ .{ 9, 0, 0, 0 } ++ "multi", .nb = 1 },
|
||||
.{ .input = "part", .nb = 1 },
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user