fix: Deadline not apply on EnhancePacketConn

This commit is contained in:
wwqgtxx 2023-05-11 19:58:50 +08:00
parent 234f7dbd3b
commit 76caab19bf
3 changed files with 8 additions and 2 deletions

View file

@ -259,10 +259,11 @@ func (c *packetConn) ReaderReplaceable() bool {
} }
func newPacketConn(pc net.PacketConn, a C.ProxyAdapter) C.PacketConn { 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 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 { func parseRemoteDestination(addr string) string {

View file

@ -128,6 +128,10 @@ type EnhancePacketConn struct {
enhancePacketConn packet.EnhancePacketConn 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) { func (c *EnhancePacketConn) WaitReadFrom() (data []byte, put func(), addr net.Addr, err error) {
select { select {
case result := <-c.resultCh: case result := <-c.resultCh:

View file

@ -12,6 +12,7 @@ type EnhancePacketConn = packet.EnhancePacketConn
var NewEnhancePacketConn = packet.NewEnhancePacketConn var NewEnhancePacketConn = packet.NewEnhancePacketConn
var NewDeadlinePacketConn = deadline.NewPacketConn var NewDeadlinePacketConn = deadline.NewPacketConn
var NewDeadlineEnhancePacketConn = deadline.NewEnhancePacketConn
type threadSafePacketConn struct { type threadSafePacketConn struct {
net.PacketConn net.PacketConn