From 16d1b42f59ec3bc93fd041dc8b2dcfa218c996f9 Mon Sep 17 00:00:00 2001 From: v2ray Date: Tue, 5 Jul 2016 14:08:08 +0200 Subject: [PATCH] refine seg allocation --- transport/internet/kcp/kcp.go | 1 + transport/internet/kcp/output.go | 2 +- transport/internet/kcp/receiving.go | 8 +++++--- transport/internet/kcp/segment.go | 3 --- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/transport/internet/kcp/kcp.go b/transport/internet/kcp/kcp.go index 4c0963fb8..bd6544114 100644 --- a/transport/internet/kcp/kcp.go +++ b/transport/internet/kcp/kcp.go @@ -215,6 +215,7 @@ func (kcp *KCP) flush() { kcp.output.Write(seg) kcp.lastPingTime = kcp.current kcp.sendingUpdated = false + seg.Release() } // flash remain segments diff --git a/transport/internet/kcp/output.go b/transport/internet/kcp/output.go index 4040969fa..21e0d5dc5 100644 --- a/transport/internet/kcp/output.go +++ b/transport/internet/kcp/output.go @@ -39,7 +39,7 @@ func (this *BufferedSegmentWriter) Write(seg Segment) { this.buffer = alloc.NewSmallBuffer().Clear() } - this.buffer.Append(seg.Bytes(nil)) + this.buffer.Value = seg.Bytes(this.buffer.Value) } func (this *BufferedSegmentWriter) FlushWithoutLock() { diff --git a/transport/internet/kcp/receiving.go b/transport/internet/kcp/receiving.go index 56bfee6c9..8501d12a9 100644 --- a/transport/internet/kcp/receiving.go +++ b/transport/internet/kcp/receiving.go @@ -112,6 +112,9 @@ L: return totalBytes, errTimeout } timeToSleep += 500 * time.Millisecond + if timeToSleep > 5*time.Second { + timeToSleep = 5 * time.Second + } } } @@ -119,9 +122,6 @@ L: } func (this *ReceivingQueue) Put(payload *alloc.Buffer) bool { - this.Lock() - defer this.Unlock() - if this.closed { payload.Release() return false @@ -211,6 +211,7 @@ func (this *AckList) Flush(current uint32, rto uint32) { this.Unlock() if seg.Count > 0 { this.writer.Write(seg) + seg.Release() } } @@ -268,6 +269,7 @@ func (this *ReceivingWorker) ProcessSegment(seg *DataSegment) { } seg.Data = nil + seg.Release() this.window.Advance() this.nextNumber++ this.updated = true diff --git a/transport/internet/kcp/segment.go b/transport/internet/kcp/segment.go index 6676a535e..9c24e1d10 100644 --- a/transport/internet/kcp/segment.go +++ b/transport/internet/kcp/segment.go @@ -230,9 +230,6 @@ func ReadSegment(buf []byte) (Segment, []byte) { seg.Count = buf[0] buf = buf[1:] - seg.NumberList = make([]uint32, 0, seg.Count) - seg.TimestampList = make([]uint32, 0, seg.Count) - if len(buf) < int(seg.Count)*8 { return nil, nil }