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