Beispiel #1
0
        void ChangeStatus(UdpConnectionStatus status)
        {
            var oldStatus = this.Status;

            if (oldStatus != status)
            {
                this.Status = status;
                this.logger.Info($"{this} status changed to {status}");
                this.lastStatusChange = DateTime.UtcNow;
                UpdateTimeoutDeadline();

                if (Status == UdpConnectionStatus.Connected)
                {
                    var connectTcs_ = this.connectTcs;
                    if (connectTcs_ != null)
                    {
                        connectTcs_.TrySetResult(null);
                    }

                    this.lastPingSent = DateTime.UtcNow;

                    if (peer.Configuration.AutoMtuExpand)
                    {
                        ExpandMTU();
                    }

                    var openedArgs = new ConnectionOpenedEventArgs(this);
                    peer.Configuration.SynchronizeSafe(() =>
                    {
                        try
                        {
                            OnConnectionOpened(openedArgs);
                        }
                        catch (Exception ex)
                        {
                            logger.Error($"Unhandled exception on {this.GetType().Name}.{nameof(OnConnectionOpened)}: {ex}");
                        }

                        peer.OnConnectionOpenedInternalSynchronized(openedArgs);
                    }, logger);
                }

                var statusChangedArgs = new ConnectionStatusChangedEventArgs(this, status);
                peer.Configuration.SynchronizeSafe(() =>
                {
                    try
                    {
                        OnStatusChanged(statusChangedArgs);
                    }
                    catch (Exception ex)
                    {
                        logger.Error($"Unhandled exception on {this.GetType().Name}.{nameof(OnStatusChanged)}: {ex}");
                    }

                    peer.OnConnectionStatusChangedSynchronized(statusChangedArgs);
                }, logger);
            }
        }
 internal ConnectionStatusChangedEventArgs(UdpConnection connection, UdpConnectionStatus status)
 {
     this.Connection = connection;
     this.Status     = status;
 }