From 2ae8e5d033bd14816f9df6158e5f8c7d2a2dbdf4 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 24 Aug 2016 23:54:39 +0200 Subject: [PATCH] rename buffer size --- transport/internet/kcp/config.go | 24 ++++++++++++++++-------- transport/internet/kcp/receiving.go | 2 +- transport/internet/kcp/sending.go | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/transport/internet/kcp/config.go b/transport/internet/kcp/config.go index dbf31d4b..7f82c932 100644 --- a/transport/internet/kcp/config.go +++ b/transport/internet/kcp/config.go @@ -40,12 +40,12 @@ func (this *Config) GetSendingInFlightSize() uint32 { return size } -func (this *Config) GetSendingWindowSize() uint32 { - return this.GetSendingInFlightSize() * 4 -} - -func (this *Config) GetSendingQueueSize() uint32 { - return this.WriteBuffer / this.Mtu +func (this *Config) GetSendingBufferSize() uint32 { + size := this.WriteBuffer / this.Mtu + if size < this.GetSendingInFlightSize() { + size = this.GetSendingInFlightSize() + } + return size } func (this *Config) GetReceivingWindowSize() uint32 { @@ -56,8 +56,16 @@ func (this *Config) GetReceivingWindowSize() uint32 { return size } -func (this *Config) GetReceivingQueueSize() uint32 { - return this.ReadBuffer / this.Mtu +func (this *Config) GetReceivingBufferSize() uint32 { + bufferSize := this.ReadBuffer / this.Mtu + windowSize := this.DownlinkCapacity * 1024 * 1024 / this.Mtu / (1000 / this.Tti) / 2 + if windowSize < 8 { + windowSize = 8 + } + if bufferSize < windowSize { + bufferSize = windowSize + } + return bufferSize } func DefaultConfig() Config { diff --git a/transport/internet/kcp/receiving.go b/transport/internet/kcp/receiving.go index c3b59b70..bb579292 100644 --- a/transport/internet/kcp/receiving.go +++ b/transport/internet/kcp/receiving.go @@ -123,7 +123,7 @@ type ReceivingWorker struct { } func NewReceivingWorker(kcp *Connection) *ReceivingWorker { - windowSize := effectiveConfig.GetReceivingQueueSize() + windowSize := effectiveConfig.GetReceivingBufferSize() worker := &ReceivingWorker{ conn: kcp, window: NewReceivingWindow(windowSize), diff --git a/transport/internet/kcp/sending.go b/transport/internet/kcp/sending.go index e4da9b20..a5a596f8 100644 --- a/transport/internet/kcp/sending.go +++ b/transport/internet/kcp/sending.go @@ -195,7 +195,7 @@ func NewSendingWorker(kcp *Connection) *SendingWorker { remoteNextNumber: 32, controlWindow: effectiveConfig.GetSendingInFlightSize(), } - worker.window = NewSendingWindow(effectiveConfig.GetSendingQueueSize(), worker, worker.OnPacketLoss) + worker.window = NewSendingWindow(effectiveConfig.GetSendingBufferSize(), worker, worker.OnPacketLoss) return worker }