1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-26 05:46:10 -04:00

refine error handling in byte reader

This commit is contained in:
Darien Raymond 2017-02-07 00:39:07 +01:00
parent 3643dc37e0
commit 4e8e15d528
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -46,7 +46,7 @@ func (v *BytesToBufferReader) Read() (*Buffer, error) {
type BufferToBytesReader struct {
stream Reader
current *Buffer
eof bool
err error
}
// Fill fills in the internal buffer.
@ -55,20 +55,20 @@ func (v *BufferToBytesReader) Fill() {
b, err := v.stream.Read()
v.current = b
if err != nil {
v.eof = true
v.err = err
v.current = nil
}
}
func (v *BufferToBytesReader) Read(b []byte) (int, error) {
if v.eof {
return 0, io.EOF
if v.err != nil {
return 0, v.err
}
if v.current == nil {
v.Fill()
if v.eof {
return 0, io.EOF
if v.err != nil {
return 0, v.err
}
}
nBytes, err := v.current.Read(b)