1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00

Try writing again when there are some bytes left

This commit is contained in:
V2Ray 2015-10-09 13:07:42 +02:00
parent 936fd03c30
commit cdea39ff95

View File

@ -33,7 +33,10 @@ func ReaderToChan(stream chan<- *alloc.Buffer, reader io.Reader) error {
// ChanToWriter dumps all content from a given chan to a writer until the chan is closed. // ChanToWriter dumps all content from a given chan to a writer until the chan is closed.
func ChanToWriter(writer io.Writer, stream <-chan *alloc.Buffer) error { func ChanToWriter(writer io.Writer, stream <-chan *alloc.Buffer) error {
for buffer := range stream { for buffer := range stream {
_, err := writer.Write(buffer.Value) nBytes, err := writer.Write(buffer.Value)
if nBytes < buffer.Len() {
_, err = writer.Write(buffer.Value[nBytes:])
}
buffer.Release() buffer.Release()
if err != nil { if err != nil {
return err return err