ensure everything are written

pull/1524/head^2
Darien Raymond 6 years ago
parent c15184d904
commit 7a4b0fff07
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

@ -4,7 +4,6 @@ import (
"crypto/cipher" "crypto/cipher"
"io" "io"
"v2ray.com/core/common"
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
) )
@ -55,9 +54,22 @@ func (w *CryptionWriter) Write(data []byte) (int, error) {
func (w *CryptionWriter) WriteMultiBuffer(mb buf.MultiBuffer) error { func (w *CryptionWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
defer mb.Release() defer mb.Release()
size := mb.Len()
if size == 0 {
return nil
}
bs := mb.ToNetBuffers() bs := mb.ToNetBuffers()
for _, b := range bs { for _, b := range bs {
w.stream.XORKeyStream(b, b) w.stream.XORKeyStream(b, b)
} }
return common.Error2(bs.WriteTo(w.writer))
for size > 0 {
n, err := bs.WriteTo(w.writer)
if err != nil {
return err
}
size -= int32(n)
}
return nil
} }

Loading…
Cancel
Save