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

28 lines
407 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 (
2016-08-20 14:55:45 -04:00
"v2ray.com/core/common/log"
2016-05-12 20:20:07 -04:00
)
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-07-16 05:12:53 -04:00
buffer.Release()
2016-05-11 14:54:55 -04:00
return err
2016-01-29 08:39:55 -05:00
}
}
}