Write implements the standard Write interface: it writes data to the internal buffer. If the read end is closed with an error, that err is returned as err; otherwise err is ErrClosedPipe.
(data []byte)
| 178 | // buffer. If the read end is closed with an error, that err is returned as err; |
| 179 | // otherwise err is ErrClosedPipe. |
| 180 | func (w *pipeWriter) Write(data []byte) (int, error) { |
| 181 | w.cond.L.Lock() |
| 182 | defer w.cond.L.Unlock() |
| 183 | |
| 184 | if w.werr != nil { |
| 185 | return 0, w.werr |
| 186 | } |
| 187 | |
| 188 | if w.buf == nil { |
| 189 | w.buf = w.bufPool.Get() |
| 190 | } |
| 191 | |
| 192 | n, err := w.buf.Write(data) |
| 193 | w.cond.Signal() |
| 194 | return n, err |
| 195 | } |
| 196 | |
| 197 | // Close closes the writer; subsequent reads from the read half of the pipe will |
| 198 | // return io.EOF once the internal buffer get empty. |