1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

fix timeout reader usage

This commit is contained in:
Darien Raymond 2017-03-27 11:14:55 +02:00
parent 8ce6e741f1
commit 14824c8451
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
3 changed files with 12 additions and 6 deletions

View File

@ -1,13 +1,15 @@
package buf
type MergingReader struct {
reader Reader
leftover *Buffer
reader Reader
timeoutReader TimeoutReader
leftover *Buffer
}
func NewMergingReader(reader Reader) Reader {
return &MergingReader{
reader: reader,
reader: reader,
timeoutReader: reader.(TimeoutReader),
}
}
@ -25,7 +27,11 @@ func (r *MergingReader) Read() (*Buffer, error) {
return b, nil
}
b2, err := r.reader.Read()
if r.timeoutReader == nil {
return b, nil
}
b2, err := r.timeoutReader.ReadTimeout(0)
if err != nil {
return b, nil
}

View File

@ -114,7 +114,7 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
bodyWriter := session.EncodeRequestBody(request, writer)
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.")
}
if !firstPayload.IsEmpty() {

View File

@ -89,7 +89,7 @@ func (v *Stream) ReadTimeout(timeout time.Duration) (*buf.Buffer, error) {
return b, nil
default:
if timeout == 0 {
return nil, ErrReadTimeout
return nil, buf.ErrReadTimeout
}
select {