mirror of https://github.com/v2ray/v2ray-core
Use Buffer as a writer
parent
32ab3dcd61
commit
a77f62428a
|
@ -50,6 +50,11 @@ func (b *Buffer) IsFull() bool {
|
|||
return len(b.Value) == cap(b.Value)
|
||||
}
|
||||
|
||||
func (b *Buffer) Write(data []byte) (int, error) {
|
||||
b.Append(data)
|
||||
return len(data), nil
|
||||
}
|
||||
|
||||
type bufferPool struct {
|
||||
chain chan []byte
|
||||
bufferSize int
|
||||
|
@ -98,7 +103,10 @@ func (p *bufferPool) cleanup(tick <-chan time.Time) {
|
|||
continue
|
||||
}
|
||||
for delta := p.buffers2Keep - pSize; delta > 0; delta-- {
|
||||
p.chain <- make([]byte, p.bufferSize)
|
||||
select {
|
||||
case p.chain <- make([]byte, p.bufferSize):
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,8 @@ func (handler *VMessInboundHandler) handlePacket(conn *net.UDPConn, request *pro
|
|||
responseKey := md5.Sum(request.RequestKey)
|
||||
responseIV := md5.Sum(request.RequestIV)
|
||||
|
||||
buffer := bytes.NewBuffer(make([]byte, 0, bufferSize))
|
||||
buffer := alloc.NewBuffer().Clear()
|
||||
defer buffer.Release()
|
||||
|
||||
responseWriter, err := v2io.NewAesEncryptWriter(responseKey[:], responseIV[:], buffer)
|
||||
if err != nil {
|
||||
|
@ -95,7 +96,7 @@ func (handler *VMessInboundHandler) handlePacket(conn *net.UDPConn, request *pro
|
|||
}
|
||||
|
||||
if hasData {
|
||||
conn.WriteToUDP(buffer.Bytes(), clientAddr)
|
||||
log.Info("VMessIn sending %d bytes to %s", len(buffer.Bytes()), clientAddr.String())
|
||||
conn.WriteToUDP(buffer.Value, clientAddr)
|
||||
log.Info("VMessIn sending %d bytes to %s", buffer.Len(), clientAddr.String())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue