mirror of https://github.com/v2ray/v2ray-core
refine error handling in byte reader
parent
3643dc37e0
commit
4e8e15d528
|
@ -46,7 +46,7 @@ func (v *BytesToBufferReader) Read() (*Buffer, error) {
|
||||||
type BufferToBytesReader struct {
|
type BufferToBytesReader struct {
|
||||||
stream Reader
|
stream Reader
|
||||||
current *Buffer
|
current *Buffer
|
||||||
eof bool
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill fills in the internal buffer.
|
// Fill fills in the internal buffer.
|
||||||
|
@ -55,20 +55,20 @@ func (v *BufferToBytesReader) Fill() {
|
||||||
b, err := v.stream.Read()
|
b, err := v.stream.Read()
|
||||||
v.current = b
|
v.current = b
|
||||||
if err != nil {
|
if err != nil {
|
||||||
v.eof = true
|
v.err = err
|
||||||
v.current = nil
|
v.current = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *BufferToBytesReader) Read(b []byte) (int, error) {
|
func (v *BufferToBytesReader) Read(b []byte) (int, error) {
|
||||||
if v.eof {
|
if v.err != nil {
|
||||||
return 0, io.EOF
|
return 0, v.err
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.current == nil {
|
if v.current == nil {
|
||||||
v.Fill()
|
v.Fill()
|
||||||
if v.eof {
|
if v.err != nil {
|
||||||
return 0, io.EOF
|
return 0, v.err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nBytes, err := v.current.Read(b)
|
nBytes, err := v.current.Read(b)
|
||||||
|
|
Loading…
Reference in New Issue