web: Update to zig 0.16.0
This commit is contained in:
@@ -8,19 +8,12 @@ const UUID = web.UUID;
|
||||
|
||||
var running: std.atomic.Value(bool) = .init(true);
|
||||
|
||||
fn interruptionHandler(sig: i32) callconv(.c) void {
|
||||
fn interruptionHandler(sig: linux.SIG) callconv(.c) void {
|
||||
var buf: [32]u8 = undefined;
|
||||
|
||||
const signal_name = blk: inline for (@typeInfo(linux.SIG).@"struct".decls) |decl| {
|
||||
if (comptime std.mem.eql(u8, decl.name, "BLOCK") or
|
||||
std.mem.eql(u8, decl.name, "UNBLOCK") or
|
||||
std.mem.eql(u8, decl.name, "SETMASK")) continue;
|
||||
|
||||
const decl_value = @field(linux.SIG, decl.name);
|
||||
if (@TypeOf(decl_value) != comptime_int) continue;
|
||||
if (decl_value == sig) break :blk "SIG" ++ decl.name;
|
||||
} else {
|
||||
break :blk std.fmt.bufPrint(&buf, "#{d}", .{sig}) catch unreachable;
|
||||
const signal_name = switch (sig) {
|
||||
_ => std.fmt.bufPrint(&buf, "#{d}", .{sig}) catch unreachable,
|
||||
inline else => |x| "SIG" ++ @tagName(x),
|
||||
};
|
||||
|
||||
std.log.debug("Interrupted with signal {s}.", .{signal_name});
|
||||
@@ -85,12 +78,8 @@ const Handler = struct {
|
||||
}
|
||||
};
|
||||
|
||||
pub fn main() !void {
|
||||
var gpa: std.heap.GeneralPurposeAllocator(.{
|
||||
.thread_safe = true,
|
||||
}) = .init;
|
||||
defer _ = gpa.deinit();
|
||||
const allocator = gpa.allocator();
|
||||
pub fn main(init: std.process.Init) !void {
|
||||
const allocator = init.gpa;
|
||||
|
||||
_ = ssl.c_ssl.SSL_library_init();
|
||||
_ = ssl.c_ssl.OpenSSL_add_all_algorithms();
|
||||
@@ -106,9 +95,8 @@ pub fn main() !void {
|
||||
try ssl_ctx.usePrivateKeyFile("key.pem", ssl.c_ssl.SSL_FILETYPE_PEM);
|
||||
try ssl_ctx.checkPrivateKey();
|
||||
|
||||
var server = try web.Server.init(allocator, .{
|
||||
var server = try web.Server.init(allocator, init.io, .{
|
||||
.request_handler = Handler.interface(),
|
||||
.address = .initIp4(.{ 127, 0, 0, 1 }, 8000),
|
||||
.ssl_ctx = ssl_ctx,
|
||||
});
|
||||
defer server.deinit(allocator);
|
||||
@@ -118,13 +106,13 @@ pub fn main() !void {
|
||||
.mask = linux.sigemptyset(),
|
||||
.flags = linux.SA.RESETHAND,
|
||||
};
|
||||
signal(linux.SIG.INT, &sigaction);
|
||||
signal(linux.SIG.TERM, &sigaction);
|
||||
signal(.INT, &sigaction);
|
||||
signal(.TERM, &sigaction);
|
||||
|
||||
try server.listen(&running);
|
||||
}
|
||||
|
||||
fn signal(sig: u8, action: *const linux.Sigaction) void {
|
||||
fn signal(sig: linux.SIG, action: *const linux.Sigaction) void {
|
||||
var old_action = std.mem.zeroes(linux.Sigaction);
|
||||
_ = linux.sigaction(sig, null, &old_action);
|
||||
if (old_action.handler.handler == linux.SIG.IGN) return;
|
||||
|
||||
Reference in New Issue
Block a user