1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-19 10:56:06 -05:00

refine locker in sending worker

This commit is contained in:
v2ray 2016-07-06 00:02:22 +02:00
parent 78ef65e17b
commit 5448ec1fe4
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -307,6 +307,8 @@ func (this *SendingWorker) ProcessSegment(current uint32, seg *AckSegment) {
func (this *SendingWorker) Push(b []byte) int { func (this *SendingWorker) Push(b []byte) int {
nBytes := 0 nBytes := 0
this.Lock()
defer this.Unlock()
for len(b) > 0 && !this.queue.IsFull() { for len(b) > 0 && !this.queue.IsFull() {
var size int var size int
if len(b) > int(this.conn.mss) { if len(b) > int(this.conn.mss) {
@ -316,9 +318,7 @@ func (this *SendingWorker) Push(b []byte) int {
} }
seg := NewDataSegment() seg := NewDataSegment()
seg.Data = alloc.NewSmallBuffer().Clear().Append(b[:size]) seg.Data = alloc.NewSmallBuffer().Clear().Append(b[:size])
this.Lock()
this.queue.Push(seg) this.queue.Push(seg)
this.Unlock()
b = b[size:] b = b[size:]
nBytes += size nBytes += size
} }
@ -331,7 +331,7 @@ func (this *SendingWorker) Write(seg Segment) {
dataSeg.Conv = this.conn.conv dataSeg.Conv = this.conn.conv
dataSeg.SendingNext = this.firstUnacknowledged dataSeg.SendingNext = this.firstUnacknowledged
dataSeg.Opt = 0 dataSeg.Opt = 0
if this.conn.state == StateReadyToClose { if this.conn.State() == StateReadyToClose {
dataSeg.Opt = SegmentOptionClose dataSeg.Opt = SegmentOptionClose
} }