mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
remove unused APIs.
This commit is contained in:
parent
41258f19fc
commit
605fc49e9e
@ -5,10 +5,6 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultOffset = 16
|
||||
)
|
||||
|
||||
// BytesWriter is a writer that writes contents into the given buffer.
|
||||
type BytesWriter func([]byte) int
|
||||
|
||||
@ -28,8 +24,8 @@ func CreateBuffer(container []byte, parent Pool) *Buffer {
|
||||
b := new(Buffer)
|
||||
b.v = container
|
||||
b.pool = parent
|
||||
b.start = defaultOffset
|
||||
b.end = defaultOffset
|
||||
b.start = 0
|
||||
b.end = 0
|
||||
return b
|
||||
}
|
||||
|
||||
@ -48,14 +44,8 @@ func (b *Buffer) Release() {
|
||||
// Clear clears the content of the buffer, results an empty buffer with
|
||||
// Len() = 0.
|
||||
func (b *Buffer) Clear() {
|
||||
b.start = defaultOffset
|
||||
b.end = defaultOffset
|
||||
}
|
||||
|
||||
// Reset resets this Buffer into its original state.
|
||||
func (b *Buffer) Reset() {
|
||||
b.start = defaultOffset
|
||||
b.end = len(b.v)
|
||||
b.start = 0
|
||||
b.end = 0
|
||||
}
|
||||
|
||||
// AppendBytes appends one or more bytes to the end of the buffer.
|
||||
@ -75,23 +65,6 @@ func (b *Buffer) AppendFunc(writer BytesWriter) {
|
||||
b.end += nBytes
|
||||
}
|
||||
|
||||
// Prepend prepends bytes in front of the buffer. Caller must ensure total bytes prepended is
|
||||
// no more than 16 bytes.
|
||||
func (b *Buffer) Prepend(data []byte) {
|
||||
b.SliceBack(len(data))
|
||||
copy(b.v[b.start:], data)
|
||||
}
|
||||
|
||||
// PrependBytes prepends all data in front of the buffer.
|
||||
func (b *Buffer) PrependBytes(data ...byte) {
|
||||
b.Prepend(data)
|
||||
}
|
||||
|
||||
func (b *Buffer) PrependFunc(offset int, writer BytesWriter) {
|
||||
b.SliceBack(offset)
|
||||
writer(b.v[b.start:])
|
||||
}
|
||||
|
||||
// Byte returns the bytes at index.
|
||||
func (b *Buffer) Byte(index int) byte {
|
||||
return b.v[b.start+index]
|
||||
@ -108,7 +81,7 @@ func (b *Buffer) Bytes() []byte {
|
||||
}
|
||||
|
||||
func (b *Buffer) SetBytesFunc(writer BytesWriter) {
|
||||
b.start = defaultOffset
|
||||
b.start = 0
|
||||
b.end = b.start + writer(b.v[b.start:])
|
||||
}
|
||||
|
||||
@ -160,15 +133,6 @@ func (b *Buffer) SliceFrom(from int) {
|
||||
b.start += from
|
||||
}
|
||||
|
||||
// SliceBack extends the Buffer to its front by offset bytes.
|
||||
// Caller must ensure cumulated offset is no more than 16.
|
||||
func (b *Buffer) SliceBack(offset int) {
|
||||
b.start -= offset
|
||||
if b.start < 0 {
|
||||
panic("Negative buffer offset.")
|
||||
}
|
||||
}
|
||||
|
||||
// Len returns the length of the buffer content.
|
||||
func (b *Buffer) Len() int {
|
||||
if b == nil {
|
||||
|
@ -84,11 +84,8 @@ func (p *BufferPool) Free(buffer *Buffer) {
|
||||
}
|
||||
|
||||
const (
|
||||
mediumBufferByteSize = 8 * 1024
|
||||
BufferSize = mediumBufferByteSize - defaultOffset
|
||||
|
||||
smallBufferByteSize = 2 * 1024
|
||||
SmallBufferSize = smallBufferByteSize - defaultOffset
|
||||
BufferSize = 8 * 1024
|
||||
SmallBufferSize = 2 * 1024
|
||||
|
||||
PoolSizeEnvKey = "v2ray.buffer.size"
|
||||
)
|
||||
@ -109,8 +106,8 @@ func init() {
|
||||
}
|
||||
if size > 0 {
|
||||
totalByteSize := size * 1024 * 1024
|
||||
mediumPool = NewBufferPool(mediumBufferByteSize, totalByteSize/mediumBufferByteSize)
|
||||
mediumPool = NewBufferPool(BufferSize, totalByteSize/BufferSize)
|
||||
} else {
|
||||
mediumPool = NewSyncPool(mediumBufferByteSize)
|
||||
mediumPool = NewSyncPool(BufferSize)
|
||||
}
|
||||
}
|
||||
|
@ -31,22 +31,6 @@ func TestBufferIsEmpty(t *testing.T) {
|
||||
assert.Bool(buffer.IsEmpty()).IsTrue()
|
||||
}
|
||||
|
||||
func TestBufferPrepend(t *testing.T) {
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := NewBuffer()
|
||||
defer buffer.Release()
|
||||
|
||||
buffer.Append([]byte{'a', 'b', 'c'})
|
||||
buffer.Prepend([]byte{'x', 'y', 'z'})
|
||||
|
||||
assert.Int(buffer.Len()).Equals(6)
|
||||
assert.String(buffer.String()).Equals("xyzabc")
|
||||
|
||||
buffer.Prepend([]byte{'u', 'v', 'w'})
|
||||
assert.String(buffer.String()).Equals("uvwxyzabc")
|
||||
}
|
||||
|
||||
func TestBufferString(t *testing.T) {
|
||||
assert := assert.On(t)
|
||||
|
||||
@ -60,7 +44,7 @@ func TestBufferString(t *testing.T) {
|
||||
func TestBufferWrite(t *testing.T) {
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := NewLocalBuffer(24) // 16 + 8
|
||||
buffer := NewLocalBuffer(8)
|
||||
nBytes, err := buffer.Write([]byte("abcd"))
|
||||
assert.Error(err).IsNil()
|
||||
assert.Int(nBytes).Equals(4)
|
||||
|
@ -225,7 +225,7 @@ func (v *VMessInboundHandler) HandleConnection(connection internet.Connection) {
|
||||
}
|
||||
output.Release()
|
||||
if request.Option.Has(protocol.RequestOptionChunkStream) {
|
||||
if err := bodyWriter.Write(alloc.NewLocalBuffer(32)); err != nil {
|
||||
if err := bodyWriter.Write(alloc.NewLocalBuffer(8)); err != nil {
|
||||
connection.SetReusable(false)
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ func (v *VMessOutboundHandler) handleRequest(session *encoding.ClientSession, co
|
||||
}
|
||||
|
||||
if request.Option.Has(protocol.RequestOptionChunkStream) {
|
||||
err := bodyWriter.Write(alloc.NewLocalBuffer(32))
|
||||
err := bodyWriter.Write(alloc.NewLocalBuffer(8))
|
||||
if err != nil {
|
||||
conn.SetReusable(false)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user