tcp: forgot to deinit stuff

This commit is contained in:
Aarnav Tale
2024-08-13 13:05:55 -04:00
parent 5bffa5c3e6
commit e16f398a42
2 changed files with 8 additions and 7 deletions

View File

@ -67,10 +67,12 @@ pub fn init(
/// Deinitializes the server /// Deinitializes the server
pub fn deinit(self: *Server) void { pub fn deinit(self: *Server) void {
self.close(); self.close();
log.info("closing server socket", .{});
log.info("deinitializing server", .{});
self.loop.deinit();
self.comp_pool.deinit(); self.comp_pool.deinit();
self.sock_pool.deinit(); self.sock_pool.deinit();
self.buf_pool.deinit(); self.buf_pool.deinit();
self.loop.deinit();
} }
/// Starts the timer which tries to accept connections /// Starts the timer which tries to accept connections
@ -81,16 +83,13 @@ pub fn start(self: *Server) !void {
try connections.startAccepting(self); try connections.startAccepting(self);
log.info("bound server to socket={any}", .{self.socket}); log.info("bound server to socket={any}", .{self.socket});
// TODO: Stop flag? Only necessary if we support signaling the server // TODO(tale): Stop flag? Only necessary if we support signaling the server
// from the main thread on an event, ie. configuration reloading. // from the main thread on an event, ie. configuration reloading.
while (true) { try self.loop.run(.until_done);
try self.loop.run(.until_done);
}
} }
/// Closes the server socket /// Closes the server socket
pub fn close(self: *Server) void { pub fn close(self: *Server) void {
log.info("closing server socket", .{});
var c: xev.Completion = undefined; var c: xev.Completion = undefined;
self.socket.close(&self.loop, &c, bool, null, (struct { self.socket.close(&self.loop, &c, bool, null, (struct {
fn callback( fn callback(

View File

@ -20,7 +20,9 @@ server: ?Server,
/// up all the internal state necessary prior to starting the thread. It /// up all the internal state necessary prior to starting the thread. It
/// is up to the caller to start the thread with the threadMain entrypoint. /// is up to the caller to start the thread with the threadMain entrypoint.
pub fn init(alloc: Allocator, mailbox: *App.Mailbox.Queue) !Thread { pub fn init(alloc: Allocator, mailbox: *App.Mailbox.Queue) !Thread {
const config = try Config.load(alloc); var config = try Config.load(alloc);
defer config.deinit();
const max_clients = config.@"remote-max-connections"; const max_clients = config.@"remote-max-connections";
const addr = config.@"remote-tcp-socket"; const addr = config.@"remote-tcp-socket";