Browse Source

check errors

pull/1524/head^2
Darien Raymond 6 years ago
parent
commit
47f1399995
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
  1. 2
      common/buf/multi_buffer.go
  2. 25
      common/buf/reader.go
  3. 4
      transport/internet/kcp/receiving.go

2
common/buf/multi_buffer.go

@ -118,7 +118,7 @@ func (mb *MultiBuffer) ReadFrom(reader io.Reader) (int64, error) {
// Read implements io.Reader.
func (mb *MultiBuffer) Read(b []byte) (int, error) {
if mb.Len() == 0 {
if mb.IsEmpty() {
return 0, io.EOF
}
endIndex := len(*mb)

25
common/buf/reader.go

@ -97,8 +97,9 @@ func (r *BufferedReader) ReadByte() (byte, error) {
// Read implements io.Reader. It reads from internal buffer first (if available) and then reads from the underlying reader.
func (r *BufferedReader) Read(b []byte) (int, error) {
if r.Buffer != nil {
nBytes, _ := r.Buffer.Read(b)
if !r.Buffer.IsEmpty() {
nBytes, err := r.Buffer.Read(b)
common.Must(err)
if r.Buffer.IsEmpty() {
r.Buffer.Release()
r.Buffer = nil
@ -113,19 +114,21 @@ func (r *BufferedReader) Read(b []byte) (int, error) {
}
mb, err := r.Reader.ReadMultiBuffer()
if mb != nil {
nBytes, _ := mb.Read(b)
if !mb.IsEmpty() {
r.Buffer = mb
}
return nBytes, err
if err != nil {
return 0, err
}
return 0, err
nBytes, err := mb.Read(b)
common.Must(err)
if !mb.IsEmpty() {
r.Buffer = mb
}
return nBytes, err
}
// ReadMultiBuffer implements Reader.
func (r *BufferedReader) ReadMultiBuffer() (MultiBuffer, error) {
if r.Buffer != nil {
if !r.Buffer.IsEmpty() {
mb := r.Buffer
r.Buffer = nil
return mb, nil
@ -136,7 +139,7 @@ func (r *BufferedReader) ReadMultiBuffer() (MultiBuffer, error) {
// ReadAtMost returns a MultiBuffer with at most size.
func (r *BufferedReader) ReadAtMost(size int32) (MultiBuffer, error) {
if r.Buffer == nil {
if r.Buffer.IsEmpty() {
mb, err := r.Reader.ReadMultiBuffer()
if mb.IsEmpty() && err != nil {
return nil, err

4
transport/internet/kcp/receiving.go

@ -3,6 +3,7 @@ package kcp
import (
"sync"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
)
@ -204,7 +205,8 @@ func (w *ReceivingWorker) ReadMultiBuffer() buf.MultiBuffer {
func (w *ReceivingWorker) Read(b []byte) int {
mb := w.ReadMultiBuffer()
nBytes, _ := mb.Read(b)
nBytes, err := mb.Read(b)
common.Must(err)
if !mb.IsEmpty() {
w.leftOver = mb
}

Loading…
Cancel
Save