@@ -3,18 +3,29 @@ const zinc = @import("zinc");
33const Datetime = @import ("datetime" ).datetime .Datetime ;
44
55pub fn main () ! void {
6- var gpa = std .heap .GeneralPurposeAllocator (.{}){};
7- const allocator = gpa .allocator ();
8-
9- var z = try zinc .init (.{ .port = 8080 , .allocator = allocator , .num_threads = 255 });
6+ var gpa = std .heap .GeneralPurposeAllocator (.{
7+ .thread_safe = true ,
8+ }){};
9+ var tsa = std.heap.ThreadSafeAllocator {
10+ .child_allocator = gpa .allocator (),
11+ };
12+ const allocator = tsa .allocator ();
13+
14+ const cpuCount = @as (u8 , @intCast (std .Thread .getCpuCount () catch 1 ));
15+
16+ var z = try zinc .init (.{
17+ .port = 8080 ,
18+ .allocator = allocator ,
19+ .num_threads = 16 * cpuCount ,
20+ });
1021
1122 var router = z .getRouter ();
1223 try router .use (&.{setupHeader });
1324
1425 try router .get ("/json" , json );
1526 try router .get ("/plaintext" , plaintext );
1627
17- try z .run ();
28+ z .run () catch | err | std . debug . print ( "Error: {any} \n " , .{ err } );
1829}
1930
2031fn plaintext (ctx : * zinc.Context ) anyerror ! void {
@@ -27,12 +38,10 @@ fn json(ctx: *zinc.Context) anyerror!void {
2738
2839fn setupHeader (ctx : * zinc.Context ) anyerror ! void {
2940 try ctx .setHeader ("Server" , "Zinc" );
30- // try ctx.setHeader("date ", "Sun Sep 22 10:01:11 CEST 2024 ");
31- // In UTC
41+ try ctx .setHeader ("Connection " , "keep-alive " );
42+
3243 const now = Datetime .now ();
3344 const now_str = try now .formatHttp (ctx .allocator );
34- // defer ctx.allocator.free(now_str);
35- // std.debug.warn("The time is now: {}\n", .{now_str});
3645 // The time is now: Fri, 20 Dec 2019 22:03:02 UTC
3746 try ctx .setHeader ("date" , now_str );
3847}
0 commit comments