File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ const MAX_MESSAGE_SIZE = 512 * 1024 + 14 + 140;
4040
4141pub const Server = struct {
4242 app : * App ,
43+ shutdown : bool ,
4344 allocator : Allocator ,
4445 client : ? posix.socket_t ,
4546 listener : ? posix.socket_t ,
@@ -54,16 +55,20 @@ pub const Server = struct {
5455 .app = app ,
5556 .client = null ,
5657 .listener = null ,
58+ .shutdown = false ,
5759 .allocator = allocator ,
5860 .json_version_response = json_version_response ,
5961 };
6062 }
6163
6264 pub fn deinit (self : * Server ) void {
63- self .allocator . free ( self . json_version_response ) ;
65+ self .shutdown = true ;
6466 if (self .listener ) | listener | {
6567 posix .close (listener );
6668 }
69+ // *if* server.run is running, we should really wait for it to return
70+ // before existing from here.
71+ self .allocator .free (self .json_version_response );
6772 }
6873
6974 pub fn run (self : * Server , address : net.Address , timeout_ms : i32 ) ! void {
@@ -82,6 +87,9 @@ pub const Server = struct {
8287 log .info (.app , "server running" , .{ .address = address });
8388 while (true ) {
8489 const socket = posix .accept (listener , null , null , posix .SOCK .NONBLOCK ) catch | err | {
90+ if (self .shutdown ) {
91+ return ;
92+ }
8593 log .err (.app , "CDP accept" , .{ .err = err });
8694 std .Thread .sleep (std .time .ns_per_s );
8795 continue ;
You can’t perform that action at this time.
0 commit comments