mirror of
https://github.com/btcsuite/btcd.git
synced 2024-11-19 01:40:07 +01:00
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
@ -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 New Issue
Block a user