Browse Source

buffered input in kcp client

pull/876/merge
Darien Raymond 7 years ago
parent
commit
1e0cad50b1
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
  1. 26
      transport/internet/kcp/dialer.go

26
transport/internet/kcp/dialer.go

@ -19,16 +19,26 @@ var (
)
func fetchInput(ctx context.Context, input io.Reader, reader PacketReader, conn *Connection) {
payload := buf.New()
defer payload.Release()
for {
err := payload.Reset(buf.ReadFrom(input))
if err != nil {
payload.Release()
return
cache := make(chan *buf.Buffer, 1024)
go func() {
for {
payload := buf.New()
if err := payload.Reset(buf.ReadFrom(input)); err != nil {
payload.Release()
close(cache)
return
}
select {
case cache <- payload:
default:
payload.Release()
}
}
}()
for payload := range cache {
segments := reader.Read(payload.Bytes())
payload.Release()
if len(segments) > 0 {
conn.Input(segments)
}

Loading…
Cancel
Save