mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 15:41:48 +00:00
async: remove context from loop impl init
This commit is contained in:
@@ -42,23 +42,20 @@ pub const Conn = struct {
|
||||
loop: *Loop,
|
||||
|
||||
pub fn connect(self: *Conn, socket: std.os.socket_t, address: std.net.Address) !void {
|
||||
var cmd = Command{ .impl = undefined };
|
||||
cmd.impl = NetworkImpl.init(self.loop, &cmd);
|
||||
cmd.impl.connect(socket, address);
|
||||
var cmd = Command{ .impl = NetworkImpl.init(self.loop) };
|
||||
cmd.impl.connect(&cmd, socket, address);
|
||||
_ = try cmd.wait();
|
||||
}
|
||||
|
||||
pub fn send(self: *Conn, socket: std.os.socket_t, buffer: []const u8) !usize {
|
||||
var cmd = Command{ .impl = undefined };
|
||||
cmd.impl = NetworkImpl.init(self.loop, &cmd);
|
||||
cmd.impl.send(socket, buffer);
|
||||
var cmd = Command{ .impl = NetworkImpl.init(self.loop) };
|
||||
cmd.impl.send(&cmd, socket, buffer);
|
||||
return try cmd.wait();
|
||||
}
|
||||
|
||||
pub fn receive(self: *Conn, socket: std.os.socket_t, buffer: []u8) !usize {
|
||||
var cmd = Command{ .impl = undefined };
|
||||
cmd.impl = NetworkImpl.init(self.loop, &cmd);
|
||||
cmd.impl.receive(socket, buffer);
|
||||
var cmd = Command{ .impl = NetworkImpl.init(self.loop) };
|
||||
cmd.impl.receive(&cmd, socket, buffer);
|
||||
return try cmd.wait();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -77,11 +77,10 @@ const AsyncClient = struct {
|
||||
|
||||
pub fn deinit(self: *AsyncRequest) void {
|
||||
self.headers.deinit();
|
||||
self.cli.allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn fetch(self: *AsyncRequest) void {
|
||||
return self.impl.yield();
|
||||
return self.impl.yield(self);
|
||||
}
|
||||
|
||||
fn onerr(self: *AsyncRequest, err: anyerror) void {
|
||||
@@ -118,16 +117,13 @@ const AsyncClient = struct {
|
||||
self.cli.deinit();
|
||||
}
|
||||
|
||||
pub fn create(self: *AsyncClient, uri: std.Uri) !*AsyncRequest {
|
||||
var req = try self.cli.allocator.create(AsyncRequest);
|
||||
req.* = AsyncRequest{
|
||||
.impl = undefined,
|
||||
pub fn create(self: *AsyncClient, uri: std.Uri) !AsyncRequest {
|
||||
return .{
|
||||
.impl = YieldImpl.init(self.cli.loop),
|
||||
.cli = &self.cli,
|
||||
.uri = uri,
|
||||
.headers = .{ .allocator = self.cli.allocator, .owned = false },
|
||||
};
|
||||
req.impl = YieldImpl.init(self.cli.loop, req);
|
||||
return req;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -140,7 +136,7 @@ test "non blocking client" {
|
||||
var client = AsyncClient.init(alloc, &loop);
|
||||
defer client.deinit();
|
||||
|
||||
var reqs: [10]*AsyncClient.AsyncRequest = undefined;
|
||||
var reqs: [10]AsyncClient.AsyncRequest = undefined;
|
||||
for (0..reqs.len) |i| {
|
||||
reqs[i] = try client.create(try std.Uri.parse(url));
|
||||
reqs[i].fetch();
|
||||
|
||||
Reference in New Issue
Block a user