using Microsoft.Extensions.Hosting;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
namespace FastGithub.PacketIntercept
{
///
/// tcp拦截后台服务
///
[SupportedOSPlatform("windows")]
sealed class TcpInterceptHostedService : BackgroundService
{
private readonly IEnumerable tcpInterceptors;
///
/// tcp拦截后台服务
///
///
public TcpInterceptHostedService(IEnumerable tcpInterceptors)
{
this.tcpInterceptors = tcpInterceptors;
}
///
/// https后台
///
///
///
protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
var tasks = this.tcpInterceptors.Select(item => this.InterceptAsync(item, stoppingToken));
return Task.WhenAll(tasks);
}
///
/// 拦截
///
///
///
///
private async Task InterceptAsync(ITcpInterceptor interceptor, CancellationToken cancellationToken)
{
await Task.Yield();
interceptor.Intercept(cancellationToken);
}
}
}