forked from TrueCloudLab/neoneo-go
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:
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue