Merge pull request #506 from nspcc-dev/fix/writemsg

network: write messages atomically
This commit is contained in:
Roman Khimov 2019-11-18 10:17:22 +03:00 committed by GitHub
commit 829f9757df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
}
}