Esempio n. 1
0
        private async Task AcceptConnections(SocketListener socketListener)
        {
            if (socketListener == null)
            {
                return;
            }

            openListeners.Push(socketListener);

            try
            {
                while (true)
                {
                    var worker = await socketListener.Accept();

                    if (worker == null)
                    {
                        break;
                    }

                    _ = worker.HandleSocket();
                }
            }
            catch (Exception ex)
            {
                logger.LogWarning(ex, "Accept connection failed with exception");
            }
            finally
            {
                Stop();
            }
        }
Esempio n. 2
0
        private async Task AcceptConnections(SocketListener socketListener)
        {
            if (socketListener == null)
            {
                return;
            }

            openListeners.Push(socketListener);

            try
            {
                while (true)
                {
                    var worker = await socketListener.Accept();

                    if (worker == null)
                    {
                        break;
                    }

                    _ = worker.HandleMessage();
                }
            }
            catch (Exception ex)
            {
                Log(ex);
            }
            finally
            {
                Stop();
            }
        }
Esempio n. 3
0
        private async Task AcceptConnections(SocketListener socketListener)
        {
            if (socketListener == null)
            {
                return;
            }

            this.openListeners.Push(socketListener);

            SocketWorkerBase worker;

            try
            {
                while (!this.Options.Cancellation.IsCancellationRequested)
                {
                    try
                    {
                        // socketListener will wait until a client connects and accept's the connection
                        // accept transfers the connection to a separate socket and hands it off to
                        // a worker that will continue listening on that socket and process
                        // messages until the socket is closed by the client or timeout

                        worker = await socketListener.Accept().ConfigureAwait(false);

                        // worker will spin until the socket is closed or timed out allowing
                        // clients to reuse existing socket connections to the KDC

                        _ = worker.HandleSocket();
                    }
                    catch (SocketException sx)
                        when(IsSocketAbort(sx.SocketErrorCode) || IsSocketError(sx.SocketErrorCode))
                        {
                            this.logger.LogTrace(sx, "Accept exception raised by socket with code {Error}", sx.SocketErrorCode);
                            continue;
                        }
                    catch (ObjectDisposedException ex)
                    {
                        this.logger.LogTrace(ex, "Accept exception raised because object was used after dispose");
                        continue;
                    }
                    catch (Exception ex)
                    {
                        this.logger.LogTrace(ex, "Accept exception raised for unknown reason");
                        break;
                    }

                    if (worker == null)
                    {
                        break;
                    }
                }
            }
            finally
            {
                this.Stop();
            }
        }