Parcourir la source

remove PingNecessary()

Darien Raymond il y a 9 ans
Parent
commit
3fd66ad795

+ 1 - 3
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()
 	}
 

+ 0 - 16
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
-}

+ 0 - 20
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) {