Skip to content

Commit

Permalink
platforms/firmata/client: use io.ReadFull
Browse files Browse the repository at this point in the history
This CL uses io.ReadFull to make sure exactly n bytes are read, and
correctly handle io.EOF and co.

Fixes hybridgroup#343.

Signed-off-by: Sebastien Binet <[email protected]>

Conflicts:
	platforms/firmata/client/client.go
  • Loading branch information
sbinet authored and deadprogram committed Dec 3, 2016
1 parent 7ac80c0 commit 9fc8828
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions platforms/firmata/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,21 +315,9 @@ func (b *Client) write(data []byte) (err error) {
return
}

func (b *Client) read(length int) (buf []byte, err error) {
i := 0
for length > 0 {
tmp := make([]byte, length)
if i, err = b.connection.Read(tmp); err != nil {
if err.Error() != "EOF" {
return
}
time.Sleep(5 * time.Millisecond)
}
if i > 0 {
buf = append(buf, tmp...)
length = length - i
}
}
func (b *Client) read(n int) (buf []byte, err error) {
buf = make([]byte, n)
_, err = io.ReadFull(b.connection, buf)
return
}

Expand Down

0 comments on commit 9fc8828

Please sign in to comment.