mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 17:46:58 -05:00
remove unnecessary err object from SplitBytes
This commit is contained in:
parent
842a089dad
commit
cb7646f682
@ -18,8 +18,7 @@ func ReadAllToBytes(reader io.Reader) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
b := make([]byte, mb.Len())
|
||||
mb, _, err = SplitBytes(mb, b)
|
||||
common.Must(err)
|
||||
mb, _ = SplitBytes(mb, b)
|
||||
ReleaseMulti(mb)
|
||||
return b, nil
|
||||
}
|
||||
@ -95,7 +94,7 @@ func ReadFrom(reader io.Reader) (MultiBuffer, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func SplitBytes(mb MultiBuffer, b []byte) (MultiBuffer, int, error) {
|
||||
func SplitBytes(mb MultiBuffer, b []byte) (MultiBuffer, int) {
|
||||
totalBytes := 0
|
||||
|
||||
for len(mb) > 0 {
|
||||
@ -110,7 +109,7 @@ func SplitBytes(mb MultiBuffer, b []byte) (MultiBuffer, int, error) {
|
||||
mb = mb[1:]
|
||||
}
|
||||
|
||||
return mb, totalBytes, nil
|
||||
return mb, totalBytes
|
||||
}
|
||||
|
||||
// Len returns the total number of bytes in the MultiBuffer.
|
||||
@ -188,9 +187,9 @@ func (c *MultiBufferContainer) Read(b []byte) (int, error) {
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
mb, nBytes, err := SplitBytes(c.MultiBuffer, b)
|
||||
mb, nBytes := SplitBytes(c.MultiBuffer, b)
|
||||
c.MultiBuffer = mb
|
||||
return nBytes, err
|
||||
return nBytes, nil
|
||||
}
|
||||
|
||||
func (c *MultiBufferContainer) ReadMultiBuffer() (MultiBuffer, error) {
|
||||
|
@ -21,8 +21,7 @@ func TestMultiBufferRead(t *testing.T) {
|
||||
mb := MultiBuffer{b1, b2}
|
||||
|
||||
bs := make([]byte, 32)
|
||||
_, nBytes, err := SplitBytes(mb, bs)
|
||||
assert(err, IsNil)
|
||||
_, nBytes := SplitBytes(mb, bs)
|
||||
assert(nBytes, Equals, 4)
|
||||
assert(bs[:nBytes], Equals, []byte("abcd"))
|
||||
}
|
||||
|
@ -46,8 +46,7 @@ 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.IsEmpty() {
|
||||
buffer, nBytes, err := SplitBytes(r.Buffer, b)
|
||||
common.Must(err)
|
||||
buffer, nBytes := SplitBytes(r.Buffer, b)
|
||||
r.Buffer = buffer
|
||||
if r.Buffer.IsEmpty() {
|
||||
r.Buffer = nil
|
||||
@ -60,8 +59,7 @@ func (r *BufferedReader) Read(b []byte) (int, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
mb, nBytes, err := SplitBytes(mb, b)
|
||||
common.Must(err)
|
||||
mb, nBytes := SplitBytes(mb, b)
|
||||
if !mb.IsEmpty() {
|
||||
r.Buffer = mb
|
||||
}
|
||||
|
@ -57,8 +57,7 @@ func TestReadvReader(t *testing.T) {
|
||||
}
|
||||
|
||||
rdata := make([]byte, size)
|
||||
_, _, err = SplitBytes(rmb, rdata)
|
||||
common.Must(err)
|
||||
SplitBytes(rmb, rdata)
|
||||
|
||||
if err := compare.BytesEqualWithDetail(data, rdata); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -285,8 +285,7 @@ func (w *AuthenticationWriter) writeStream(mb buf.MultiBuffer) error {
|
||||
rawBytes := temp.Extend(payloadSize)
|
||||
|
||||
for {
|
||||
nb, nBytes, err := buf.SplitBytes(mb, rawBytes)
|
||||
common.Must(err)
|
||||
nb, nBytes := buf.SplitBytes(mb, rawBytes)
|
||||
mb = nb
|
||||
|
||||
eb, err := w.seal(rawBytes[:nBytes])
|
||||
|
@ -116,7 +116,7 @@ func (w *ChunkWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
||||
defer buf.ReleaseMulti(mb)
|
||||
|
||||
for {
|
||||
mb, payloadLen, _ := buf.SplitBytes(mb, w.buffer[2+AuthSize:])
|
||||
mb, payloadLen := buf.SplitBytes(mb, w.buffer[2+AuthSize:])
|
||||
binary.BigEndian.PutUint16(w.buffer, uint16(payloadLen))
|
||||
w.auth.Authenticate(w.buffer[2+AuthSize:2+AuthSize+payloadLen], w.buffer[2:])
|
||||
if err := buf.WriteAllBytes(w.writer, w.buffer[:2+AuthSize+payloadLen]); err != nil {
|
||||
|
@ -3,7 +3,6 @@ package kcp
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
)
|
||||
|
||||
@ -209,8 +208,7 @@ func (w *ReceivingWorker) Read(b []byte) int {
|
||||
if mb.IsEmpty() {
|
||||
return 0
|
||||
}
|
||||
mb, nBytes, err := buf.SplitBytes(mb, b)
|
||||
common.Must(err)
|
||||
mb, nBytes := buf.SplitBytes(mb, b)
|
||||
if !mb.IsEmpty() {
|
||||
w.leftOver = mb
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user