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.")
|
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.
|
// Use an one-byte buffer to wait for incoming payload.
|
||||||
var firstByte [1]byte
|
var firstByte [1]byte
|
||||||
nBytes, err := r.Read(firstByte[:])
|
nBytes, err := r.Read(firstByte[:])
|
||||||
@ -163,7 +164,7 @@ type SingleReader struct {
|
|||||||
|
|
||||||
// ReadMultiBuffer implements Reader.
|
// ReadMultiBuffer implements Reader.
|
||||||
func (r *SingleReader) ReadMultiBuffer() (MultiBuffer, error) {
|
func (r *SingleReader) ReadMultiBuffer() (MultiBuffer, error) {
|
||||||
b, err := readOne(r.Reader)
|
b, err := ReadBuffer(r.Reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ func (r *ReadVReader) readMulti() (MultiBuffer, error) {
|
|||||||
// ReadMultiBuffer implements Reader.
|
// ReadMultiBuffer implements Reader.
|
||||||
func (r *ReadVReader) ReadMultiBuffer() (MultiBuffer, error) {
|
func (r *ReadVReader) ReadMultiBuffer() (MultiBuffer, error) {
|
||||||
if r.alloc.Current() == 1 {
|
if r.alloc.Current() == 1 {
|
||||||
b, err := readOne(r.Reader)
|
b, err := ReadBuffer(r.Reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -150,17 +150,14 @@ func (c *interConn) Read(b []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *interConn) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
func (c *interConn) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
||||||
const BufferCount = 16
|
firstBuffer, err := buf.ReadBuffer(c)
|
||||||
mb := make(buf.MultiBuffer, 0, BufferCount)
|
if err != nil {
|
||||||
{
|
return nil, err
|
||||||
b := buf.New()
|
|
||||||
if _, err := b.ReadFrom(c.stream); err != nil {
|
|
||||||
b.Release()
|
|
||||||
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() {
|
for len(mb) < BufferCount && c.stream.HasMoreData() {
|
||||||
b := buf.New()
|
b := buf.New()
|
||||||
if _, err := b.ReadFrom(c.stream); err != nil {
|
if _, err := b.ReadFrom(c.stream); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user