From 5448ec1fe48492f14fe2d5a358d8c0ccfe3dfaaf Mon Sep 17 00:00:00 2001 From: v2ray Date: Wed, 6 Jul 2016 00:02:22 +0200 Subject: [PATCH] refine locker in sending worker --- transport/internet/kcp/sending.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/transport/internet/kcp/sending.go b/transport/internet/kcp/sending.go index d6870970b..31415b601 100644 --- a/transport/internet/kcp/sending.go +++ b/transport/internet/kcp/sending.go @@ -307,6 +307,8 @@ func (this *SendingWorker) ProcessSegment(current uint32, seg *AckSegment) { func (this *SendingWorker) Push(b []byte) int { nBytes := 0 + this.Lock() + defer this.Unlock() for len(b) > 0 && !this.queue.IsFull() { var size int if len(b) > int(this.conn.mss) { @@ -316,9 +318,7 @@ func (this *SendingWorker) Push(b []byte) int { } seg := NewDataSegment() seg.Data = alloc.NewSmallBuffer().Clear().Append(b[:size]) - this.Lock() this.queue.Push(seg) - this.Unlock() b = b[size:] nBytes += size } @@ -331,7 +331,7 @@ func (this *SendingWorker) Write(seg Segment) { dataSeg.Conv = this.conn.conv dataSeg.SendingNext = this.firstUnacknowledged dataSeg.Opt = 0 - if this.conn.state == StateReadyToClose { + if this.conn.State() == StateReadyToClose { dataSeg.Opt = SegmentOptionClose }