mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 18:17:52 -05:00
35 lines
535 B
Go
35 lines
535 B
Go
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
|
|
}
|