mirror of
https://github.com/zigzap/zap.git
synced 2025-10-21 15:44:10 +00:00
Fix var vs const for files under src/
This commit is contained in:
parent
21d8afb21a
commit
13559620f6
4 changed files with 40 additions and 42 deletions
58
src/fio.zig
58
src/fio.zig
|
@ -118,10 +118,10 @@ pub const struct_fio_str_info_s = extern struct {
|
||||||
pub const fio_str_info_s = struct_fio_str_info_s;
|
pub const fio_str_info_s = struct_fio_str_info_s;
|
||||||
pub extern fn http_send_body(h: [*c]http_s, data: ?*anyopaque, length: usize) c_int;
|
pub extern fn http_send_body(h: [*c]http_s, data: ?*anyopaque, length: usize) c_int;
|
||||||
pub fn fiobj_each1(arg_o: FIOBJ, arg_start_at: usize, arg_task: ?*const fn (FIOBJ, ?*anyopaque) callconv(.C) c_int, arg_arg: ?*anyopaque) callconv(.C) usize {
|
pub fn fiobj_each1(arg_o: FIOBJ, arg_start_at: usize, arg_task: ?*const fn (FIOBJ, ?*anyopaque) callconv(.C) c_int, arg_arg: ?*anyopaque) callconv(.C) usize {
|
||||||
var o = arg_o;
|
const o = arg_o;
|
||||||
var start_at = arg_start_at;
|
const start_at = arg_start_at;
|
||||||
var task = arg_task;
|
const task = arg_task;
|
||||||
var arg = arg_arg;
|
const arg = arg_arg;
|
||||||
if ((((o != 0) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 0)))))) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) != @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6)))))) and (fiobj_type_vtable(o).*.each != null)) return fiobj_type_vtable(o).*.each.?(o, start_at, task, arg);
|
if ((((o != 0) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 0)))))) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) != @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6)))))) and (fiobj_type_vtable(o).*.each != null)) return fiobj_type_vtable(o).*.each.?(o, start_at, task, arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -288,8 +288,8 @@ pub const fiobj_object_header_s = extern struct {
|
||||||
ref: u32,
|
ref: u32,
|
||||||
};
|
};
|
||||||
pub fn fiobj_type_is(arg_o: FIOBJ, arg_type: fiobj_type_enum) callconv(.C) usize {
|
pub fn fiobj_type_is(arg_o: FIOBJ, arg_type: fiobj_type_enum) callconv(.C) usize {
|
||||||
var o = arg_o;
|
const o = arg_o;
|
||||||
var @"type" = arg_type;
|
const @"type" = arg_type;
|
||||||
while (true) {
|
while (true) {
|
||||||
switch (@as(c_int, @bitCast(@as(c_uint, @"type")))) {
|
switch (@as(c_int, @bitCast(@as(c_uint, @"type")))) {
|
||||||
@as(c_int, 1) => return @as(usize, @bitCast(@as(c_long, @intFromBool(((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) != 0) or (@as(c_int, @bitCast(@as(c_uint, @as([*c]fiobj_type_enum, @ptrFromInt(o))[@as(c_uint, @intCast(@as(c_int, 0)))]))) == FIOBJ_T_NUMBER))))),
|
@as(c_int, 1) => return @as(usize, @bitCast(@as(c_long, @intFromBool(((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) != 0) or (@as(c_int, @bitCast(@as(c_uint, @as([*c]fiobj_type_enum, @ptrFromInt(o))[@as(c_uint, @intCast(@as(c_int, 0)))]))) == FIOBJ_T_NUMBER))))),
|
||||||
|
@ -311,7 +311,7 @@ pub fn fiobj_type_is(arg_o: FIOBJ, arg_type: fiobj_type_enum) callconv(.C) usize
|
||||||
return @as(usize, @bitCast(@as(c_long, @intFromBool((((o != 0) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 0)))))) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) != @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6)))))) and (@as(c_int, @bitCast(@as(c_uint, @as([*c]fiobj_type_enum, @ptrCast(@alignCast(@as(?*anyopaque, @ptrFromInt(o & ~@as(usize, @bitCast(@as(c_long, @as(c_int, 7)))))))))[@as(c_uint, @intCast(@as(c_int, 0)))]))) == @as(c_int, @bitCast(@as(c_uint, @"type"))))))));
|
return @as(usize, @bitCast(@as(c_long, @intFromBool((((o != 0) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 0)))))) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) != @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6)))))) and (@as(c_int, @bitCast(@as(c_uint, @as([*c]fiobj_type_enum, @ptrCast(@alignCast(@as(?*anyopaque, @ptrFromInt(o & ~@as(usize, @bitCast(@as(c_long, @as(c_int, 7)))))))))[@as(c_uint, @intCast(@as(c_int, 0)))]))) == @as(c_int, @bitCast(@as(c_uint, @"type"))))))));
|
||||||
}
|
}
|
||||||
pub fn fiobj_type(arg_o: FIOBJ) callconv(.C) fiobj_type_enum {
|
pub fn fiobj_type(arg_o: FIOBJ) callconv(.C) fiobj_type_enum {
|
||||||
var o = arg_o;
|
const o = arg_o;
|
||||||
if (!(o != 0)) return @as(u8, @bitCast(@as(i8, @truncate(FIOBJ_T_NULL))));
|
if (!(o != 0)) return @as(u8, @bitCast(@as(i8, @truncate(FIOBJ_T_NULL))));
|
||||||
if ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) != 0) return @as(u8, @bitCast(@as(i8, @truncate(FIOBJ_T_NUMBER))));
|
if ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) != 0) return @as(u8, @bitCast(@as(i8, @truncate(FIOBJ_T_NUMBER))));
|
||||||
if ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) return @as(u8, @bitCast(@as(u8, @truncate(o))));
|
if ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) return @as(u8, @bitCast(@as(u8, @truncate(o))));
|
||||||
|
@ -326,7 +326,7 @@ pub extern const FIOBJECT_VTABLE_ARRAY: fiobj_object_vtable_s;
|
||||||
pub extern const FIOBJECT_VTABLE_HASH: fiobj_object_vtable_s;
|
pub extern const FIOBJECT_VTABLE_HASH: fiobj_object_vtable_s;
|
||||||
pub extern const FIOBJECT_VTABLE_DATA: fiobj_object_vtable_s;
|
pub extern const FIOBJECT_VTABLE_DATA: fiobj_object_vtable_s;
|
||||||
pub fn fiobj_type_vtable(arg_o: FIOBJ) callconv(.C) [*c]const fiobj_object_vtable_s {
|
pub fn fiobj_type_vtable(arg_o: FIOBJ) callconv(.C) [*c]const fiobj_object_vtable_s {
|
||||||
var o = arg_o;
|
const o = arg_o;
|
||||||
while (true) {
|
while (true) {
|
||||||
switch (@as(c_int, @bitCast(@as(c_uint, fiobj_type(o))))) {
|
switch (@as(c_int, @bitCast(@as(c_uint, fiobj_type(o))))) {
|
||||||
@as(c_int, 1) => return &FIOBJECT_VTABLE_NUMBER,
|
@as(c_int, 1) => return &FIOBJECT_VTABLE_NUMBER,
|
||||||
|
@ -361,7 +361,7 @@ pub fn fiobj_obj2float(o: FIOBJ) callconv(.C) f64 {
|
||||||
pub extern fn fio_ltocstr(c_long) fio_str_info_s;
|
pub extern fn fio_ltocstr(c_long) fio_str_info_s;
|
||||||
pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.C) fio_str_info_s {
|
pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.C) fio_str_info_s {
|
||||||
if (!(o != 0)) {
|
if (!(o != 0)) {
|
||||||
var ret: fio_str_info_s = fio_str_info_s{
|
const ret: fio_str_info_s = fio_str_info_s{
|
||||||
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
||||||
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 4)))),
|
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 4)))),
|
||||||
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("null"))),
|
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("null"))),
|
||||||
|
@ -374,7 +374,7 @@ pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.C) fio_str_info_s {
|
||||||
switch (@as(c_int, @bitCast(@as(c_uint, @as(u8, @bitCast(@as(u8, @truncate(o)))))))) {
|
switch (@as(c_int, @bitCast(@as(c_uint, @as(u8, @bitCast(@as(u8, @truncate(o)))))))) {
|
||||||
@as(c_int, 6) => {
|
@as(c_int, 6) => {
|
||||||
{
|
{
|
||||||
var ret: fio_str_info_s = fio_str_info_s{
|
const ret: fio_str_info_s = fio_str_info_s{
|
||||||
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
||||||
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 4)))),
|
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 4)))),
|
||||||
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("null"))),
|
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("null"))),
|
||||||
|
@ -384,7 +384,7 @@ pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.C) fio_str_info_s {
|
||||||
},
|
},
|
||||||
@as(c_int, 38) => {
|
@as(c_int, 38) => {
|
||||||
{
|
{
|
||||||
var ret: fio_str_info_s = fio_str_info_s{
|
const ret: fio_str_info_s = fio_str_info_s{
|
||||||
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
||||||
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 5)))),
|
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 5)))),
|
||||||
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("false"))),
|
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("false"))),
|
||||||
|
@ -394,7 +394,7 @@ pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.C) fio_str_info_s {
|
||||||
},
|
},
|
||||||
@as(c_int, 22) => {
|
@as(c_int, 22) => {
|
||||||
{
|
{
|
||||||
var ret: fio_str_info_s = fio_str_info_s{
|
const ret: fio_str_info_s = fio_str_info_s{
|
||||||
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
||||||
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 4)))),
|
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 4)))),
|
||||||
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("true"))),
|
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("true"))),
|
||||||
|
@ -534,21 +534,21 @@ pub extern fn http_mimetype_register(file_ext: [*c]u8, file_ext_len: usize, mime
|
||||||
pub extern fn http_mimetype_find(file_ext: [*c]u8, file_ext_len: usize) FIOBJ;
|
pub extern fn http_mimetype_find(file_ext: [*c]u8, file_ext_len: usize) FIOBJ;
|
||||||
pub extern fn http_mimetype_find2(url: FIOBJ) FIOBJ;
|
pub extern fn http_mimetype_find2(url: FIOBJ) FIOBJ;
|
||||||
pub extern fn http_mimetype_clear() void;
|
pub extern fn http_mimetype_clear() void;
|
||||||
pub extern var HTTP_HEADER_ACCEPT: FIOBJ;
|
pub extern const HTTP_HEADER_ACCEPT: FIOBJ;
|
||||||
pub extern var HTTP_HEADER_CACHE_CONTROL: FIOBJ;
|
pub extern const HTTP_HEADER_CACHE_CONTROL: FIOBJ;
|
||||||
pub extern var HTTP_HEADER_CONNECTION: FIOBJ;
|
pub extern const HTTP_HEADER_CONNECTION: FIOBJ;
|
||||||
pub extern var HTTP_HEADER_CONTENT_ENCODING: FIOBJ;
|
pub extern const HTTP_HEADER_CONTENT_ENCODING: FIOBJ;
|
||||||
pub extern var HTTP_HEADER_CONTENT_LENGTH: FIOBJ;
|
pub extern const HTTP_HEADER_CONTENT_LENGTH: FIOBJ;
|
||||||
pub extern var HTTP_HEADER_CONTENT_RANGE: FIOBJ;
|
pub extern const HTTP_HEADER_CONTENT_RANGE: FIOBJ;
|
||||||
pub extern var HTTP_HEADER_CONTENT_TYPE: FIOBJ;
|
pub extern const HTTP_HEADER_CONTENT_TYPE: FIOBJ;
|
||||||
pub extern var HTTP_HEADER_COOKIE: FIOBJ;
|
pub extern const HTTP_HEADER_COOKIE: FIOBJ;
|
||||||
pub extern var HTTP_HEADER_DATE: FIOBJ;
|
pub extern const HTTP_HEADER_DATE: FIOBJ;
|
||||||
pub extern var HTTP_HEADER_ETAG: FIOBJ;
|
pub extern const HTTP_HEADER_ETAG: FIOBJ;
|
||||||
pub extern var HTTP_HEADER_HOST: FIOBJ;
|
pub extern const HTTP_HEADER_HOST: FIOBJ;
|
||||||
pub extern var HTTP_HEADER_LAST_MODIFIED: FIOBJ;
|
pub extern const HTTP_HEADER_LAST_MODIFIED: FIOBJ;
|
||||||
pub extern var HTTP_HEADER_ORIGIN: FIOBJ;
|
pub extern const HTTP_HEADER_ORIGIN: FIOBJ;
|
||||||
pub extern var HTTP_HEADER_SET_COOKIE: FIOBJ;
|
pub extern const HTTP_HEADER_SET_COOKIE: FIOBJ;
|
||||||
pub extern var HTTP_HEADER_UPGRADE: FIOBJ;
|
pub extern const HTTP_HEADER_UPGRADE: FIOBJ;
|
||||||
pub extern fn http_req2str(h: [*c]http_s) FIOBJ;
|
pub extern fn http_req2str(h: [*c]http_s) FIOBJ;
|
||||||
pub extern fn http_write_log(h: [*c]http_s) void;
|
pub extern fn http_write_log(h: [*c]http_s) void;
|
||||||
pub extern fn http_gmtime(timer: time_t, tmbuf: [*c]struct_tm) [*c]struct_tm;
|
pub extern fn http_gmtime(timer: time_t, tmbuf: [*c]struct_tm) [*c]struct_tm;
|
||||||
|
@ -556,8 +556,8 @@ pub extern fn http_date2rfc7231(target: [*c]u8, tmbuf: [*c]struct_tm) usize;
|
||||||
pub extern fn http_date2rfc2109(target: [*c]u8, tmbuf: [*c]struct_tm) usize;
|
pub extern fn http_date2rfc2109(target: [*c]u8, tmbuf: [*c]struct_tm) usize;
|
||||||
pub extern fn http_date2rfc2822(target: [*c]u8, tmbuf: [*c]struct_tm) usize;
|
pub extern fn http_date2rfc2822(target: [*c]u8, tmbuf: [*c]struct_tm) usize;
|
||||||
pub fn http_date2str(arg_target: [*c]u8, arg_tmbuf: [*c]struct_tm) callconv(.C) usize {
|
pub fn http_date2str(arg_target: [*c]u8, arg_tmbuf: [*c]struct_tm) callconv(.C) usize {
|
||||||
var target = arg_target;
|
const target = arg_target;
|
||||||
var tmbuf = arg_tmbuf;
|
const tmbuf = arg_tmbuf;
|
||||||
return http_date2rfc7231(target, tmbuf);
|
return http_date2rfc7231(target, tmbuf);
|
||||||
}
|
}
|
||||||
pub extern fn http_time2str(target: [*c]u8, t: time_t) usize;
|
pub extern fn http_time2str(target: [*c]u8, t: time_t) usize;
|
||||||
|
|
|
@ -122,7 +122,7 @@ pub fn Basic(comptime Lookup: type, comptime kind: BasicAuthStrategy) type {
|
||||||
);
|
);
|
||||||
return .AuthFailed;
|
return .AuthFailed;
|
||||||
}
|
}
|
||||||
var decoded = buffer[0..decoded_size];
|
const decoded = buffer[0..decoded_size];
|
||||||
decoder.decode(decoded, encoded) catch |err| {
|
decoder.decode(decoded, encoded) catch |err| {
|
||||||
zap.debug(
|
zap.debug(
|
||||||
"ERROR: UserPassAuth: unable to decode `{s}`: {any}\n",
|
"ERROR: UserPassAuth: unable to decode `{s}`: {any}\n",
|
||||||
|
@ -400,7 +400,7 @@ pub fn UserPassSession(comptime Lookup: type, comptime lockedPwLookups: bool) ty
|
||||||
lookup: *Lookup,
|
lookup: *Lookup,
|
||||||
args: UserPassSessionArgs,
|
args: UserPassSessionArgs,
|
||||||
) !Self {
|
) !Self {
|
||||||
var ret: Self = .{
|
return Self{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.settings = .{
|
.settings = .{
|
||||||
.usernameParam = try allocator.dupe(u8, args.usernameParam),
|
.usernameParam = try allocator.dupe(u8, args.usernameParam),
|
||||||
|
@ -413,8 +413,6 @@ pub fn UserPassSession(comptime Lookup: type, comptime lockedPwLookups: bool) ty
|
||||||
.lookup = lookup,
|
.lookup = lookup,
|
||||||
.sessionTokens = SessionTokenMap.init(allocator),
|
.sessionTokens = SessionTokenMap.init(allocator),
|
||||||
};
|
};
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// De-init this authenticator.
|
/// De-init this authenticator.
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub fn handle_func(self: *Self, path: []const u8, h: zap.HttpRequestFn) !void {
|
||||||
pub fn serve(self: *Self, r: zap.Request) void {
|
pub fn serve(self: *Self, r: zap.Request) void {
|
||||||
const path = if (r.path) |p| p else "/";
|
const path = if (r.path) |p| p else "/";
|
||||||
|
|
||||||
var route = self.routes.get(path);
|
const route = self.routes.get(path);
|
||||||
|
|
||||||
if (route) |handler| {
|
if (route) |handler| {
|
||||||
handler(r);
|
handler(r);
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub fn Handler(comptime ContextType: type) type {
|
||||||
|
|
||||||
/// This function will end the HTTP stage of the connection and attempt to "upgrade" to a WebSockets connection.
|
/// This function will end the HTTP stage of the connection and attempt to "upgrade" to a WebSockets connection.
|
||||||
pub fn upgrade(h: [*c]fio.http_s, settings: *WebSocketSettings) WebSocketError!void {
|
pub fn upgrade(h: [*c]fio.http_s, settings: *WebSocketSettings) WebSocketError!void {
|
||||||
var fio_settings: fio.websocket_settings_s = .{
|
const fio_settings: fio.websocket_settings_s = .{
|
||||||
.on_message = internal_on_message,
|
.on_message = internal_on_message,
|
||||||
.on_open = internal_on_open,
|
.on_open = internal_on_open,
|
||||||
.on_ready = internal_on_ready,
|
.on_ready = internal_on_ready,
|
||||||
|
@ -64,8 +64,8 @@ pub fn Handler(comptime ContextType: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn internal_on_message(handle: WsHandle, msg: fio.fio_str_info_s, is_text: u8) callconv(.C) void {
|
fn internal_on_message(handle: WsHandle, msg: fio.fio_str_info_s, is_text: u8) callconv(.C) void {
|
||||||
var user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
const user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||||
var message = msg.data[0..msg.len];
|
const message = msg.data[0..msg.len];
|
||||||
if (user_provided_settings) |settings| {
|
if (user_provided_settings) |settings| {
|
||||||
if (settings.on_message) |on_message| {
|
if (settings.on_message) |on_message| {
|
||||||
on_message(settings.context, handle, message, is_text == 1);
|
on_message(settings.context, handle, message, is_text == 1);
|
||||||
|
@ -74,7 +74,7 @@ pub fn Handler(comptime ContextType: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn internal_on_open(handle: WsHandle) callconv(.C) void {
|
fn internal_on_open(handle: WsHandle) callconv(.C) void {
|
||||||
var user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
const user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||||
if (user_provided_settings) |settings| {
|
if (user_provided_settings) |settings| {
|
||||||
if (settings.on_open) |on_open| {
|
if (settings.on_open) |on_open| {
|
||||||
on_open(settings.context, handle);
|
on_open(settings.context, handle);
|
||||||
|
@ -83,7 +83,7 @@ pub fn Handler(comptime ContextType: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn internal_on_ready(handle: WsHandle) callconv(.C) void {
|
fn internal_on_ready(handle: WsHandle) callconv(.C) void {
|
||||||
var user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
const user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||||
if (user_provided_settings) |settings| {
|
if (user_provided_settings) |settings| {
|
||||||
if (settings.on_ready) |on_ready| {
|
if (settings.on_ready) |on_ready| {
|
||||||
on_ready(settings.context, handle);
|
on_ready(settings.context, handle);
|
||||||
|
@ -92,7 +92,7 @@ pub fn Handler(comptime ContextType: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn internal_on_shutdown(handle: WsHandle) callconv(.C) void {
|
fn internal_on_shutdown(handle: WsHandle) callconv(.C) void {
|
||||||
var user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
const user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||||
if (user_provided_settings) |settings| {
|
if (user_provided_settings) |settings| {
|
||||||
if (settings.on_shutdown) |on_shutdown| {
|
if (settings.on_shutdown) |on_shutdown| {
|
||||||
on_shutdown(settings.context, handle);
|
on_shutdown(settings.context, handle);
|
||||||
|
@ -101,7 +101,7 @@ pub fn Handler(comptime ContextType: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn internal_on_close(uuid: isize, udata: ?*anyopaque) callconv(.C) void {
|
fn internal_on_close(uuid: isize, udata: ?*anyopaque) callconv(.C) void {
|
||||||
var user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(udata)));
|
const user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(udata)));
|
||||||
if (user_provided_settings) |settings| {
|
if (user_provided_settings) |settings| {
|
||||||
if (settings.on_close) |on_close| {
|
if (settings.on_close) |on_close| {
|
||||||
on_close(settings.context, uuid);
|
on_close(settings.context, uuid);
|
||||||
|
@ -192,7 +192,7 @@ pub fn Handler(comptime ContextType: type) type {
|
||||||
/// we need it to look up the ziggified callbacks.
|
/// we need it to look up the ziggified callbacks.
|
||||||
pub inline fn subscribe(handle: WsHandle, args: *SubscribeArgs) WebSocketError!usize {
|
pub inline fn subscribe(handle: WsHandle, args: *SubscribeArgs) WebSocketError!usize {
|
||||||
if (handle == null) return error.SubscribeError;
|
if (handle == null) return error.SubscribeError;
|
||||||
var fio_args: fio.websocket_subscribe_s_zigcompat = .{
|
const fio_args: fio.websocket_subscribe_s_zigcompat = .{
|
||||||
.ws = handle.?,
|
.ws = handle.?,
|
||||||
.channel = util.str2fio(args.channel),
|
.channel = util.str2fio(args.channel),
|
||||||
.on_message = if (args.on_message) |_| internal_subscription_on_message else null,
|
.on_message = if (args.on_message) |_| internal_subscription_on_message else null,
|
||||||
|
|
Loading…
Add table
Reference in a new issue