fix kcp write

pull/1712/head
Darien Raymond 2017-12-05 18:04:34 +01:00
parent 53b0f91873
commit 19a0d21cb6
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 10 additions and 7 deletions

View File

@ -335,7 +335,7 @@ func (v *Connection) Read(b []byte) (int, error) {
}
}
// Write implements the Conn Write method.
// Write implements io.Writer.
func (v *Connection) Write(b []byte) (int, error) {
totalWritten := 0
@ -352,6 +352,7 @@ func (v *Connection) Write(b []byte) (int, error) {
common.Must(rb.Reset(func(bb []byte) (int, error) {
return copy(bb[:v.mss], b[totalWritten:]), nil
}))
v.dataUpdater.WakeUp()
totalWritten += rb.Len()
if totalWritten == len(b) {
return totalWritten, nil
@ -376,6 +377,7 @@ func (v *Connection) Write(b []byte) (int, error) {
}
}
// WriteMultiBuffer implements buf.Writer.
func (v *Connection) WriteMultiBuffer(mb buf.MultiBuffer) error {
defer mb.Release()
@ -392,6 +394,7 @@ func (v *Connection) WriteMultiBuffer(mb buf.MultiBuffer) error {
common.Must(rb.Reset(func(bb []byte) (int, error) {
return mb.Read(bb[:v.mss])
}))
v.dataUpdater.WakeUp()
if mb.IsEmpty() {
return nil
}

View File

@ -288,15 +288,15 @@ func (v *SendingWorker) Push() *buf.Buffer {
v.Lock()
defer v.Unlock()
if !v.window.IsFull() {
b := v.window.Push(v.nextNumber)
v.nextNumber++
return b
if v.window.IsFull() {
return nil
}
return nil
b := v.window.Push(v.nextNumber)
v.nextNumber++
return b
}
// Private: Visible for testing.
func (v *SendingWorker) Write(seg Segment) error {
dataSeg := seg.(*DataSegment)