Exemple #1
0
// We would use win.ReadAll except for a bug in acme
// where it crashes when reading trying to read more
// than the negotiated 9P message size.
func readBody(win *acme.Win) ([]byte, error) {
	var body []byte
	buf := make([]byte, 8000)
	for {
		n, err := win.Read("body", buf)
		if err == io.EOF {
			break
		}
		if err != nil {
			return nil, err
		}
		body = append(body, buf[0:n]...)
	}
	return body, nil
}
Exemple #2
0
// We would use io.Copy except for a bug in acme
// where it crashes when reading trying to read more
// than the negotiated 9P message size.
func copyBody(w io.Writer, win *acme.Win) error {
	buf := make([]byte, 8000)
	for {
		n, err := win.Read("body", buf)
		if err == io.EOF {
			break
		}
		if err != nil {
			return err
		}
		if _, err := w.Write(buf[0:n]); err != nil {
			return fmt.Errorf("write error: %v", err)
		}
	}
	return nil
}