Ejemplo n.º 1
0
        public override async Task StopAsync()
        {
            // Request that the accept loop stop
            shutdownTokenSource.Cancel();

            // Stop listening. This causes the accept loop's wait for an
            // incoming socket to fail, which then causes the accept loop to
            // look at the value of shutdownTokenSource.Token.
            listener.Stop();

            // Wait for the accept loop to exit. Once it has exited, no new
            // connections will be accepted, so we can close the outstanding
            // ones.
            await acceptTask;

            // Stop all the outstanding connections.
            var shutdownTask = connections.CleanupAsync(connection =>
            {
                logger.Site().Debug("{0} stopping connection {1}", this, connection);
                return(connection.StopAsync());
            });

            logger.Site().Debug("Waiting for all connections to stop.");
            await shutdownTask;
        }
        public override Task StopAsync()
        {
            Func <EpoxyConnection, Task> cleanupConnectionFunc = connection =>
            {
                logger.Site().Debug("Stopping connection {0}", connection);
                return(connection.StopAsync());
            };

            Func <EpoxyListener, Task> cleanupListenerFunc = listener =>
            {
                logger.Site().Debug("Stopping listener {0}", listener);
                return(listener.StopAsync());
            };

            return(Task.WhenAll(
                       connections.CleanupAsync(cleanupConnectionFunc),
                       listeners.CleanupAsync(cleanupListenerFunc)));
        }