1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-07 02:38:10 -05:00
v2fly/common/io/transport.go

27 lines
400 B
Go
Raw Normal View History

2016-01-29 08:39:55 -05:00
package io
2016-05-12 20:20:07 -04:00
import (
"github.com/v2ray/v2ray-core/common/log"
)
2016-04-18 12:44:10 -04:00
func Pipe(reader Reader, writer Writer) error {
2016-01-29 08:39:55 -05:00
for {
buffer, err := reader.Read()
2016-05-11 14:54:29 -04:00
if err != nil {
2016-05-12 20:20:07 -04:00
log.Debug("IO: Pipe exits as ", err)
2016-05-11 14:54:55 -04:00
return err
2016-05-11 14:54:29 -04:00
}
if buffer.IsEmpty() {
2016-02-01 06:22:29 -05:00
buffer.Release()
2016-05-11 14:54:29 -04:00
continue
2016-01-29 08:39:55 -05:00
}
2016-05-11 14:54:29 -04:00
err = writer.Write(buffer)
2016-01-29 08:39:55 -05:00
if err != nil {
2016-05-12 20:20:07 -04:00
log.Debug("IO: Pipe exits as ", err)
2016-05-11 14:54:55 -04:00
return err
2016-01-29 08:39:55 -05:00
}
}
}