From f0201c103926ad7c4054fcfac510df5eecd70c65 Mon Sep 17 00:00:00 2001 From: ffdfgdfg Date: Sun, 22 Sep 2019 22:08:51 +0800 Subject: [PATCH] change slide window --- lib/mux/conn.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/mux/conn.go b/lib/mux/conn.go index 81f876f..b1141ee 100644 --- a/lib/mux/conn.go +++ b/lib/mux/conn.go @@ -66,7 +66,7 @@ func (s *conn) Read(buf []byte) (n int, err error) { n = <-s.readCh.nCh err = <-s.readCh.errCh } - //logs.Warn("read window finish conn read n err buf", n, err, string(buf[:15])) + //logs.Warn("read window finish conn read n err buf", n, err, string(buf[:15]), s.connId) return } @@ -115,6 +115,7 @@ func (s *conn) Write(buf []byte) (n int, err error) { n = <-s.writeCh.nCh err = <-s.writeCh.errCh } + //logs.Warn("write window finish n err buf id", n, err, string(buf[:15]), s.connId) return } func (s *conn) write(nCh chan int, errCh chan error) { @@ -334,11 +335,22 @@ func (Self *window) Read(p []byte) (n int, err error) { } else { Self.mutex.Unlock() } - Self.mutex.Lock() - n = copy(p, Self.windowBuff[Self.off:]) - Self.off += uint16(n) + minCopy := 512 + for { + Self.mutex.Lock() + if len(p) == n || Self.len() == 0 { + Self.mutex.Unlock() + break + } + if n+minCopy > len(p) { + minCopy = len(p) - n + } + i := copy(p[n:n+minCopy], Self.windowBuff[Self.off:]) + Self.off += uint16(i) + n += i + Self.mutex.Unlock() + } p = p[:n] - Self.mutex.Unlock() return }