稍微优化一下

This commit is contained in:
dmy@lab 2015-11-19 21:50:06 +08:00
parent 54cd925ab2
commit 6f8bda54e4
2 changed files with 5 additions and 3 deletions

View File

@ -49,6 +49,7 @@ func (this *Tunnel) run() { //单向的从src发送到dest
cipherDirection := this.cipherDirection
id := this.id
defer func() {
log.Info("tunnel id %s ends", id)
if r := recover(); r != nil {
if src != nil {
src.Close()
@ -56,7 +57,6 @@ func (this *Tunnel) run() { //单向的从src发送到dest
if dest != nil {
dest.Close()
}
}
}()
cache := make([]byte, 1024*4) //4kB

View File

@ -49,14 +49,14 @@ func NewCarrier(conn net.Conn, cipher Cipher, cache []byte, id string) *Carrier
t.Cipher = cipher
t.Cache = cache
t.AttachedTunnelID = id
t.receiveBuff = make([]byte, 0, len(cache)*8)
t.receiveBuff = make([]byte, 0, len(cache))
return t
}
func (this *Carrier) GetReceiveBuff() []byte {
log.Debug("id %d receivebuff Get, len %d", this.AttachedTunnelID, len(this.receiveBuff))
buff := this.receiveBuff
_b := make([]byte, len(buff), cap(buff))
_b := make([]byte, len(buff), cap(buff)) //必须这样写,没错。
copy(_b, buff)
return _b
}
@ -82,6 +82,8 @@ func NewCipher(cipherName string) (cipher Cipher) {
func WrapPackage(data []byte) []byte { //把要加密传输的数据打包成一定的格式避免发送了100自己只收到90字节的问题。
sizeOfData := len(data)
binSize := utils.Int2binary(sizeOfData, 10)
// header := make([]byte, 18)
// header = append(append(append(header, StartMark...), binSize...), EndMark...)
header := append(append(StartMark, binSize...), EndMark...)
// log.Error("size of header %d %x", len(header), header)
//加密