A secondary listener is delegated requests from a primary listener via a named pipe or UNIX domain socket.
Inheritance: ListenerContext, IDisposable
 public Task PostAsync(Action<ListenerSecondary> callback, ListenerSecondary state)
 {
     var tcs = new TaskCompletionSource<object>();
     lock (_workSync)
     {
         _workAdding.Enqueue(new Work
         {
             CallbackAdapter = _listenerSecondaryCallbackAdapter,
             Callback = callback,
             State = state,
             Completion = tcs
         });
     }
     _post.Send();
     return tcs.Task;
 }
 public void Send(Action<ListenerSecondary> callback, ListenerSecondary state)
 {
     if (_loop.ThreadId == Thread.CurrentThread.ManagedThreadId)
     {
         callback.Invoke(state);
     }
     else
     {
         PostAsync(callback, state).Wait();
     }
 }
Esempio n. 3
0
        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;
            }
        }