Fix packet conn api

This commit is contained in:
世界 2023-04-25 13:49:43 +08:00
parent f6a6b7258c
commit ff03af056a
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 100 additions and 0 deletions

View file

@ -209,6 +209,37 @@ func (c *clientPacketConn) FrontHeadroom() int {
return 2
}
func (c *clientPacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
if !c.responseRead {
err = c.readResponse()
if err != nil {
return
}
c.responseRead = true
}
var length uint16
err = binary.Read(c.ExtendedConn, binary.BigEndian, &length)
if err != nil {
return
}
if cap(p) < int(length) {
return 0, nil, io.ErrShortBuffer
}
n, err = io.ReadFull(c.ExtendedConn, p[:length])
return
}
func (c *clientPacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
if !c.requestWritten {
return c.writeRequest(p)
}
err = binary.Write(c.ExtendedConn, binary.BigEndian, uint16(len(p)))
if err != nil {
return
}
return c.ExtendedConn.Write(p)
}
func (c *clientPacketConn) ReadPacket(buffer *buf.Buffer) (destination M.Socksaddr, err error) {
err = c.ReadBuffer(buffer)
return