From 73e9cd8e06058a99f5222572dfd49bae1581002a Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Thu, 12 Jan 2023 19:27:40 -0800 Subject: [PATCH] [Bun.listen] Add flag to close all connections --- src/bun.js/api/bun/socket.zig | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig index 911dc9e892..7a3176072f 100644 --- a/src/bun.js/api/bun/socket.zig +++ b/src/bun.js/api/bun/socket.zig @@ -630,15 +630,23 @@ pub const Listener = struct { // uws.us_socket_context_add_server_name // } - pub fn stop(this: *Listener, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSValue { + pub fn stop(this: *Listener, _: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSValue { + const arguments = callframe.arguments(1); log("close", .{}); - var listener = this.listener orelse return JSValue.jsUndefined(); - this.listener = null; - listener.close(this.ssl); + if (arguments.len > 0 and arguments.ptr[0].isBoolean() and arguments.ptr[0].toBoolean() and this.socket_context != null) { + this.socket_context.?.close(this.ssl); + this.listener = null; + } else { + var listener = this.listener orelse return JSValue.jsUndefined(); + this.listener = null; + listener.close(this.ssl); + } + this.poll_ref.unref(this.handlers.vm); if (this.handlers.active_connections == 0) { this.handlers.unprotect(); + this.socket_context.?.close(this.ssl); this.socket_context.?.deinit(this.ssl); this.socket_context = null; this.strong_self.clear(); @@ -661,6 +669,7 @@ pub const Listener = struct { std.debug.assert(this.handlers.active_connections == 0); if (this.socket_context) |ctx| { + ctx.close(this.ssl); ctx.deinit(this.ssl); }