github.com/moqsien/xraycore@v1.8.5/transport/pipe/reader.go (about) 1 package pipe 2 3 import ( 4 "time" 5 6 "github.com/moqsien/xraycore/common/buf" 7 ) 8 9 // Reader is a buf.Reader that reads content from a pipe. 10 type Reader struct { 11 pipe *pipe 12 } 13 14 // ReadMultiBuffer implements buf.Reader. 15 func (r *Reader) ReadMultiBuffer() (buf.MultiBuffer, error) { 16 return r.pipe.ReadMultiBuffer() 17 } 18 19 // ReadMultiBufferTimeout reads content from a pipe within the given duration, or returns buf.ErrTimeout otherwise. 20 func (r *Reader) ReadMultiBufferTimeout(d time.Duration) (buf.MultiBuffer, error) { 21 return r.pipe.ReadMultiBufferTimeout(d) 22 } 23 24 // Interrupt implements common.Interruptible. 25 func (r *Reader) Interrupt() { 26 r.pipe.Interrupt() 27 } 28 29 // ReturnAnError makes ReadMultiBuffer return an error, only once. 30 func (r *Reader) ReturnAnError(err error) { 31 r.pipe.errChan <- err 32 } 33 34 // Recover catches an error set by ReturnAnError, if exists. 35 func (r *Reader) Recover() (err error) { 36 select { 37 case err = <-r.pipe.errChan: 38 default: 39 } 40 return 41 }