1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-11-14 07:35:05 -05:00

wait for both requests to finish before changing timeout

This commit is contained in:
Darien Raymond
2019-01-30 21:38:25 +01:00
parent e33e450e48
commit b05514b02c

View File

@@ -4,6 +4,7 @@ package dokodemo
import (
"context"
"sync/atomic"
"time"
"v2ray.com/core"
@@ -106,8 +107,13 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
return newError("failed to dispatch request").Base(err)
}
requestCount := int32(1)
requestDone := func() error {
defer timer.SetTimeout(plcy.Timeouts.DownlinkOnly)
defer func() {
if atomic.AddInt32(&requestCount, -1) == 0 {
timer.SetTimeout(plcy.Timeouts.DownlinkOnly)
}
}()
reader := buf.NewReader(conn)
if err := buf.Copy(reader, link.Writer, buf.UpdateActivity(timer)); err != nil {
@@ -144,7 +150,13 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
writer = &buf.SequentialWriter{Writer: tConn}
tReader := buf.NewReader(tConn)
requestCount++
tproxyRequest = func() error {
defer func() {
if atomic.AddInt32(&requestCount, -1) == 0 {
timer.SetTimeout(plcy.Timeouts.DownlinkOnly)
}
}()
if err := buf.Copy(tReader, link.Writer, buf.UpdateActivity(timer)); err != nil {
return newError("failed to transport request (TPROXY conn)").Base(err)
}