From 84ed66018e9434536604a25bec3dc99f5d173f7c Mon Sep 17 00:00:00 2001 From: zhangyuyu <1580074674@qq.com> Date: Tue, 14 Nov 2023 20:00:26 +0800 Subject: [PATCH] fix issue: Windows Platform did not handle process signal (#3154) --- net/ghttp/ghttp_server_admin_windows.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/net/ghttp/ghttp_server_admin_windows.go b/net/ghttp/ghttp_server_admin_windows.go index 135dc56d5..7d83e3e0d 100644 --- a/net/ghttp/ghttp_server_admin_windows.go +++ b/net/ghttp/ghttp_server_admin_windows.go @@ -9,7 +9,19 @@ package ghttp -// registerSignalHandler does nothing on window platform. -func handleProcessSignal() { +import ( + "context" + "os" + "github.com/gogf/gf/v2/os/gproc" +) + +// handleProcessSignal handles all signals from system in blocking way. +func handleProcessSignal() { + var ctx = context.TODO() + gproc.AddSigHandlerShutdown(func(sig os.Signal) { + shutdownWebServersGracefully(ctx, sig) + }) + + gproc.Listen() }