mirror of https://github.com/v2ray/v2ray-core
write buffer size
parent
4beeba933c
commit
ab710f2714
|
@ -6,6 +6,7 @@ type Config struct {
|
||||||
UplinkCapacity int
|
UplinkCapacity int
|
||||||
DownlinkCapacity int
|
DownlinkCapacity int
|
||||||
Congestion bool
|
Congestion bool
|
||||||
|
WriteBuffer int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Config) Apply() {
|
func (this *Config) Apply() {
|
||||||
|
@ -27,6 +28,7 @@ func DefaultConfig() Config {
|
||||||
UplinkCapacity: 5,
|
UplinkCapacity: 5,
|
||||||
DownlinkCapacity: 20,
|
DownlinkCapacity: 20,
|
||||||
Congestion: false,
|
Congestion: false,
|
||||||
|
WriteBuffer: 8 * 1024 * 1024,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ type Connection struct {
|
||||||
writer io.WriteCloser
|
writer io.WriteCloser
|
||||||
since int64
|
since int64
|
||||||
terminateOnce signal.Once
|
terminateOnce signal.Once
|
||||||
|
writeBufferSize int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConnection create a new KCP connection between local and remote.
|
// NewConnection create a new KCP connection between local and remote.
|
||||||
|
@ -82,6 +83,7 @@ func NewConnection(conv uint32, writerCloser io.WriteCloser, local *net.UDPAddr,
|
||||||
conn.kcp.WndSize(effectiveConfig.GetSendingWindowSize(), effectiveConfig.GetReceivingWindowSize())
|
conn.kcp.WndSize(effectiveConfig.GetSendingWindowSize(), effectiveConfig.GetReceivingWindowSize())
|
||||||
conn.kcp.NoDelay(1, effectiveConfig.Tti, 2, effectiveConfig.Congestion)
|
conn.kcp.NoDelay(1, effectiveConfig.Tti, 2, effectiveConfig.Congestion)
|
||||||
conn.kcp.current = conn.Elapsed()
|
conn.kcp.current = conn.Elapsed()
|
||||||
|
conn.writeBufferSize = effectiveConfig.WriteBuffer / effectiveConfig.Mtu
|
||||||
|
|
||||||
go conn.updateTask()
|
go conn.updateTask()
|
||||||
|
|
||||||
|
@ -144,7 +146,7 @@ func (this *Connection) Write(b []byte) (int, error) {
|
||||||
this.RUnlock()
|
this.RUnlock()
|
||||||
|
|
||||||
this.kcpAccess.Lock()
|
this.kcpAccess.Lock()
|
||||||
if this.kcp.WaitSnd() < int(this.kcp.snd_wnd) {
|
if this.kcp.WaitSnd() < this.writeBufferSize {
|
||||||
nBytes := len(b)
|
nBytes := len(b)
|
||||||
this.kcp.Send(b)
|
this.kcp.Send(b)
|
||||||
this.kcp.current = this.Elapsed()
|
this.kcp.current = this.Elapsed()
|
||||||
|
|
Loading…
Reference in New Issue