Chore: adjust the signal
This commit is contained in:
parent
ac4cde1411
commit
f4312cfa5a
2 changed files with 7 additions and 6 deletions
|
@ -3,9 +3,10 @@
|
||||||
package tun
|
package tun
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Dreamacro/clash/common/pool"
|
"github.com/Dreamacro/clash/common/pool"
|
||||||
"github.com/Dreamacro/clash/listener/tun/device"
|
"github.com/Dreamacro/clash/listener/tun/device"
|
||||||
|
@ -53,9 +54,7 @@ func Open(name string, mtu uint32) (_ device.Device, err error) {
|
||||||
nt, err := tun.CreateTUN(t.name, forcedMTU) // forcedMTU do not work on wintun, need to be setting by other way
|
nt, err := tun.CreateTUN(t.name, forcedMTU) // forcedMTU do not work on wintun, need to be setting by other way
|
||||||
|
|
||||||
// retry if abnormal exit on Windows at last time
|
// retry if abnormal exit on Windows at last time
|
||||||
if err != nil && runtime.GOOS == "windows" &&
|
if err != nil && runtime.GOOS == "windows" && errors.Is(err, os.ErrExist) {
|
||||||
strings.HasSuffix(err.Error(), "file already exists.") {
|
|
||||||
|
|
||||||
nt, err = tun.CreateTUN(t.name, forcedMTU)
|
nt, err = tun.CreateTUN(t.name, forcedMTU)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +79,9 @@ func (t *TUN) Read(packet []byte) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
buff := pool.Get(t.offset + cap(packet))
|
buff := pool.Get(t.offset + cap(packet))
|
||||||
defer pool.Put(buff)
|
defer func() {
|
||||||
|
_ = pool.Put(buff)
|
||||||
|
}()
|
||||||
|
|
||||||
n, err := t.nt.Read(buff, t.offset)
|
n, err := t.nt.Read(buff, t.offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
2
main.go
2
main.go
|
@ -101,7 +101,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
sigCh := make(chan os.Signal, 1)
|
sigCh := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
|
||||||
<-sigCh
|
<-sigCh
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
|
|
Loading…
Reference in a new issue