Quellcode durchsuchen

remove unused code

Darien Raymond vor 9 Jahren
Ursprung
Commit
aabb9137e1
2 geänderte Dateien mit 0 neuen und 141 gelöschten Zeilen
  1. 0 102
      transport/internet/kcp/buffer.go
  2. 0 39
      transport/internet/kcp/buffer_test.go

+ 0 - 102
transport/internet/kcp/buffer.go

@@ -1,102 +0,0 @@
-package kcp
-
-import (
-	"sync"
-
-	"v2ray.com/core/common/alloc"
-)
-
-const (
-	NumDistro  = 5
-	DistroSize = 1600
-)
-
-type Buffer struct {
-	sync.Mutex
-	buffer *alloc.Buffer
-
-	next     int
-	released int
-	hold     bool
-	distro   [NumDistro]*alloc.Buffer
-}
-
-func NewBuffer() *Buffer {
-	b := &Buffer{
-		next:     0,
-		released: 0,
-		hold:     true,
-		buffer:   alloc.NewBuffer(),
-	}
-	for idx := range b.distro {
-		content := b.buffer.Value[idx*DistroSize : (idx+1)*DistroSize]
-		b.distro[idx] = alloc.CreateBuffer(content, b)
-	}
-	return b
-}
-
-func (this *Buffer) IsEmpty() bool {
-	this.Lock()
-	defer this.Unlock()
-
-	return this.next == NumDistro
-}
-
-func (this *Buffer) Allocate() *alloc.Buffer {
-	this.Lock()
-	defer this.Unlock()
-	if this.next == NumDistro {
-		return nil
-	}
-	b := this.distro[this.next]
-	this.next++
-	return b
-}
-
-func (this *Buffer) Free(b *alloc.Buffer) {
-	this.Lock()
-	defer this.Unlock()
-
-	this.released++
-	if !this.hold && this.released == this.next {
-		this.ReleaseBuffer()
-	}
-}
-
-func (this *Buffer) Release() {
-	this.Lock()
-	defer this.Unlock()
-
-	if this.next == this.released {
-		this.ReleaseBuffer()
-	}
-	this.hold = false
-}
-
-func (this *Buffer) ReleaseBuffer() {
-	this.buffer.Release()
-	this.buffer = nil
-	for idx := range this.distro {
-		this.distro[idx] = nil
-	}
-}
-
-var (
-	globalBuffer       *Buffer
-	globalBufferAccess sync.Mutex
-)
-
-func AllocateBuffer() *alloc.Buffer {
-	globalBufferAccess.Lock()
-	defer globalBufferAccess.Unlock()
-
-	if globalBuffer == nil {
-		globalBuffer = NewBuffer()
-	}
-	b := globalBuffer.Allocate()
-	if globalBuffer.IsEmpty() {
-		globalBuffer.Release()
-		globalBuffer = nil
-	}
-	return b
-}

+ 0 - 39
transport/internet/kcp/buffer_test.go

@@ -1,39 +0,0 @@
-package kcp_test
-
-import (
-	"testing"
-
-	"v2ray.com/core/testing/assert"
-	. "v2ray.com/core/transport/internet/kcp"
-)
-
-func TestBuffer(t *testing.T) {
-	assert := assert.On(t)
-
-	b := NewBuffer()
-
-	for i := 0; i < NumDistro; i++ {
-		x := b.Allocate()
-		assert.Pointer(x).IsNotNil()
-		x.Release()
-	}
-	assert.Pointer(b.Allocate()).IsNil()
-	b.Release()
-}
-
-func TestSingleRelease(t *testing.T) {
-	assert := assert.On(t)
-
-	b := NewBuffer()
-	x := b.Allocate()
-	x.Release()
-
-	y := b.Allocate()
-	assert.Pointer(y.Value).IsNotNil()
-
-	b.Release()
-	y.Release()
-
-	z := b.Allocate()
-	assert.Pointer(z).IsNil()
-}