From 3fd66ad795b64b366118c964f089b80c45efab80 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Thu, 25 Aug 2016 12:00:31 +0200 Subject: [PATCH] remove PingNecessary() --- transport/internet/kcp/connection.go | 4 +--- transport/internet/kcp/receiving.go | 16 ---------------- transport/internet/kcp/sending.go | 20 -------------------- 3 files changed, 1 insertion(+), 39 deletions(-) diff --git a/transport/internet/kcp/connection.go b/transport/internet/kcp/connection.go index 8a615af5d..360f407e7 100644 --- a/transport/internet/kcp/connection.go +++ b/transport/internet/kcp/connection.go @@ -512,7 +512,7 @@ func (this *Connection) flush() { this.receivingWorker.Flush(current) this.sendingWorker.Flush(current) - if this.sendingWorker.PingNecessary() || this.receivingWorker.PingNecessary() || current-atomic.LoadUint32(&this.lastPingTime) >= 3000 { + if current-atomic.LoadUint32(&this.lastPingTime) >= 3000 { seg := NewCmdOnlySegment() seg.Conv = this.conv seg.Command = CommandPing @@ -524,8 +524,6 @@ func (this *Connection) flush() { } this.output.Write(seg) this.lastPingTime = current - this.sendingWorker.MarkPingNecessary(false) - this.receivingWorker.MarkPingNecessary(false) seg.Release() } diff --git a/transport/internet/kcp/receiving.go b/transport/internet/kcp/receiving.go index f30384bad..198e432b7 100644 --- a/transport/internet/kcp/receiving.go +++ b/transport/internet/kcp/receiving.go @@ -117,7 +117,6 @@ type ReceivingWorker struct { leftOver *alloc.Buffer window *ReceivingWindow acklist *AckList - updated bool nextNumber uint32 windowSize uint32 } @@ -154,7 +153,6 @@ func (this *ReceivingWorker) ProcessSegment(seg *DataSegment) { if !this.window.Set(idx, seg) { seg.Release() } - this.updated = true } func (this *ReceivingWorker) Read(b []byte) int { @@ -180,7 +178,6 @@ func (this *ReceivingWorker) Read(b []byte) int { } this.window.Advance() this.nextNumber++ - this.updated = true nBytes := copy(b[total:], seg.Data.Value) total += nBytes @@ -212,20 +209,7 @@ func (this *ReceivingWorker) Write(seg Segment) { ackSeg.Option = SegmentOptionClose } this.conn.output.Write(ackSeg) - this.updated = false } func (this *ReceivingWorker) CloseRead() { } - -func (this *ReceivingWorker) PingNecessary() bool { - this.RLock() - defer this.RUnlock() - return this.updated -} - -func (this *ReceivingWorker) MarkPingNecessary(b bool) { - this.Lock() - defer this.Unlock() - this.updated = b -} diff --git a/transport/internet/kcp/sending.go b/transport/internet/kcp/sending.go index 85322c598..6d50cc03f 100644 --- a/transport/internet/kcp/sending.go +++ b/transport/internet/kcp/sending.go @@ -178,7 +178,6 @@ type SendingWorker struct { remoteNextNumber uint32 controlWindow uint32 fastResend uint32 - updated bool } func NewSendingWorker(kcp *Connection) *SendingWorker { @@ -206,15 +205,11 @@ func (this *SendingWorker) ProcessReceivingNextWithoutLock(nextNumber uint32) { // Private: Visible for testing. func (this *SendingWorker) FindFirstUnacknowledged() { - prevUna := this.firstUnacknowledged if !this.window.IsEmpty() { this.firstUnacknowledged = this.window.First().Number } else { this.firstUnacknowledged = this.nextNumber } - if this.firstUnacknowledged != prevUna { - this.updated = true - } } // Private: Visible for testing. @@ -293,21 +288,6 @@ func (this *SendingWorker) Write(seg Segment) { } this.conn.output.Write(dataSeg) - this.updated = false -} - -func (this *SendingWorker) PingNecessary() bool { - this.RLock() - defer this.RUnlock() - - return this.updated -} - -func (this *SendingWorker) MarkPingNecessary(b bool) { - this.Lock() - defer this.Unlock() - - this.updated = b } func (this *SendingWorker) OnPacketLoss(lossRate uint32) {