Browse Source

ensure everything are written

pull/1524/head^2
Darien Raymond 6 years ago
parent
commit
7a4b0fff07
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
  1. 16
      common/crypto/io.go

16
common/crypto/io.go

@ -4,7 +4,6 @@ import (
"crypto/cipher"
"io"
"v2ray.com/core/common"
"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 {
defer mb.Release()
size := mb.Len()
if size == 0 {
return nil
}
bs := mb.ToNetBuffers()
for _, b := range bs {
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