fix api usage

pull/314/merge v2.10.1
Darien Raymond 2016-12-11 21:43:16 +01:00
parent 58bcfcee4e
commit eee23e6718
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
4 changed files with 13 additions and 9 deletions

View File

@ -145,7 +145,7 @@ func (v *UDPNameServer) HandleResponse(dest v2net.Destination, payload *buf.Buff
} }
func (v *UDPNameServer) BuildQueryA(domain string, id uint16) *buf.Buffer { func (v *UDPNameServer) BuildQueryA(domain string, id uint16) *buf.Buffer {
buffer := buf.New()
msg := new(dns.Msg) msg := new(dns.Msg)
msg.Id = id msg.Id = id
msg.RecursionDesired = true msg.RecursionDesired = true
@ -156,8 +156,11 @@ func (v *UDPNameServer) BuildQueryA(domain string, id uint16) *buf.Buffer {
Qclass: dns.ClassINET, Qclass: dns.ClassINET,
}} }}
writtenBuffer, _ := msg.PackBuffer(buffer.Bytes()) buffer := buf.New()
buffer.Append(writtenBuffer) buffer.AppendSupplier(func(b []byte) (int, error) {
writtenBuffer, err := msg.PackBuffer(b)
return len(writtenBuffer), err
})
return buffer return buffer
} }

View File

@ -136,7 +136,7 @@ func ReadUserPassRequest(reader io.Reader) (request Socks5UserPassRequest, err e
if err != nil { if err != nil {
return return
} }
request.username = string(buffer.Bytes()) request.username = buffer.String()
err = buffer.AppendSupplier(buf.ReadFullFrom(reader, 1)) err = buffer.AppendSupplier(buf.ReadFullFrom(reader, 1))
if err != nil { if err != nil {
@ -147,7 +147,7 @@ func ReadUserPassRequest(reader io.Reader) (request Socks5UserPassRequest, err e
if err != nil { if err != nil {
return return
} }
request.password = string(buffer.Bytes()) request.password = buffer.String()
return return
} }

View File

@ -58,8 +58,10 @@ func (*HeaderReader) Read(reader io.Reader) (*buf.Buffer, error) {
break break
} }
if buffer.Len() >= len(ENDING) { if buffer.Len() >= len(ENDING) {
copy(buffer.Bytes(), buffer.BytesFrom(buffer.Len()-len(ENDING))) leftover := buffer.BytesFrom(buffer.Len() - len(ENDING))
buffer.Slice(0, len(ENDING)) buffer.Reset(func(b []byte) (int, error) {
return copy(b, leftover), nil
})
} }
} }
if buffer.IsEmpty() { if buffer.IsEmpty() {

View File

@ -92,8 +92,7 @@ func (o *ClientConnection) Run() {
defer payload.Release() defer payload.Release()
for { for {
payload.Clear() err := payload.Reset(buf.ReadFrom(o.Conn))
err := payload.AppendSupplier(buf.ReadFrom(o.Conn))
if err != nil { if err != nil {
payload.Release() payload.Release()
return return