mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
pool: return specified size of buffer
This commit is contained in:
1 parent
5326c0a901
commit
a0542a028e
16 files changed
+158
-139
No files matched your search
@@ -1,13 +1,13 @@
|
||||
package trojan
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
|
||||
"github.com/nadoo/glider/common/conn"
|
||||
"github.com/nadoo/glider/common/pool"
|
||||
"github.com/nadoo/glider/common/socks"
|
||||
)
|
||||
|
||||
@@ -62,9 +62,11 @@ func (pc *PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||
|
||||
// WriteTo implements the necessary function of net.PacketConn.
|
||||
func (pc *PktConn) WriteTo(b []byte, addr net.Addr) (int, error) {
|
||||
var buf bytes.Buffer
|
||||
buf := pool.GetWriteBuffer()
|
||||
defer pool.PutWriteBuffer(buf)
|
||||
|
||||
buf.Write(pc.tgtAddr)
|
||||
binary.Write(&buf, binary.BigEndian, uint16(len(b)))
|
||||
binary.Write(buf, binary.BigEndian, uint16(len(b)))
|
||||
buf.WriteString("\r\n")
|
||||
buf.Write(b)
|
||||
return pc.Write(buf.Bytes())
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package trojan
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"crypto/tls"
|
||||
"encoding/hex"
|
||||
@@ -13,6 +12,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/nadoo/glider/common/log"
|
||||
"github.com/nadoo/glider/common/pool"
|
||||
"github.com/nadoo/glider/common/socks"
|
||||
"github.com/nadoo/glider/proxy"
|
||||
)
|
||||
@@ -105,7 +105,9 @@ func (s *Trojan) dial(network, addr string) (net.Conn, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
buf := pool.GetWriteBuffer()
|
||||
defer pool.PutWriteBuffer(buf)
|
||||
|
||||
buf.Write(s.pass[:])
|
||||
buf.WriteString("\r\n")
|
||||
|
||||
|
||||
Reference in new issue
Block a user