Example #1
0
        public void Dispose()
        {
            _currentSession?.Dispose();
            _currentSession = null;

            _inboundChannel?.Writer.Complete();
            _inboundChannel = null;

            _controlChannel?.Writer.Complete();
            _controlChannel = null;
        }
Example #2
0
        internal void AddSession(PNetMeshSession session)
        {
            _sessions = _sessions.Add(session);
            Timestamp = Math.Max(session.Timestamp, Timestamp);

            session.AttachTo(_inboundChannel.Writer, _controlChannel.Writer);
            session.StatusChanged += OnSessionStatusChanged;
            OnSessionStatusChanged(session, EventArgs.Empty);

            //todo cleanup _sessions

            _logger.LogDebug("session[{sessionIndex}] to {remoteEndPoint} added.",
                             session.SenderIndex, session.RemoteEndPoint);
        }
Example #3
0
        private void OnSessionStatusChanged(object sender, EventArgs e)
        {
            var session = sender as PNetMeshSession;

            switch (session.Status)
            {
            case PNetMeshSessionStatus.Open:
                _currentSession = session;     //undone close other
                if (_controlTask.IsCompleted)
                {
                    _controlTask = Task.Run(ProcessControl)
                                   .ContinueWith(t => _logger.LogError(t.Exception, "control process error"), TaskContinuationOptions.OnlyOnFaulted);
                }
                break;

            case PNetMeshSessionStatus.Closed:
                session.StatusChanged -= OnSessionStatusChanged;
                break;
            }
        }