mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
open ReadBuffer for quic connections
This commit is contained in:
parent
3340f81d03
commit
0f63be6340
@ -24,7 +24,8 @@ func readOneUDP(r io.Reader) (*Buffer, error) {
|
||||
return nil, newError("Reader returns too many empty payloads.")
|
||||
}
|
||||
|
||||
func readOne(r io.Reader) (*Buffer, error) {
|
||||
// ReadBuffer reads a Buffer from the given reader, without allocating large buffer in advance.
|
||||
func ReadBuffer(r io.Reader) (*Buffer, error) {
|
||||
// Use an one-byte buffer to wait for incoming payload.
|
||||
var firstByte [1]byte
|
||||
nBytes, err := r.Read(firstByte[:])
|
||||
@ -163,7 +164,7 @@ type SingleReader struct {
|
||||
|
||||
// ReadMultiBuffer implements Reader.
|
||||
func (r *SingleReader) ReadMultiBuffer() (MultiBuffer, error) {
|
||||
b, err := readOne(r.Reader)
|
||||
b, err := ReadBuffer(r.Reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ func (r *ReadVReader) readMulti() (MultiBuffer, error) {
|
||||
// ReadMultiBuffer implements Reader.
|
||||
func (r *ReadVReader) ReadMultiBuffer() (MultiBuffer, error) {
|
||||
if r.alloc.Current() == 1 {
|
||||
b, err := readOne(r.Reader)
|
||||
b, err := ReadBuffer(r.Reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -150,17 +150,14 @@ func (c *interConn) Read(b []byte) (int, error) {
|
||||
}
|
||||
|
||||
func (c *interConn) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
||||
const BufferCount = 16
|
||||
mb := make(buf.MultiBuffer, 0, BufferCount)
|
||||
{
|
||||
b := buf.New()
|
||||
if _, err := b.ReadFrom(c.stream); err != nil {
|
||||
b.Release()
|
||||
firstBuffer, err := buf.ReadBuffer(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mb = append(mb, b)
|
||||
}
|
||||
|
||||
const BufferCount = 16
|
||||
mb := make(buf.MultiBuffer, 0, BufferCount)
|
||||
mb = append(mb, firstBuffer)
|
||||
for len(mb) < BufferCount && c.stream.HasMoreData() {
|
||||
b := buf.New()
|
||||
if _, err := b.ReadFrom(c.stream); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user