mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
fix timeout reader usage
This commit is contained in:
parent
8ce6e741f1
commit
14824c8451
@ -2,12 +2,14 @@ package buf
|
|||||||
|
|
||||||
type MergingReader struct {
|
type MergingReader struct {
|
||||||
reader Reader
|
reader Reader
|
||||||
|
timeoutReader TimeoutReader
|
||||||
leftover *Buffer
|
leftover *Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMergingReader(reader Reader) Reader {
|
func NewMergingReader(reader Reader) Reader {
|
||||||
return &MergingReader{
|
return &MergingReader{
|
||||||
reader: reader,
|
reader: reader,
|
||||||
|
timeoutReader: reader.(TimeoutReader),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +27,11 @@ func (r *MergingReader) Read() (*Buffer, error) {
|
|||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
b2, err := r.reader.Read()
|
if r.timeoutReader == nil {
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
b2, err := r.timeoutReader.ReadTimeout(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
|
|||||||
|
|
||||||
bodyWriter := session.EncodeRequestBody(request, writer)
|
bodyWriter := session.EncodeRequestBody(request, writer)
|
||||||
firstPayload, err := input.ReadTimeout(time.Millisecond * 500)
|
firstPayload, err := input.ReadTimeout(time.Millisecond * 500)
|
||||||
if err != nil && err != ray.ErrReadTimeout {
|
if err != nil && err != buf.ErrReadTimeout {
|
||||||
return errors.Base(err).Message("VMess|Outbound: Failed to get first payload.")
|
return errors.Base(err).Message("VMess|Outbound: Failed to get first payload.")
|
||||||
}
|
}
|
||||||
if !firstPayload.IsEmpty() {
|
if !firstPayload.IsEmpty() {
|
||||||
|
@ -89,7 +89,7 @@ func (v *Stream) ReadTimeout(timeout time.Duration) (*buf.Buffer, error) {
|
|||||||
return b, nil
|
return b, nil
|
||||||
default:
|
default:
|
||||||
if timeout == 0 {
|
if timeout == 0 {
|
||||||
return nil, ErrReadTimeout
|
return nil, buf.ErrReadTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
Loading…
Reference in New Issue
Block a user