From 87983464d8a331c1ddd09eced9920269a759f0a9 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sat, 7 Jan 2023 07:09:48 -0800 Subject: Implement DNS module (#1691) * Boilerplate for DNS stuff * Add c-ares * lookup * make * Implement dns.lookup * Create c-ares * wip * normalize * repro * Revert "repro" This reverts commit 8b93e0c295b335b8882a9601da47720348549beb. * Implement macOS `getaddrinfo_async_start` * embiggen * Update string_immutable.zig * Update Makefile * alright * Update .gitignore * Add types * more ccache * Update Dockerfile * Update Dockerfile * Update Dockerfile * Update bun.d.ts Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> --- src/bun.js/event_loop.zig | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/bun.js/event_loop.zig') diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index 6331480d8..825bd7b1b 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -83,10 +83,16 @@ pub fn ConcurrentPromiseTask(comptime Context: type) type { } pub fn IOTask(comptime Context: type) type { + return WorkTask(Context, false); +} + +pub fn WorkTask(comptime Context: type, comptime async_io: bool) type { return struct { + const TaskType = if (async_io) NetworkThread.Task else WorkPoolTask; + const This = @This(); ctx: *Context, - task: NetworkThread.Task = .{ .callback = &runFromThreadPool }, + task: TaskType = .{ .callback = &runFromThreadPool }, event_loop: *JSC.EventLoop, allocator: std.mem.Allocator, globalThis: *JSGlobalObject, @@ -108,7 +114,7 @@ pub fn IOTask(comptime Context: type) type { return this; } - pub fn runFromThreadPool(task: *NetworkThread.Task) void { + pub fn runFromThreadPool(task: *TaskType) void { var this = @fieldParentPtr(This, "task", task); Context.run(this.ctx, this); } @@ -121,8 +127,12 @@ pub fn IOTask(comptime Context: type) type { pub fn schedule(this: *This) void { this.ref.ref(this.event_loop.virtual_machine); - NetworkThread.init() catch return; - NetworkThread.global.schedule(NetworkThread.Batch.from(&this.task)); + if (comptime async_io) { + NetworkThread.init() catch return; + NetworkThread.global.schedule(NetworkThread.Batch.from(&this.task)); + } else { + WorkPool.schedule(&this.task); + } } pub fn onFinish(this: *This) void { @@ -175,6 +185,7 @@ const MicrotaskForDefaultGlobalObject = JSC.MicrotaskForDefaultGlobalObject; const HotReloadTask = JSC.HotReloader.HotReloadTask; const PollPendingModulesTask = JSC.ModuleLoader.AsyncModule.Queue; // const PromiseTask = JSInternalPromise.Completion.PromiseTask; +const GetAddrInfoRequestTask = JSC.DNS.GetAddrInfoRequest.Task; pub const Task = TaggedPointerUnion(.{ FetchTasklet, Microtask, @@ -189,6 +200,7 @@ pub const Task = TaggedPointerUnion(.{ CppTask, HotReloadTask, PollPendingModulesTask, + GetAddrInfoRequestTask, // PromiseTask, // TimeoutTasklet, }); @@ -416,6 +428,11 @@ pub const EventLoop = struct { @field(Task.Tag, typeBaseName(@typeName(PollPendingModulesTask))) => { this.virtual_machine.modules.onPoll(); }, + @field(Task.Tag, typeBaseName(@typeName(GetAddrInfoRequestTask))) => { + var any: *GetAddrInfoRequestTask = task.get(GetAddrInfoRequestTask).?; + any.runFromJS(); + any.deinit(); + }, else => if (Environment.allow_assert) { bun.Output.prettyln("\nUnexpected tag: {s}\n", .{@tagName(task.tag())}); } else unreachable, -- cgit v1.2.3