const ThreadPool = @import("thread_pool"); pub const Batch = ThreadPool.Batch; pub const Task = ThreadPool.Task; pub const Completion = AsyncIO.Completion; const std = @import("std"); pub const AsyncIO = @import("io"); const Output = @import("./global.zig").Output; const IdentityContext = @import("./identity_context.zig").IdentityContext; const HTTP = @import("./http_client_async.zig"); const NetworkThread = @This(); /// Single-thread in this pool pool: ThreadPool, pub var global: NetworkThread = undefined; pub var global_loaded: std.atomic.Atomic(u32) = std.atomic.Atomic(u32).init(0); const CachedAddressList = struct { address_list: *std.net.AddressList, expire_after: u64, key: u64, index: ?u32 = null, invalidated: bool = false, pub fn hash(name: []const u8, port: u16) u64 { var hasher = std.hash.Wyhash.init(0); hasher.update(name); hasher.update(":"); hasher.update(std.mem.asBytes(&port)); return hasher.final(); } pub fn init(key: u64, address_list: *std.net.AddressList, now: u64) CachedAddressList { return CachedAddressList{ .address_list = address_list, .expire_after = now + std.time.ms_per_hour, .key = key, }; } pub fn invalidate(this: *CachedAddressList) void { if (!this.invalidated) { this.invalidated = true; this.address_list.deinit(); } _ = address_list_cached.remove(this.key); } }; pub const AddressListCache = std.HashMap(u64, CachedAddressList, IdentityContext(u64), 80); pub var address_list_cached: AddressListCache = undefined; pub fn getAddressList(allocator: std.mem.Allocator, name: []const u8, port: u16) !*std.net.AddressList { // const hash = CachedAddressList.hash(name, port); // const now = @intCast(u64, @maximum(0, std.time.milliTimestamp())); // if (address_list_cached.getPtr(hash)) |cached| { // if (cached.expire_after > now) { // return cached; // } // cached.address_list.deinit(); // } return try std.net.getAddressList(allocator, name, port); } pub var has_warmed = false; pub fn warmup() !void { if (has_warmed) return; has_warmed = true; try init(); global.pool.forceSpawn(); } pub fn init() !void { if ((global_loaded.swap(1, .Monotonic)) == 1) return; AsyncIO.global_loaded = true; global = NetworkThread{ .pool = ThreadPool.init(.{ .max_threads = 1, .stack_size = 64 * 1024 * 1024 }), }; global.pool.on_thread_spawn = HTTP.onThreadStart; } option> Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/examples/middleware (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-08-03[ci] release (#7912)astro@2.10.0@astrojs/vercel@3.8.0@astrojs/node@5.3.2@astrojs/image@0.17.3Gravatar Houston (Bot) 1-2/+2
2023-08-03Fix failed server restart calling integration hooks twice (#7917)Gravatar Bjorn Lu 5-30/+27
2023-08-02[ci] formatGravatar matthewp 3-19/+28
2023-08-02Persistent DOM in ViewTransitions (#7861)Gravatar Matthew Phillips 18-20/+242
2023-08-02[ci] formatGravatar matthewp 1-1/+1
2023-08-02Fix scroll position in view transition (#7882) (#7911)Gravatar Martin Trapp 2-1/+6
2023-08-02Improve sourcemap generation and performance (#7901)Gravatar Bjorn Lu 11-27/+34
2023-08-01[ci] formatGravatar natemoo-re 1-1/+0
2023-08-01Fix astro/app import (#7821)Gravatar ottomated 4-1/+25
2023-08-01[ci] formatGravatar natemoo-re 1-1/+1
2023-08-01feat: add cache headers to assets in Vercel adapter (#7729)Gravatar Hee 10-3/+144
2023-08-01Fix "res.writeHead is not a function" in Express/node middleware (#7708)Gravatar DixCouleur 3-8/+34
2023-08-01Fix: Content Collections - Ignore `.json` files nested in non-underscored sub...Gravatar Tony Dang 3-1/+6
2023-08-01chore: address feedback from #7754 (#7906)Gravatar Nate Moore 1-2/+4
2023-08-01[ci] release (#7877)astro@2.9.7@astrojs/vercel@3.7.5@astrojs/node@5.3.1@astrojs/netlify@2.5.2Gravatar Houston (Bot) 52-129/+128
2023-08-01feat: add logging for when hydrate's JSON parse fails (#7887)Gravatar Sam Hulick 2-3/+28
2023-08-01Fix prefetch test fail (#7902)Gravatar Bjorn Lu 1-0/+2
2023-08-01[ci] formatGravatar bluwy 4-13/+28