diff --git a/common/bufio/conn.go b/common/bufio/conn.go index d9a3345..23a8f71 100644 --- a/common/bufio/conn.go +++ b/common/bufio/conn.go @@ -283,18 +283,18 @@ func CopyPacketWithPoolTimeout(dest N.PacketWriter, src N.TimeoutPacketReader, t func CopyPacketConn(ctx context.Context, conn N.PacketConn, dest N.PacketConn) error { defer common.Close(conn, dest) - return task.Any(ctx, func() error { + return task.Any(ctx, func(ctx context.Context) error { return common.Error(CopyPacket(dest, conn)) - }, func() error { + }, func(ctx context.Context) error { return common.Error(CopyPacket(conn, dest)) }) } func CopyPacketConnTimeout(ctx context.Context, conn N.PacketConn, dest N.PacketConn, timeout time.Duration) error { defer common.Close(conn, dest) - return task.Any(ctx, func() error { + return task.Any(ctx, func(ctx context.Context) error { return common.Error(CopyPacketTimeout(dest, conn, timeout)) - }, func() error { + }, func(ctx context.Context) error { return common.Error(CopyPacketTimeout(conn, dest, timeout)) }) } diff --git a/common/task/task.go b/common/task/task.go index c7a1f2c..b998194 100644 --- a/common/task/task.go +++ b/common/task/task.go @@ -34,13 +34,13 @@ func Run(ctx context.Context, tasks ...func() error) error { } //goland:noinspection GoVetLostCancel -func Any(ctx context.Context, tasks ...func() error) error { +func Any(ctx context.Context, tasks ...func(ctx context.Context) error) error { runtimeCtx, cancel := context.WithCancel(ctx) var retErr error for _, task := range tasks { currentTask := task go func() { - if err := currentTask(); err != nil { + if err := currentTask(runtimeCtx); err != nil { retErr = err } cancel()