mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-03 07:56:42 -05:00
cleanup
This commit is contained in:
parent
a624e50ffe
commit
0ebebfa458
@ -148,11 +148,9 @@ func fetchInput(ctx context.Context, s *Session, output buf.Writer) {
|
|||||||
|
|
||||||
log.Trace(newError("dispatching request to ", dest))
|
log.Trace(newError("dispatching request to ", dest))
|
||||||
data, _ := s.input.ReadTimeout(time.Millisecond * 500)
|
data, _ := s.input.ReadTimeout(time.Millisecond * 500)
|
||||||
if data != nil {
|
if err := writer.Write(data); err != nil {
|
||||||
if err := writer.Write(data); err != nil {
|
log.Trace(newError("failed to write first payload").Base(err))
|
||||||
log.Trace(newError("failed to write first payload").Base(err))
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if err := buf.Copy(signal.BackgroundTimer(), s.input, writer); err != nil {
|
if err := buf.Copy(signal.BackgroundTimer(), s.input, writer); err != nil {
|
||||||
log.Trace(newError("failed to fetch all input").Base(err))
|
log.Trace(newError("failed to fetch all input").Base(err))
|
||||||
|
@ -38,19 +38,18 @@ func (r *Reader) ReadMetadata() (*FrameMetadata, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) Read() (buf.MultiBuffer, error) {
|
func (r *Reader) Read() (buf.MultiBuffer, error) {
|
||||||
r.buffer.Clear()
|
if err := r.buffer.Reset(buf.ReadFullFrom(r.reader, 2)); err != nil {
|
||||||
if err := r.buffer.AppendSupplier(buf.ReadFullFrom(r.reader, 2)); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
dataLen := int(serial.BytesToUint16(r.buffer.Bytes()))
|
dataLen := int(serial.BytesToUint16(r.buffer.Bytes()))
|
||||||
mb := buf.NewMultiBuffer()
|
mb := buf.NewMultiBuffer()
|
||||||
for dataLen > 0 {
|
for dataLen > 0 {
|
||||||
b := buf.New()
|
|
||||||
readLen := buf.Size
|
readLen := buf.Size
|
||||||
if dataLen < readLen {
|
if dataLen < readLen {
|
||||||
readLen = dataLen
|
readLen = dataLen
|
||||||
}
|
}
|
||||||
|
b := buf.New()
|
||||||
if err := b.AppendSupplier(buf.ReadFullFrom(r.reader, readLen)); err != nil {
|
if err := b.AppendSupplier(buf.ReadFullFrom(r.reader, readLen)); err != nil {
|
||||||
mb.Release()
|
mb.Release()
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -77,8 +77,8 @@ func (b *Buffer) Bytes() []byte {
|
|||||||
// Reset resets the content of the Buffer with a supplier.
|
// Reset resets the content of the Buffer with a supplier.
|
||||||
func (b *Buffer) Reset(writer Supplier) error {
|
func (b *Buffer) Reset(writer Supplier) error {
|
||||||
b.start = 0
|
b.start = 0
|
||||||
nBytes, err := writer(b.v[b.start:])
|
nBytes, err := writer(b.v)
|
||||||
b.end = b.start + nBytes
|
b.end = nBytes
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,9 @@ func (r *bufferToBytesReader) writeToInternal(writer io.Writer) (int64, error) {
|
|||||||
mbWriter := NewWriter(writer)
|
mbWriter := NewWriter(writer)
|
||||||
totalBytes := int64(0)
|
totalBytes := int64(0)
|
||||||
if r.leftOver != nil {
|
if r.leftOver != nil {
|
||||||
mbWriter.Write(r.leftOver)
|
if err := mbWriter.Write(r.leftOver); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
totalBytes += int64(r.leftOver.Len())
|
totalBytes += int64(r.leftOver.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user