Exemplo n.º 1
0
        private void ListeningRoutine()
        {
            lock (_lock)
            {
                try
                {
                    //_streamListener = this.CreateStreamListener();
                    _streamListener.Start();

                    GetLogger().InfoFormat("Listener started at {0}", _streamListener.LocalEndpointName);
                }
                catch (Exception ex)
                {
                    GetLogger().ErrorException("Could not start listener", ex);

                    try
                    {
                        _streamListener.Dispose();
                    }
                    catch
                    {
                        // dismiss
                    }

                    _isRunning = false;

                    // no re-throw
                    return;
                }
            }

            try
            {
                while (true)
                {
                    var stream = _streamListener.AcceptStream();

                    try
                    {
                        var id         = _idGenerator.Generate();
                        var connection = new ServerConnection(this, id, stream, _handlerFactory);

                        lock (_lock)
                        {
                            _connections.Add(connection.Id, connection);
                        }

                        this.ConnectionAccepted?.Invoke(this, connection);

                        connection.Start();
                    }
                    catch (Exception ex)
                    {
                        throw new NotImplementedException(); // todo00000000000[ak]
                    }
                }
            }
            catch (Exception ex)
            {
                throw new NotImplementedException(); // todo00000000000[ak]
            }
        }