chore: add WaitReadFrom support in quicStreamPacketConn
This commit is contained in:
parent
92f71fd25f
commit
7aae781569
4 changed files with 22 additions and 1 deletions
|
@ -19,6 +19,7 @@ import (
|
|||
"github.com/metacubex/quic-go/congestion"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
|
||||
N "github.com/Dreamacro/clash/common/net"
|
||||
"github.com/Dreamacro/clash/component/dialer"
|
||||
"github.com/Dreamacro/clash/component/proxydialer"
|
||||
tlsC "github.com/Dreamacro/clash/component/tls"
|
||||
|
@ -324,7 +325,7 @@ func (c *hyPacketConn) WaitReadFrom() (data []byte, put func(), addr net.Addr, e
|
|||
return
|
||||
}
|
||||
data = b
|
||||
put = func() {}
|
||||
put = N.NilPut
|
||||
addr = M.ParseSocksaddr(addrStr).UDPAddr()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ import (
|
|||
)
|
||||
|
||||
type EnhancePacketConn = packet.EnhancePacketConn
|
||||
type WaitReadFrom = packet.WaitReadFrom
|
||||
|
||||
var NilPut = packet.NilPut
|
||||
var NewEnhancePacketConn = packet.NewEnhancePacketConn
|
||||
var NewThreadSafePacketConn = packet.NewThreadSafePacketConn
|
||||
var NewRefPacketConn = packet.NewRefPacketConn
|
||||
|
|
|
@ -10,6 +10,8 @@ type WaitReadFrom interface {
|
|||
WaitReadFrom() (data []byte, put func(), addr net.Addr, err error)
|
||||
}
|
||||
|
||||
func NilPut() {}
|
||||
|
||||
type EnhancePacketConn interface {
|
||||
net.PacketConn
|
||||
WaitReadFrom
|
||||
|
|
|
@ -197,6 +197,22 @@ func (q *quicStreamPacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err err
|
|||
return
|
||||
}
|
||||
|
||||
func (q *quicStreamPacketConn) WaitReadFrom() (data []byte, put func(), addr net.Addr, err error) {
|
||||
if q.inputConn != nil {
|
||||
var packet Packet
|
||||
packet, err = ReadPacket(q.inputConn)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
data = packet.DATA
|
||||
put = N.NilPut
|
||||
addr = packet.ADDR.UDPAddr()
|
||||
} else {
|
||||
err = net.ErrClosed
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (q *quicStreamPacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
|
||||
if q.udpRelayMode != "quic" && len(p) > q.maxUdpRelayPacketSize {
|
||||
return 0, quic.ErrMessageTooLarge(q.maxUdpRelayPacketSize)
|
||||
|
|
Loading…
Reference in a new issue