mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 04:17:38 +03:00
Merge 0457413904
into d962a01bf7
This commit is contained in:
commit
de92334e65
2 changed files with 33 additions and 1 deletions
|
@ -212,7 +212,6 @@ func (w *syscallPacketReadWaiter) InitializeReadWaiter(newBuffer func() *buf.Buf
|
|||
buffer.Truncate(readN)
|
||||
} else {
|
||||
buffer.Release()
|
||||
buffer = nil
|
||||
}
|
||||
if w.readErr == syscall.EAGAIN {
|
||||
return false
|
||||
|
|
|
@ -13,11 +13,17 @@ import (
|
|||
N "github.com/sagernet/sing/common/network"
|
||||
)
|
||||
|
||||
var (
|
||||
_ N.NetPacketConn = (*Conn)(nil)
|
||||
_ N.PacketReadWaiter = (*Conn)(nil)
|
||||
)
|
||||
|
||||
type Conn struct {
|
||||
net.Conn
|
||||
isConnect bool
|
||||
destination M.Socksaddr
|
||||
writer N.VectorisedWriter
|
||||
newBuffer func() *buf.Buffer
|
||||
}
|
||||
|
||||
func NewConn(conn net.Conn, request Request) *Conn {
|
||||
|
@ -141,6 +147,33 @@ func (c *Conn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error {
|
|||
return c.writer.WriteVectorised([]*buf.Buffer{header, buffer})
|
||||
}
|
||||
|
||||
func (c *Conn) InitializeReadWaiter(newBuffer func() *buf.Buffer) {
|
||||
c.newBuffer = newBuffer
|
||||
}
|
||||
|
||||
func (c *Conn) WaitReadPacket() (destination M.Socksaddr, err error) {
|
||||
if c.isConnect {
|
||||
destination = c.destination
|
||||
} else {
|
||||
destination, err = AddrParser.ReadAddrPort(c.Conn)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
var length uint16
|
||||
err = binary.Read(c.Conn, binary.BigEndian, &length)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
buffer := c.newBuffer()
|
||||
_, err = buffer.ReadFullFrom(c.Conn, int(length))
|
||||
if err != nil {
|
||||
buffer.Release()
|
||||
return M.Socksaddr{}, E.Cause(err, "UoT read")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Conn) NeedAdditionalReadDeadline() bool {
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue