Skip to content

Commit

Permalink
correctly handle Read errors/EOF
Browse files Browse the repository at this point in the history
Read can read data *and* return an error.
  • Loading branch information
Stebalien committed Mar 8, 2018
1 parent c49327c commit 02aa648
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions p2p/net/pnet/psk_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@ func (c *pskConn) Read(out []byte) (int, error) {

in = in[:maxn] // truncate to required length
n, err := c.Conn.Read(in) // read to in
if err != nil {
return 0, err
if n > 0 {
c.readS20.XORKeyStream(out[:n], in[:n]) // decrypt to out buffer
}

c.readS20.XORKeyStream(out[:n], in[:n]) // decrypt to out buffer

return n, nil
return n, err
}

func (c *pskConn) Write(in []byte) (int, error) {
Expand Down

0 comments on commit 02aa648

Please sign in to comment.