mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-27 23:31:35 +00:00
Merge pull request #506 from nspcc-dev/fix/writemsg
network: write messages atomically
This commit is contained in:
commit
829f9757df
1 changed files with 8 additions and 2 deletions
|
@ -63,8 +63,14 @@ func (p *TCPPeer) writeMsg(msg *Message) error {
|
|||
case err := <-p.done:
|
||||
return err
|
||||
default:
|
||||
w := io.NewBinWriterFromIO(p.conn)
|
||||
return msg.Encode(w)
|
||||
w := io.NewBufBinWriter()
|
||||
if err := msg.Encode(w.BinWriter); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := p.conn.Write(w.Bytes())
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue