Skip to content

Commit e133c7a

Browse files
committed
Cleaner merge
Switch to non-blocking sockets. Fix TLS handshake/receive/send ordering
1 parent bd32c06 commit e133c7a

File tree

12 files changed

+280
-212
lines changed

12 files changed

+280
-212
lines changed

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
.fingerprint = 0xda130f3af836cea0,
66
.dependencies = .{
77
.tls = .{
8-
.url = "https://github.com/ianic/tls.zig/archive/21aeaa9dd90f89fb86b0cd597f201a2680236f06.tar.gz",
9-
.hash = "1220e584a5962cfba7c2f8d13151754bf76338c9916fedfd9b7a754501b9d9276c61",
8+
.url = "https://github.com/ianic/tls.zig/archive/96b923fcdaa6371617154857cef7b8337778cbe2.tar.gz",
9+
.hash = "122031f94565d7420a155b6eaec65aaa02acc80e75e6f0947899be2106bc3055b1ec",
1010
},
1111
},
1212
}

src/app.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const std = @import("std");
22

33
const Loop = @import("jsruntime").Loop;
44
const Allocator = std.mem.Allocator;
5-
const HttpClient = @import("http/Client.zig");
5+
const HttpClient = @import("http/client.zig").Client;
66
const Telemetry = @import("telemetry/telemetry.zig").Telemetry;
77

88
const log = std.log.scoped(.app);
@@ -38,7 +38,7 @@ pub const App = struct {
3838
.allocator = allocator,
3939
.telemetry = undefined,
4040
.app_dir_path = app_dir_path,
41-
.http_client = .{ .allocator = allocator },
41+
.http_client = try HttpClient.init(allocator, 5, null),
4242
};
4343
app.telemetry = Telemetry.init(app, run_mode);
4444

src/browser/browser.zig

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const Location = @import("../html/location.zig").Location;
4343

4444
const storage = @import("../storage/storage.zig");
4545

46-
const http = @import("../http/client.zig");
46+
const HttpClient = @import("../http/client.zig").Client;
4747
const UserContext = @import("../user_context.zig").UserContext;
4848

4949
const polyfill = @import("../polyfill/polyfill.zig");
@@ -60,21 +60,20 @@ pub const Browser = struct {
6060
app: *App,
6161
session: ?*Session,
6262
allocator: Allocator,
63-
http_client: *http.Client,
63+
http_client: *HttpClient,
6464
session_pool: SessionPool,
6565
page_arena: std.heap.ArenaAllocator,
6666

6767
const SessionPool = std.heap.MemoryPool(Session);
6868

69-
pub fn init(app: *App) !Browser {
69+
pub fn init(app: *App) Browser {
7070
const allocator = app.allocator;
7171
return .{
7272
.app = app,
7373
.session = null,
7474
.allocator = allocator,
7575
.http_client = &app.http_client,
7676
.session_pool = SessionPool.init(allocator),
77-
.http_client = try http.Client.init(allocator, 5, null),
7877
.page_arena = std.heap.ArenaAllocator.init(allocator),
7978
};
8079
}
@@ -127,7 +126,7 @@ pub const Session = struct {
127126
// TODO move the shed to the browser?
128127
storage_shed: storage.Shed,
129128
page: ?Page = null,
130-
http_client: *http.Client,
129+
http_client: *HttpClient,
131130

132131
jstypes: [Types.len]usize = undefined,
133132

@@ -139,7 +138,7 @@ pub const Session = struct {
139138
.env = undefined,
140139
.browser = browser,
141140
.inspector = undefined,
142-
.http_client = &browser.http_client,
141+
.http_client = browser.http_client,
143142
.storage_shed = storage.Shed.init(allocator),
144143
.arena = std.heap.ArenaAllocator.init(allocator),
145144
.window = Window.create(null, .{ .agent = user_agent }),
@@ -434,7 +433,7 @@ pub const Page = struct {
434433
// replace the user context document with the new one.
435434
try session.env.setUserContext(.{
436435
.document = html_doc,
437-
.http_client = self.session.browser.http_client,
436+
.http_client = @ptrCast(self.session.http_client),
438437
});
439438

440439
// browse the DOM tree to retrieve scripts

src/cdp/cdp.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ pub fn CDPT(comptime TypeProvider: type) type {
7070
pub const Browser = TypeProvider.Browser;
7171
pub const Session = TypeProvider.Session;
7272

73-
pub fn init(app: *App, client: TypeProvider.Client) !Self {
73+
pub fn init(app: *App, client: TypeProvider.Client) Self {
7474
const allocator = app.allocator;
7575
return .{
7676
.client = client,
7777
.allocator = allocator,
7878
.browser_context = null,
79-
.browser = try Browser.init(app),
79+
.browser = Browser.init(app),
8080
.message_arena = std.heap.ArenaAllocator.init(allocator),
8181
.browser_context_pool = std.heap.MemoryPool(BrowserContext(Self)).init(allocator),
8282
};

src/cdp/testing.zig

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
// Copyright (C) 2023-2024 Lightpanda (Selecy SAS)
2+
//
3+
// Francis Bouvier <[email protected]>
4+
// Pierre Tachoire <[email protected]>
5+
//
6+
// This program is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU Affero General Public License as
8+
// published by the Free Software Foundation, either version 3 of the
9+
// License, or (at your option) any later version.
10+
//
11+
// This program is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU Affero General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU Affero General Public License
17+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
119
const std = @import("std");
220

321
const json = std.json;
@@ -17,7 +35,7 @@ const Browser = struct {
1735
session: ?*Session = null,
1836
arena: std.heap.ArenaAllocator,
1937

20-
pub fn init(app: *App) !Browser {
38+
pub fn init(app: *App) Browser {
2139
return .{
2240
.arena = std.heap.ArenaAllocator.init(app.allocator),
2341
};

0 commit comments

Comments
 (0)