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

housekeeping

This commit is contained in:
Rene Schallner 2023-04-21 22:18:22 +02:00
parent 17d72e1b78
commit b197fb5ff7
4 changed files with 19 additions and 7 deletions

View file

@ -28,6 +28,10 @@ pub fn init(
}; };
} }
pub fn deinit(self: *Self) void {
self.users.deinit();
}
pub fn getUsers(self: *Self) *Users { pub fn getUsers(self: *Self) *Users {
return &self.users; return &self.users;
} }

View file

@ -20,8 +20,10 @@ pub fn main() !void {
.max_body_size = 100 * 1024 * 1024, .max_body_size = 100 * 1024 * 1024,
}, },
); );
defer listener.deinit();
var endpoint = Endpoint.init(allocator, "/users"); var endpoint = Endpoint.init(allocator, "/users");
defer endpoint.deinit();
// add endpoint // add endpoint
try listener.addEndpoint(endpoint.getUserEndpoint()); try listener.addEndpoint(endpoint.getUserEndpoint());

View file

@ -29,6 +29,10 @@ pub fn init(a: std.mem.Allocator) Self {
}; };
} }
pub fn deinit(self: *Self) void {
self.users.deinit();
}
// the request will be freed (and its mem reused by facilio) when it's // the request will be freed (and its mem reused by facilio) when it's
// completed, so we take copies of the names // completed, so we take copies of the names
pub fn addByName(self: *Self, first: ?[]const u8, last: ?[]const u8) !usize { pub fn addByName(self: *Self, first: ?[]const u8, last: ?[]const u8) !usize {

View file

@ -160,9 +160,6 @@ pub const EndpointListenerError = error{
EndpointPathShadowError, EndpointPathShadowError,
}; };
// var endpoints: std.StringHashMap(*SimpleEndpoint) = undefined;
var endpoints: std.ArrayList(*SimpleEndpoint) = undefined;
// NOTE: We switch on path.startsWith -> so use endpoints with distinctly // NOTE: We switch on path.startsWith -> so use endpoints with distinctly
// starting names!! // starting names!!
pub const SimpleEndpointListener = struct { pub const SimpleEndpointListener = struct {
@ -171,10 +168,15 @@ pub const SimpleEndpointListener = struct {
const Self = @This(); const Self = @This();
/// static struct member endpoints
var endpoints: std.ArrayList(*SimpleEndpoint) = undefined;
pub fn init(a: std.mem.Allocator, l: ListenerSettings) Self { pub fn init(a: std.mem.Allocator, l: ListenerSettings) Self {
var ls = l;
ls.on_request = onRequest;
endpoints = std.ArrayList(*SimpleEndpoint).init(a); endpoints = std.ArrayList(*SimpleEndpoint).init(a);
var ls = l; // take copy of listener settings
ls.on_request = onRequest;
return .{ return .{
.listener = Listener.init(ls), .listener = Listener.init(ls),
.allocator = a, .allocator = a,
@ -186,11 +188,11 @@ pub const SimpleEndpointListener = struct {
endpoints.deinit(); endpoints.deinit();
} }
pub fn listen(self: *SimpleEndpointListener) !void { pub fn listen(self: *Self) !void {
try self.listener.listen(); try self.listener.listen();
} }
pub fn addEndpoint(self: *SimpleEndpointListener, e: *SimpleEndpoint) !void { pub fn addEndpoint(self: *Self, e: *SimpleEndpoint) !void {
_ = self; _ = self;
for (endpoints.items) |other| { for (endpoints.items) |other| {
if (std.mem.startsWith( if (std.mem.startsWith(