From 51b84bd1985454198c97ff905eb506110b7267a9 Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Wed, 11 Jan 2023 19:29:46 +0100 Subject: [PATCH] added wrapper facilio.sendBody --- examples/hello/hello.zig | 13 +++++-------- src/deps/facilio.zig | 7 +++++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/hello/hello.zig b/examples/hello/hello.zig index 5f3a75d..a2f1d63 100644 --- a/examples/hello/hello.zig +++ b/examples/hello/hello.zig @@ -1,17 +1,14 @@ const std = @import("std"); -const facilio = @import("facilio").Http; +const facilio = @import("facilio"); -fn on_request(request: [*c]facilio.http_s) callconv(.C) void { +fn on_request(request: [*c]facilio.Http.http_s) callconv(.C) void { std.debug.print("REQUEST!\n", .{}); var msg: []const u8 = "Hello from ZAP!"; - _ = facilio.http_send_body(request, @intToPtr( - *anyopaque, - @ptrToInt(msg.ptr), - ), msg.len); + _ = facilio.sendBody(request, msg); } pub fn main() void { - if (facilio.http_listen("3000", null, .{ + if (facilio.Http.http_listen("3000", null, .{ .on_request = on_request, .log = 1, .on_upgrade = null, @@ -36,7 +33,7 @@ pub fn main() void { std.debug.print("Listening failed\n", .{}); return; } - facilio.fio_start(.{ + facilio.Http.fio_start(.{ .threads = 4, .workers = 4, }); diff --git a/src/deps/facilio.zig b/src/deps/facilio.zig index 4b114b0..5367af3 100644 --- a/src/deps/facilio.zig +++ b/src/deps/facilio.zig @@ -4,3 +4,10 @@ pub const Http = @cImport({ @cInclude("http.h"); @cInclude("fio.h"); }); + +pub fn sendBody(request: [*c]Http.http_s, body: []const u8) void { + _ = Http.http_send_body(request, @intToPtr( + *anyopaque, + @ptrToInt(body.ptr), + ), body.len); +}