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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|