Esempio n. 1
0
// note that after calling this method, you MUST either write returnBytesLength to this pipe
// or return an error code from the Read() method
func (r *readPipe) WriteHeader(code int32, returnBytesLength int) error {
	r.req.status = Status(code)
	headerBytes := r.req.serializeHeader(returnBytesLength)
	log.Printf("readResponse.WriterHeader:  Code %d returnBytesLength %d", code, returnBytesLength)
	r.numInPipe = len(headerBytes) + returnBytesLength
	err := r.pipe.Grow(r.numInPipe)
	if err != nil {
		log.Printf("Error growing pipe to size %d : %s", r.numInPipe, err.Error())
		r.req.status = EIO
		splice.Drop(r.pipe)
		r.pipe = nil
		return err
	}
	// response header goes in buffer first, before read results
	_, err = r.pipe.Write(headerBytes)
	if err != nil {
		log.Printf("Error writing header to pipe prior to read: %s\n", err)
		r.req.status = EIO
		splice.Drop(r.pipe)
		return err
	}
	return nil
}
Esempio n. 2
0
func (r *readPipe) Reset() (err error) {
	splice.Drop(r.pipe)
	r.pipe, err = splice.Get()
	r.numInPipe = 0
	return err
}