public IDisposable CreateServer(string scheme, string host, int port, Func<Frame, Task> application) { var listeners = new List<IDisposable>(); try { var pipeName = (Libuv.IsWindows ? @"\\.\pipe\kestrel_" : "/tmp/kestrel_") + Guid.NewGuid().ToString("n"); var single = Threads.Count == 1; var first = true; foreach (var thread in Threads) { if (single) { var listener = new Listener(Memory); listeners.Add(listener); listener.StartAsync(scheme, host, port, thread, application).Wait(); } else if (first) { var listener = new ListenerPrimary(Memory); listeners.Add(listener); listener.StartAsync(pipeName, scheme, host, port, thread, application).Wait(); } else { var listener = new ListenerSecondary(Memory); listeners.Add(listener); listener.StartAsync(pipeName, thread, application).Wait(); } first = false; } return new Disposable(() => { foreach (var listener in listeners) { listener.Dispose(); } }); } catch { foreach (var listener in listeners) { listener.Dispose(); } throw; } }
public IDisposable CreateServer(string scheme, string host, int port, Func<Frame, Task> application) { var listeners = new List<Listener>(); foreach (var thread in Threads) { var listener = new Listener(Memory); listener.StartAsync(scheme, host, port, thread, application).Wait(); listeners.Add(listener); } return new Disposable(() => { foreach (var listener in listeners) { listener.Dispose(); } }); }