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 {
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 {

View File

@ -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:

View File

@ -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