chore: Add read deadline implementation

This commit is contained in:
wwqgtxx
2023-04-09 22:58:05 +08:00
parent 20b0af9a03
commit 6c76312e5c
6 changed files with 24 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import (
"strings"
"github.com/Dreamacro/clash/adapter/inbound"
N "github.com/Dreamacro/clash/common/net"
C "github.com/Dreamacro/clash/constant"
LC "github.com/Dreamacro/clash/listener/config"
"github.com/Dreamacro/clash/transport/shadowsocks/core"
@ -99,7 +100,7 @@ func (l *Listener) AddrList() (addrList []net.Addr) {
}
func (l *Listener) HandleConn(conn net.Conn, in chan<- C.ConnContext, additions ...inbound.Addition) {
conn = l.pickCipher.StreamConn(conn)
conn = N.NewDeadlineConn(l.pickCipher.StreamConn(conn))
target, err := socks5.ReadAddr(conn, make([]byte, socks5.MaxAddrLen))
if err != nil {

View File

@ -4,6 +4,7 @@ import (
"net"
"github.com/Dreamacro/clash/adapter/inbound"
N "github.com/Dreamacro/clash/common/net"
"github.com/Dreamacro/clash/common/pool"
"github.com/Dreamacro/clash/common/sockopt"
C "github.com/Dreamacro/clash/constant"
@ -29,7 +30,7 @@ func NewUDP(addr string, pickCipher core.Cipher, in chan<- C.PacketAdapter) (*UD
}
sl := &UDPListener{l, false}
conn := pickCipher.PacketConn(l)
conn := N.NewDeadlinePacketConn(pickCipher.PacketConn(l))
go func() {
for {
buf := pool.Get(pool.RelayBufferSize)