fix: close linstener

This commit is contained in:
Skyxim
2022-12-04 15:15:23 +08:00
parent 6fc62da7ae
commit e9d8dd09ac
9 changed files with 23 additions and 18 deletions

View File

@ -52,7 +52,7 @@ func (b *Base) RawAddress() string {
}
// ReCreate implements constant.NewListener
func (*Base) ReCreate(tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter) error {
func (*Base) Listen(tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter) error {
return nil
}

View File

@ -30,9 +30,8 @@ func (h *HTTP) Address() string {
}
// ReCreate implements constant.NewListener
func (h *HTTP) ReCreate(tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter) error {
func (h *HTTP) Listen(tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter) error {
var err error
_ = h.Close()
h.l, err = http.NewWithInfos(h.RawAddress(), h.name, h.preferRulesName, tcpIn)
if err != nil {
return err

View File

@ -39,9 +39,8 @@ func (m *Mixed) Address() string {
}
// ReCreate implements constant.NewListener
func (m *Mixed) ReCreate(tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter) error {
func (m *Mixed) Listen(tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter) error {
var err error
_ = m.Close()
m.l, err = mixed.NewWithInfos(m.RawAddress(), m.name, m.preferRulesName, tcpIn)
if err != nil {
return err

View File

@ -31,9 +31,8 @@ func (r *Redir) Address() string {
}
// ReCreate implements constant.NewListener
func (r *Redir) ReCreate(tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter) error {
func (r *Redir) Listen(tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter) error {
var err error
_ = r.Close()
r.l, err = redir.NewWithInfos(r.Address(), r.name, r.preferRulesName, tcpIn)
if err != nil {
return err

View File

@ -2,8 +2,6 @@ package inbound
import (
"fmt"
"sync"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/listener/socks"
"github.com/Dreamacro/clash/log"
@ -16,7 +14,6 @@ type SocksOption struct {
type Socks struct {
*Base
mux sync.Mutex
udp bool
stl *socks.Listener
sul *socks.UDPListener
@ -60,11 +57,8 @@ func (s *Socks) Address() string {
}
// ReCreate implements constant.NewListener
func (s *Socks) ReCreate(tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter) error {
s.mux.Lock()
defer s.mux.Unlock()
func (s *Socks) Listen(tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter) error {
var err error
_ = s.Close()
if s.stl, err = socks.NewWithInfos(s.RawAddress(), s.name, s.preferRulesName, tcpIn); err != nil {
return err
}

View File

@ -38,9 +38,8 @@ func (t *TProxy) Address() string {
}
// ReCreate implements constant.NewListener
func (t *TProxy) ReCreate(tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter) error {
func (t *TProxy) Listen(tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter) error {
var err error
_ = t.Close()
t.lTCP, err = tproxy.NewWithInfos(t.RawAddress(), t.name, t.preferRulesName, tcpIn)
if err != nil {
return err