Skip to content
Snippets Groups Projects
Commit e52c71a2 authored by Manish R Jain's avatar Manish R Jain
Browse files

Use io.ReadFull to allow for Read() returning before reading the full buffer

parent 1c592684
No related branches found
No related tags found
No related merge requests found
......@@ -42,11 +42,7 @@ func (c *ClientCodec) ReadResponseHeader(r *rpc.Response) error {
func (c *ClientCodec) ReadResponseBody(body interface{}) error {
buf := make([]byte, c.payloadLen)
n, err := c.Rwc.Read(buf)
if n != int(c.payloadLen) {
return fmt.Errorf("ClientCodec expected: %d. Got: %d\n", c.payloadLen, n)
}
_, err := io.ReadFull(c.Rwc, buf)
reply := body.(*Reply)
reply.Data = buf
return err
......
package conn
import (
"errors"
"io"
"log"
"net/rpc"
......@@ -18,12 +17,9 @@ func (c *ServerCodec) ReadRequestHeader(r *rpc.Request) error {
func (c *ServerCodec) ReadRequestBody(data interface{}) error {
b := make([]byte, c.payloadLen)
n, err := c.Rwc.Read(b)
_, err := io.ReadFull(c.Rwc, b)
if err != nil {
log.Fatal("server", err)
}
if n != int(c.payloadLen) {
return errors.New("ServerCodec unable to read request.")
return err
}
if data == nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment