1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-31 06:25:32 -05:00

Apply buffered reader and writer to socks

This commit is contained in:
v2ray
2016-02-27 11:02:42 +01:00
parent cba26dabe8
commit ef51c600fb
4 changed files with 39 additions and 40 deletions

View File

@@ -295,16 +295,16 @@ func (r *Socks5Response) SetDomain(domain string) {
r.Domain = domain
}
func (r *Socks5Response) Write(buffer *alloc.Buffer) {
buffer.AppendBytes(r.Version, r.Error, 0x00 /* reserved */, r.AddrType)
func (r *Socks5Response) Write(writer io.Writer) {
writer.Write([]byte{r.Version, r.Error, 0x00 /* reserved */, r.AddrType})
switch r.AddrType {
case 0x01:
buffer.Append(r.IPv4[:])
writer.Write(r.IPv4[:])
case 0x03:
buffer.AppendBytes(byte(len(r.Domain)))
buffer.Append([]byte(r.Domain))
writer.Write([]byte{byte(len(r.Domain))})
writer.Write([]byte(r.Domain))
case 0x04:
buffer.Append(r.IPv6[:])
writer.Write(r.IPv6[:])
}
buffer.Append(r.Port.Bytes())
writer.Write(r.Port.Bytes())
}