1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-01 16:26:02 -04:00

compact kcp stream

This commit is contained in:
v2ray 2016-08-07 01:01:44 +02:00
parent 6678da2fe2
commit 0caf2e6d30
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -212,6 +212,13 @@ func (this *SendingQueue) Pop() *alloc.Buffer {
return seg return seg
} }
func (this *SendingQueue) Last() *alloc.Buffer {
if this.IsEmpty() {
return nil
}
return this.list[(this.start+this.len-1+this.cap)%this.cap]
}
func (this *SendingQueue) Push(seg *alloc.Buffer) { func (this *SendingQueue) Push(seg *alloc.Buffer) {
if this.IsFull() { if this.IsFull() {
return return
@ -339,6 +346,18 @@ func (this *SendingWorker) Push(b []byte) int {
nBytes := 0 nBytes := 0
this.Lock() this.Lock()
defer this.Unlock() defer this.Unlock()
if !this.queue.IsEmpty() {
lastSeg := this.queue.Last()
if lastSeg.Len() < int(this.conn.mss) {
delta := int(this.conn.mss) - lastSeg.Len()
if delta > len(b) {
delta = len(b)
}
lastSeg.Append(b[:delta])
b = b[delta:]
nBytes += delta
}
}
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) {