public static async Task RunServerLoopAsync(int browserPort, int proxyPort, ILoggerFactory loggerFactory, ILogger logger, CancellationToken token, ProxyOptions?options = null) { StartListener(proxyPort, logger, browserPort); while (!token.IsCancellationRequested) { TcpClient ideClient = await s_tcpListener.AcceptTcpClientAsync(token); _ = Task.Run(async() => { CancellationTokenSource cts = new(); try { int id = Interlocked.Increment(ref s_nextId); logger.LogInformation($"IDE connected to the proxy, id: {id}"); var monoProxy = new FirefoxMonoProxy(loggerFactory.CreateLogger($"{nameof(FirefoxMonoProxy)}-{id}"), id.ToString(), options); await monoProxy.RunForFirefox(ideClient: ideClient, browserPort, cts); } catch (Exception ex) { logger.LogError($"{nameof(FirefoxMonoProxy)} crashed with {ex}"); } finally { cts.Cancel(); } }, token) .ConfigureAwait(false); } }
public static async Task Run(int browserPort, int proxyPort, ILoggerFactory loggerFactory, ILogger logger) { StartListener(proxyPort, logger); logger.LogInformation($"Expecting firefox to be listening on {browserPort}"); while (true) { TcpClient ideClient = await s_tcpListener.AcceptTcpClientAsync(); _ = Task.Run(async() => { CancellationTokenSource cts = new(); try { int id = Interlocked.Increment(ref s_nextId); logger.LogInformation($"IDE connected to the proxy, id: {id}"); var monoProxy = new FirefoxMonoProxy(loggerFactory, id.ToString()); await monoProxy.RunForFirefox(ideClient: ideClient, browserPort, cts); } catch (Exception ex) { logger.LogError($"{nameof(FirefoxMonoProxy)} crashed with {ex}"); throw; } finally { cts.Cancel(); } }, CancellationToken.None) .ConfigureAwait(false); } }