Refactor(pool): move to internal (#398)

This commit is contained in:
Jason Lyu
2024-09-01 04:23:25 +08:00
committed by GitHub
parent 978803cdf8
commit fc4c5c4c55
13 changed files with 26 additions and 27 deletions

View File

@@ -1,17 +0,0 @@
package pool
import (
"bytes"
"sync"
)
var bufferPool = sync.Pool{New: func() any { return &bytes.Buffer{} }}
func GetBuffer() *bytes.Buffer {
return bufferPool.Get().(*bytes.Buffer)
}
func PutBuffer(buf *bytes.Buffer) {
buf.Reset()
bufferPool.Put(buf)
}

View File

@@ -51,8 +51,7 @@ func (alloc *Allocator) Put(buf []byte) error {
return errors.New("allocator Put() incorrect buffer size") return errors.New("allocator Put() incorrect buffer size")
} }
//lint:ignore SA6002 ignore temporarily //nolint:staticcheck
//nolint
alloc.buffers[b].Put(buf) alloc.buffers[b].Put(buf)
return nil return nil
} }

17
internal/pool/buffer.go Normal file
View File

@@ -0,0 +1,17 @@
package pool
import (
"bytes"
"sync"
)
var _bufferPool = sync.Pool{New: func() any { return &bytes.Buffer{} }}
func GetBuffer() *bytes.Buffer {
return _bufferPool.Get().(*bytes.Buffer)
}
func PutBuffer(buf *bytes.Buffer) {
buf.Reset()
_bufferPool.Put(buf)
}

View File

@@ -13,8 +13,8 @@ import (
"github.com/go-gost/relay" "github.com/go-gost/relay"
"github.com/xjasonlyu/tun2socks/v2/common/pool"
"github.com/xjasonlyu/tun2socks/v2/dialer" "github.com/xjasonlyu/tun2socks/v2/dialer"
"github.com/xjasonlyu/tun2socks/v2/internal/pool"
M "github.com/xjasonlyu/tun2socks/v2/metadata" M "github.com/xjasonlyu/tun2socks/v2/metadata"
"github.com/xjasonlyu/tun2socks/v2/proxy/proto" "github.com/xjasonlyu/tun2socks/v2/proxy/proto"
) )

View File

@@ -6,7 +6,7 @@ import (
"io" "io"
"net" "net"
"github.com/xjasonlyu/tun2socks/v2/common/pool" "github.com/xjasonlyu/tun2socks/v2/internal/pool"
) )
// ErrShortPacket means that the packet is too short for a valid encrypted packet. // ErrShortPacket means that the packet is too short for a valid encrypted packet.

View File

@@ -7,7 +7,7 @@ import (
"io" "io"
"net" "net"
"github.com/xjasonlyu/tun2socks/v2/common/pool" "github.com/xjasonlyu/tun2socks/v2/internal/pool"
) )
const ( const (

View File

@@ -6,7 +6,7 @@ import (
"io" "io"
"net" "net"
"github.com/xjasonlyu/tun2socks/v2/common/pool" "github.com/xjasonlyu/tun2socks/v2/internal/pool"
) )
// ErrShortPacket means the packet is too short to be a valid encrypted packet. // ErrShortPacket means the packet is too short to be a valid encrypted packet.

View File

@@ -10,7 +10,7 @@ import (
"net" "net"
"net/http" "net/http"
"github.com/xjasonlyu/tun2socks/v2/common/pool" "github.com/xjasonlyu/tun2socks/v2/internal/pool"
) )
// HTTPObfs is shadowsocks http simple-obfs implementation // HTTPObfs is shadowsocks http simple-obfs implementation

View File

@@ -8,7 +8,7 @@ import (
"net" "net"
"time" "time"
"github.com/xjasonlyu/tun2socks/v2/common/pool" "github.com/xjasonlyu/tun2socks/v2/internal/pool"
) )
const ( const (

View File

@@ -7,8 +7,8 @@ import (
"sync" "sync"
"time" "time"
"github.com/xjasonlyu/tun2socks/v2/common/pool"
"github.com/xjasonlyu/tun2socks/v2/core/adapter" "github.com/xjasonlyu/tun2socks/v2/core/adapter"
"github.com/xjasonlyu/tun2socks/v2/internal/pool"
"github.com/xjasonlyu/tun2socks/v2/log" "github.com/xjasonlyu/tun2socks/v2/log"
M "github.com/xjasonlyu/tun2socks/v2/metadata" M "github.com/xjasonlyu/tun2socks/v2/metadata"
"github.com/xjasonlyu/tun2socks/v2/tunnel/statistic" "github.com/xjasonlyu/tun2socks/v2/tunnel/statistic"

View File

@@ -6,8 +6,8 @@ import (
"sync" "sync"
"time" "time"
"github.com/xjasonlyu/tun2socks/v2/common/pool"
"github.com/xjasonlyu/tun2socks/v2/core/adapter" "github.com/xjasonlyu/tun2socks/v2/core/adapter"
"github.com/xjasonlyu/tun2socks/v2/internal/pool"
"github.com/xjasonlyu/tun2socks/v2/log" "github.com/xjasonlyu/tun2socks/v2/log"
M "github.com/xjasonlyu/tun2socks/v2/metadata" M "github.com/xjasonlyu/tun2socks/v2/metadata"
"github.com/xjasonlyu/tun2socks/v2/tunnel/statistic" "github.com/xjasonlyu/tun2socks/v2/tunnel/statistic"