fix: vision conn read short buffer error

This commit is contained in:
wwqgtxx 2025-04-16 20:38:10 +08:00
parent 9e0889c02c
commit a75e570cca

View File

@ -5,6 +5,7 @@ import (
"crypto/subtle" "crypto/subtle"
gotls "crypto/tls" gotls "crypto/tls"
"encoding/binary" "encoding/binary"
"errors"
"fmt" "fmt"
"io" "io"
"net" "net"
@ -117,10 +118,12 @@ func (vc *Conn) ReadBuffer(buffer *buf.Buffer) error {
case commandPaddingDirect: case commandPaddingDirect:
needReturn := false needReturn := false
if vc.input != nil { if vc.input != nil {
_, err := buffer.ReadFrom(vc.input) _, err := buffer.ReadOnceFrom(vc.input)
if err != nil { if err != nil {
if !errors.Is(err, io.EOF) {
return err return err
} }
}
if vc.input.Len() == 0 { if vc.input.Len() == 0 {
needReturn = true needReturn = true
vc.input = nil vc.input = nil
@ -129,10 +132,12 @@ func (vc *Conn) ReadBuffer(buffer *buf.Buffer) error {
} }
} }
if vc.rawInput != nil { if vc.rawInput != nil {
_, err := buffer.ReadFrom(vc.rawInput) _, err := buffer.ReadOnceFrom(vc.rawInput)
if err != nil { if err != nil {
if !errors.Is(err, io.EOF) {
return err return err
} }
}
needReturn = true needReturn = true
if vc.rawInput.Len() == 0 { if vc.rawInput.Len() == 0 {
vc.rawInput = nil vc.rawInput = nil