simplify writeMsg slightly

This commit is contained in:
Arceliar 2019-10-04 19:25:32 -05:00
parent 58c97df6a0
commit 807c12453c
2 changed files with 5 additions and 6 deletions

2
go.mod
View file

@ -17,3 +17,5 @@ require (
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a
golang.org/x/text v0.3.2 golang.org/x/text v0.3.2
) )
go 1.13

View file

@ -38,12 +38,9 @@ func (s *stream) init(rwc io.ReadWriteCloser) {
func (s *stream) writeMsg(bs []byte) (int, error) { func (s *stream) writeMsg(bs []byte) (int, error) {
s.outputBuffer.Write(streamMsg[:]) s.outputBuffer.Write(streamMsg[:])
s.outputBuffer.Write(wire_encode_uint64(uint64(len(bs)))) s.outputBuffer.Write(wire_encode_uint64(uint64(len(bs))))
n, err := s.outputBuffer.Write(bs) s.outputBuffer.Write(bs)
err2 := s.outputBuffer.Flush() s.outputBuffer.Flush() // TODO? delay flushing until we're idle
if err == nil { return len(bs), nil // TODO? return an error? its not like we check for it...
err = err2
}
return n, err
} }
// readMsg reads a message from the stream, accounting for stream padding, and is *not* thread safe. // readMsg reads a message from the stream, accounting for stream padding, and is *not* thread safe.