MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / Write

Method Write

pkg/streamclient/streamwriter.go:110–140  ·  view source on GitHub ↗
(p []byte)

Source from the content-addressed store, hash-verified

108}
109
110func (w *Writer) Write(p []byte) (int, error) {
111 w.lock.Lock()
112 defer w.lock.Unlock()
113
114 if w.closed {
115 return 0, io.ErrClosedPipe
116 }
117
118 if w.err != nil {
119 return 0, w.err
120 }
121
122 w.buffer = append(w.buffer, p...)
123 n := len(p)
124
125 for len(w.buffer) > 0 {
126 if w.closed {
127 return 0, io.ErrClosedPipe
128 }
129 if w.err != nil {
130 return 0, w.err
131 }
132
133 sent := w.trySendDataLocked()
134 if !sent {
135 w.cond.Wait()
136 }
137 }
138
139 return n, nil
140}
141
142func (w *Writer) trySendDataLocked() bool {
143 availWindow := w.readWindow - w.sentNotAcked

Callers 4

TestBasicReadWriteFunction · 0.95
TestEOFFunction · 0.95
TestFlowControlFunction · 0.95
TestMultipleWritesFunction · 0.95

Calls 2

trySendDataLockedMethod · 0.95
WaitMethod · 0.65

Tested by 4

TestBasicReadWriteFunction · 0.76
TestEOFFunction · 0.76
TestFlowControlFunction · 0.76
TestMultipleWritesFunction · 0.76