MCPcopy
hub / github.com/wavetermdev/waveterm / Read

Method Read

pkg/streamclient/streamreader.go:149–187  ·  view source on GitHub ↗
(p []byte)

Source from the content-addressed store, hash-verified

147}
148
149func (r *Reader) Read(p []byte) (int, error) {
150 r.lock.Lock()
151 defer r.lock.Unlock()
152
153 for len(r.buffer) == 0 && !r.eof && r.err == nil && !r.closed {
154 r.cond.Wait()
155 }
156
157 if r.closed {
158 return 0, io.ErrClosedPipe
159 }
160
161 if r.err != nil {
162 return 0, r.err
163 }
164
165 if len(r.buffer) == 0 && r.eof {
166 return 0, io.EOF
167 }
168
169 n := copy(p, r.buffer)
170 r.buffer = r.buffer[n:]
171
172 if n > 0 {
173 currentRwnd := r.readWindow - int64(len(r.buffer))
174 if currentRwnd < 0 {
175 currentRwnd = 0
176 }
177
178 threshold := r.readWindow / 5
179 rwndDiff := currentRwnd - r.lastRwndSent
180
181 if len(r.buffer) == 0 || rwndDiff >= threshold {
182 r.sendAckLocked(false, false, "")
183 }
184 }
185
186 return n, nil
187}
188
189func (r *Reader) UpdateNextSeq(newSeq int64) {
190 r.lock.Lock()

Callers 15

TestBasicReadWriteFunction · 0.95
TestEOFFunction · 0.95
TestFlowControlFunction · 0.95
TestErrorFunction · 0.95
TestMultipleWritesFunction · 0.95
TestOutOfOrderPacketsFunction · 0.95
TestOutOfOrderWithGapsFunction · 0.95
TestOutOfOrderWithEOFFunction · 0.95
fileAppendRunFunction · 0.95
TestBrokerBasicReadWriteFunction · 0.45

Calls 2

sendAckLockedMethod · 0.95
WaitMethod · 0.65

Tested by 15

TestBasicReadWriteFunction · 0.76
TestEOFFunction · 0.76
TestFlowControlFunction · 0.76
TestErrorFunction · 0.76
TestMultipleWritesFunction · 0.76
TestOutOfOrderPacketsFunction · 0.76
TestOutOfOrderWithGapsFunction · 0.76
TestOutOfOrderWithEOFFunction · 0.76
TestBrokerBasicReadWriteFunction · 0.36
TestBrokerEOFFunction · 0.36
TestBrokerFlowControlFunction · 0.36