mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
Cleanup
This commit is contained in:
parent
089de290ad
commit
7e499ee0b6
@ -7,17 +7,6 @@ import (
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
)
|
||||
|
||||
// ReadFrom reads from a reader and put all content to a buffer.
|
||||
// If buffer is nil, ReadFrom creates a new normal buffer.
|
||||
func ReadFrom(reader io.Reader, buffer *alloc.Buffer) (*alloc.Buffer, error) {
|
||||
if buffer == nil {
|
||||
buffer = alloc.NewBuffer()
|
||||
}
|
||||
nBytes, err := reader.Read(buffer.Value)
|
||||
buffer.Slice(0, nBytes)
|
||||
return buffer, err
|
||||
}
|
||||
|
||||
// Reader extends io.Reader with alloc.Buffer.
|
||||
type Reader interface {
|
||||
common.Releasable
|
||||
@ -42,7 +31,12 @@ func NewAdaptiveReader(reader io.Reader) *AdaptiveReader {
|
||||
|
||||
// Read implements Reader.Read().
|
||||
func (this *AdaptiveReader) Read() (*alloc.Buffer, error) {
|
||||
buffer, err := ReadFrom(this.reader, this.allocate())
|
||||
buffer := this.allocate().Clear()
|
||||
_, err := buffer.FillFrom(this.reader)
|
||||
if err != nil {
|
||||
buffer.Release()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if buffer.Len() >= alloc.BufferSize {
|
||||
this.allocate = alloc.NewLargeBuffer
|
||||
@ -50,10 +44,6 @@ func (this *AdaptiveReader) Read() (*alloc.Buffer, error) {
|
||||
this.allocate = alloc.NewBuffer
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
buffer.Release()
|
||||
return nil, err
|
||||
}
|
||||
return buffer, nil
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
)
|
||||
|
||||
@ -44,13 +43,13 @@ func (server *Server) acceptConnections(listener *net.TCPListener) {
|
||||
}
|
||||
|
||||
func (server *Server) handleConnection(conn net.Conn) {
|
||||
request := make([]byte, 4096)
|
||||
for true {
|
||||
request, err := v2io.ReadFrom(conn, nil)
|
||||
nBytes, err := conn.Read(request)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
response := server.MsgProcessor(request.Value)
|
||||
request.Release()
|
||||
response := server.MsgProcessor(request[:nBytes])
|
||||
conn.Write(response)
|
||||
}
|
||||
conn.Close()
|
||||
|
Loading…
Reference in New Issue
Block a user