1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 15:14:08 +00:00

lil progress

This commit is contained in:
Rene Schallner 2023-01-11 21:21:25 +01:00
parent 80678c1cf9
commit 1174a4946d
3 changed files with 15 additions and 5 deletions

View file

@ -53,7 +53,7 @@ pub fn addFacilio(exe: *std.build.LibExeObjStep) !void {
if (b.is_release) try flags.append("-Os"); if (b.is_release) try flags.append("-Os");
try flags.append("-Wno-return-type-c-linkage"); try flags.append("-Wno-return-type-c-linkage");
try flags.append("-fno-sanitize=undefined"); try flags.append("-fno-sanitize=undefined");
try flags.append("-DFIO_OVERRIDE_MALLOC");
exe.addIncludePath("./src/deps/facilio/libdump/all"); exe.addIncludePath("./src/deps/facilio/libdump/all");
// Add C // Add C

View file

@ -7,15 +7,21 @@ fn on_request(request: [*c]zap.C.http_s) callconv(.C) void {
} }
pub fn main() !void { pub fn main() !void {
std.debug.print("debug1\n", .{});
// configure // configure
var listen_settings = zap.ListenSettings.init(); var listen_settings: zap.ListenSettings = .{};
std.debug.print("debug2\n", .{});
listen_settings.on_request = on_request; listen_settings.on_request = on_request;
listen_settings.log = true; listen_settings.log = true;
std.debug.print("debug3\n", .{});
// listen // listen
try zap.listen("3000", null, listen_settings); try zap.listen("3000", null, listen_settings);
std.debug.print("Listening on port 3000\n", .{}); std.debug.print("Listening on port 3000\n", .{});
std.debug.print("debug4\n", .{});
// start working // start working
zap.start(.{ zap.start(.{
.threads = 4, .threads = 4,

View file

@ -1,6 +1,7 @@
// zig type definitions for facilio lib // zig type definitions for facilio lib
// or maybe let's just make it zap directly... // or maybe let's just make it zap directly...
const std = @import("std");
pub const C = @cImport({ pub const C = @cImport({
@cInclude("http.h"); @cInclude("http.h");
@cInclude("fio.h"); @cInclude("fio.h");
@ -34,8 +35,7 @@ pub fn listen(port: [*c]const u8, interface: [*c]const u8, settings: ListenSetti
} }
pfolder = pf.ptr; pfolder = pf.ptr;
} }
var x: C.http_settings_s = .{
if (C.http_listen(port, interface, .{
.on_request = settings.on_request, .on_request = settings.on_request,
.on_upgrade = settings.on_upgrade, .on_upgrade = settings.on_upgrade,
.on_response = settings.on_response, .on_response = settings.on_response,
@ -55,7 +55,11 @@ pub fn listen(port: [*c]const u8, interface: [*c]const u8, settings: ListenSetti
.ws_timeout = 0, .ws_timeout = 0,
.log = if (settings.log) 1 else 0, .log = if (settings.log) 1 else 0,
.is_client = 0, .is_client = 0,
}) == -1) { };
// TODO: BUG: without this print statement, -Drelease* loop forever
// in debug2 and debug3
std.debug.print("X\n", .{});
if (C.http_listen(port, interface, x) == -1) {
return error.ListenError; return error.ListenError;
} }
} }