change slide window

This commit is contained in:
ffdfgdfg 2019-09-22 22:08:51 +08:00
parent 1bf4cf2347
commit f0201c1039

View File

@ -66,7 +66,7 @@ func (s *conn) Read(buf []byte) (n int, err error) {
n = <-s.readCh.nCh n = <-s.readCh.nCh
err = <-s.readCh.errCh 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 return
} }
@ -115,6 +115,7 @@ func (s *conn) Write(buf []byte) (n int, err error) {
n = <-s.writeCh.nCh n = <-s.writeCh.nCh
err = <-s.writeCh.errCh err = <-s.writeCh.errCh
} }
//logs.Warn("write window finish n err buf id", n, err, string(buf[:15]), s.connId)
return return
} }
func (s *conn) write(nCh chan int, errCh chan error) { 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 { } else {
Self.mutex.Unlock() Self.mutex.Unlock()
} }
Self.mutex.Lock() minCopy := 512
n = copy(p, Self.windowBuff[Self.off:]) for {
Self.off += uint16(n) 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] p = p[:n]
Self.mutex.Unlock()
return return
} }