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: case err := <-p.done:
return err return err
default: default:
w := io.NewBinWriterFromIO(p.conn) w := io.NewBufBinWriter()
return msg.Encode(w) if err := msg.Encode(w.BinWriter); err != nil {
return err
}
_, err := p.conn.Write(w.Bytes())
return err
} }
} }