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