wire: only write message payload if there actually is one
There are certain messages that won't have a payload, e.g., verack, causing an unnecessary write of 0 bytes.
This commit is contained in:
parent
c26ffa870f
commit
2cd83210b5
1 changed files with 7 additions and 3 deletions
|
@ -321,9 +321,13 @@ func WriteMessageWithEncodingN(w io.Writer, msg Message, pver uint32,
|
|||
return totalBytes, err
|
||||
}
|
||||
|
||||
// Write payload.
|
||||
n, err = w.Write(payload)
|
||||
totalBytes += n
|
||||
// Only write the payload if there is one, e.g., verack messages don't
|
||||
// have one.
|
||||
if len(payload) > 0 {
|
||||
n, err = w.Write(payload)
|
||||
totalBytes += n
|
||||
}
|
||||
|
||||
return totalBytes, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue