mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 10:08:15 -05:00
improve fetch performance
This commit is contained in:
parent
f7d54d57c4
commit
4c63e9e168
@ -40,6 +40,12 @@ func (b *Buffer) Clear() *Buffer {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Buffer) Reset() *Buffer {
|
||||||
|
b.offset = defaultOffset
|
||||||
|
b.Value = b.head
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
// AppendBytes appends one or more bytes to the end of the buffer.
|
// AppendBytes appends one or more bytes to the end of the buffer.
|
||||||
func (b *Buffer) AppendBytes(bytes ...byte) *Buffer {
|
func (b *Buffer) AppendBytes(bytes ...byte) *Buffer {
|
||||||
b.Value = append(b.Value, bytes...)
|
b.Value = append(b.Value, bytes...)
|
||||||
|
@ -333,11 +333,12 @@ func (this *Connection) updateTask() {
|
|||||||
|
|
||||||
func (this *Connection) FetchInputFrom(conn net.Conn) {
|
func (this *Connection) FetchInputFrom(conn net.Conn) {
|
||||||
go func() {
|
go func() {
|
||||||
|
payload := alloc.NewBuffer()
|
||||||
|
defer payload.Release()
|
||||||
for {
|
for {
|
||||||
payload := alloc.NewBuffer()
|
payload.Reset()
|
||||||
nBytes, err := conn.Read(payload.Value)
|
nBytes, err := conn.Read(payload.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
payload.Release()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
payload.Slice(0, nBytes)
|
payload.Slice(0, nBytes)
|
||||||
@ -346,7 +347,6 @@ func (this *Connection) FetchInputFrom(conn net.Conn) {
|
|||||||
} else {
|
} else {
|
||||||
log.Info("KCP|Connection: Invalid response from ", conn.RemoteAddr())
|
log.Info("KCP|Connection: Invalid response from ", conn.RemoteAddr())
|
||||||
}
|
}
|
||||||
payload.Release()
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user