30 lines
601 B
Go
30 lines
601 B
Go
package fastcgi
|
|
|
|
// streamWriter abstracts out the separation of a stream into discrete records.
|
|
// It only writes maxWrite bytes at a time.
|
|
type streamWriter struct {
|
|
c *FCGIClient
|
|
recType FCGIRequestType
|
|
}
|
|
|
|
func (w *streamWriter) Write(p []byte) (int, error) {
|
|
nn := 0
|
|
for len(p) > 0 {
|
|
n := len(p)
|
|
if n > maxWrite {
|
|
n = maxWrite
|
|
}
|
|
if err := w.c.writeRecord(w.recType, p[:n]); err != nil {
|
|
return nn, err
|
|
}
|
|
nn += n
|
|
p = p[n:]
|
|
}
|
|
return nn, nil
|
|
}
|
|
|
|
func (w *streamWriter) Close() error {
|
|
// send empty record to close the stream
|
|
return w.c.writeRecord(w.recType, nil)
|
|
}
|