You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/common/buf/merge_reader.go

35 lines
535 B

package buf
type MergingReader struct {
reader Reader
timeoutReader TimeoutReader
}
func NewMergingReader(reader Reader) Reader {
return &MergingReader{
reader: reader,
timeoutReader: reader.(TimeoutReader),
}
}
func (r *MergingReader) Read() (MultiBuffer, error) {
mb, err := r.reader.Read()
if err != nil {
return nil, err
}
if r.timeoutReader == nil {
return mb, nil
}
for {
mb2, err := r.timeoutReader.ReadTimeout(0)
if err != nil {
break
}
mb.AppendMulti(mb2)
}
return mb, nil
}