diff --git a/adapter/outbound/base.go b/adapter/outbound/base.go index e4a553b9..c5901d7f 100644 --- a/adapter/outbound/base.go +++ b/adapter/outbound/base.go @@ -259,10 +259,11 @@ func (c *packetConn) ReaderReplaceable() bool { } func newPacketConn(pc net.PacketConn, a C.ProxyAdapter) C.PacketConn { + epc := N.NewEnhancePacketConn(pc) if _, ok := pc.(syscall.Conn); !ok { // exclusion system conn like *net.UDPConn - pc = N.NewDeadlinePacketConn(pc) // most conn from outbound can't handle readDeadline correctly + epc = N.NewDeadlineEnhancePacketConn(epc) // most conn from outbound can't handle readDeadline correctly } - return &packetConn{N.NewEnhancePacketConn(pc), []string{a.Name()}, a.Name(), utils.NewUUIDV4().String(), parseRemoteDestination(a.Addr())} + return &packetConn{epc, []string{a.Name()}, a.Name(), utils.NewUUIDV4().String(), parseRemoteDestination(a.Addr())} } func parseRemoteDestination(addr string) string { diff --git a/common/net/deadline/packet.go b/common/net/deadline/packet.go index 4f2e9111..38b5f579 100644 --- a/common/net/deadline/packet.go +++ b/common/net/deadline/packet.go @@ -128,6 +128,10 @@ type EnhancePacketConn struct { enhancePacketConn packet.EnhancePacketConn } +func NewEnhancePacketConn(pc packet.EnhancePacketConn) packet.EnhancePacketConn { + return NewPacketConn(pc).(packet.EnhancePacketConn) +} + func (c *EnhancePacketConn) WaitReadFrom() (data []byte, put func(), addr net.Addr, err error) { select { case result := <-c.resultCh: diff --git a/common/net/packet.go b/common/net/packet.go index 2895b537..261c721c 100644 --- a/common/net/packet.go +++ b/common/net/packet.go @@ -12,6 +12,7 @@ type EnhancePacketConn = packet.EnhancePacketConn var NewEnhancePacketConn = packet.NewEnhancePacketConn var NewDeadlinePacketConn = deadline.NewPacketConn +var NewDeadlineEnhancePacketConn = deadline.NewEnhancePacketConn type threadSafePacketConn struct { net.PacketConn