private async Task StartImpl(HL7Connection Connection, List <BourneListens> listeners, ObservableCollection <BourneListens> deadListeners, List <TcpClient> clients, Func <TcpClient, int, Task> Read) { RemoveDeadListeners(listeners, deadListeners); //frequent DNS lookup required for Cloud and HA environments where a lower TTL results in faster failover. //For a listener this means a container might have been moved to another server with different IP. var hostEntry = Dns.GetHostEntry(Connection.localHostname); foreach (var ip in hostEntry.AddressList) { _logger.Log(LogLevel.Information, $"{Connection.name} hostEntry: {Connection.localHostname} ip: {ip}"); BourneListens bourne = null; if (ip.AddressFamily == AddressFamily.InterNetworkV6 && Connection.UseIPV6) { if (!listeners.Exists(x => x.localaddr.Equals(ip) && x.port.Equals(Connection.localPort))) { bourne = new BourneListens(ip, Connection.localPort); listeners.Add(bourne); //you can verify Start worked on mac by doing lsof -n -i:2575 | grep LISTEN, where 2575 is HL7 or whatever port you want. bourne.Start(); _logger.Log(LogLevel.Information, $"{Connection.name} is listening on {bourne.LocalEndpoint}"); _logger.Log(LogLevel.Information, $"{Connection.name} Verify with Mac/Linux:lsof -n -i:{Connection.localPort} | grep LISTEN and with echo \"Hello world\" | nc {Connection.localHostname} {Connection.localPort}"); _logger.Log(LogLevel.Information, $"{Connection.name} Verify with Windows:netstat -abno (requires elevated privileges)"); } } if ((ip.AddressFamily == AddressFamily.InterNetwork && Connection.UseIPV4 && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) || (ip.AddressFamily == AddressFamily.InterNetwork && Connection.UseIPV4 && !Connection.UseIPV6 && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))) { if (!listeners.Exists(x => x.localaddr.Equals(ip) && x.port.Equals(Connection.localPort))) { bourne = new BourneListens(ip, Connection.localPort); listeners.Add(bourne); //you can verify Start worked on mac by doing lsof -n -i:2575 | grep LISTEN, where 2575 is HL7 or whatever port you want. bourne.Start(); _logger.Log(LogLevel.Information, $"{Connection.name} is listening on {bourne.LocalEndpoint}"); _logger.Log(LogLevel.Information, $"{Connection.name} Verify with Mac/Linux:lsof -n -i:{Connection.localPort} | grep LISTEN and with echo \"Hello world\" | nc {Connection.localHostname} {Connection.localPort}"); _logger.Log(LogLevel.Information, $"{Connection.name} Verify with Windows:netstat -abno (requires elevated privileges)"); } } } foreach (var listener in listeners) { if (listener != null && listener.LocalEndpoint != null) { if (_taskManager.CanStart($"{Connection.name}.accept: {listener.LocalEndpoint}")) { var newTaskID = _taskManager.NewTaskID(); Task task = new Task(new Action(async() => await _hl7AcceptService.Accept(Connection, listener, clients, Read, newTaskID)), _taskManager.cts.Token); await _taskManager.Start(newTaskID, task, $"{Connection.name}.accept: {listener.LocalEndpoint}", $"{Connection.name}.accept: {listener.LocalEndpoint}", isLongRunning : true); await Task.Delay(1000); } } else { _logger.Log(LogLevel.Information, $"listener is disposed but still in list. Ignoring"); } } }
public async Task Accept(BourneListens bourne, int taskID) { await _hl7AcceptService.Accept(Connection, bourne, clients, Read, taskID); }