From ea46fa321d56064d92d29b330fe8a792c951ca45 Mon Sep 17 00:00:00 2001 From: injoy <1113655791@qq.com> Date: Tue, 14 Nov 2023 14:39:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dial/dial_serial.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/dial/dial_serial.go b/dial/dial_serial.go index fff1f43..9a64a0c 100644 --- a/dial/dial_serial.go +++ b/dial/dial_serial.go @@ -2,10 +2,12 @@ package dial import ( "github.com/goburrow/serial" - "github.com/injoyai/base/oss" "github.com/injoyai/io" "github.com/injoyai/logs" serial2 "go.bug.st/serial" + "os" + "os/signal" + "syscall" "time" ) @@ -54,13 +56,25 @@ func WithSerial(cfg *SerialConfig) io.DialFunc { func NewSerial(cfg *SerialConfig, options ...io.OptionClient) (*io.Client, error) { return io.NewDial(WithSerial(cfg), func(c *io.Client) { c.SetOptions(options...) - oss.ListenExit(func() { c.CloseAll() }) + exitChan := make(chan os.Signal) + signal.Notify(exitChan, os.Interrupt, os.Kill, syscall.SIGTERM) + go func(c *io.Client) { + <-exitChan + c.CloseAll() + os.Exit(-127) + }(c) }) } func RedialSerial(cfg *SerialConfig, options ...io.OptionClient) *io.Client { c := io.Redial(WithSerial(cfg), options...) - oss.ListenExit(func() { c.CloseAll() }) + exitChan := make(chan os.Signal) + signal.Notify(exitChan, os.Interrupt, os.Kill, syscall.SIGTERM) + go func(c *io.Client) { + <-exitChan + c.CloseAll() + os.Exit(-127) + }(c) return c }