// fire and forget
        private async void DoReconnect()
        {
            var reconnectUrl = UrlBuilder.BuildReconnect(_connection, Name, _connectionData);

            while (TransportHelper.VerifyLastActive(_connection) && _connection.EnsureReconnecting())
            {
                try
                {
                    await Task.Delay(ReconnectDelay);
                    await PerformConnect(reconnectUrl);

                    break;
                }
                catch (OperationCanceledException)
                {
                    break;
                }
                catch (Exception ex)
                {
                    if (ExceptionHelper.IsRequestAborted(ex))
                    {
                        break;
                    }

                    _connection.OnError(ex);
                }
            }
        }
        // internal for testing
        internal async Task Reconnect(IConnection connection, string connectionData)
        {
            var reconnectUrl = UrlBuilder.BuildReconnect(connection, Name, connectionData);

            if (ConnectionState.Disconnected == connection.State || !_webSocket.IsConnected)
            {
                while (TransportHelper.VerifyLastActive(connection) && connection.EnsureReconnecting() && !_disconnectToken.IsCancellationRequested)
                {
                    try
                    {
                        await StartWebSocket(connection, reconnectUrl);

                        if (connection.ChangeState(ConnectionState.Reconnecting, ConnectionState.Connected))
                        {
                            connection.OnReconnected();
                        }

                        break;
                    }
                    catch (OperationCanceledException)
                    {
                        break;
                    }
                    catch (Exception ex)
                    {
                        connection.OnError(ex);
                    }
                    await Task.Delay(ReconnectDelay);
                }
            }
        }
        private async Task DoReconnect()
        {
            var reconnectUrl = UrlBuilder.BuildReconnect(connection, Name, connectionData);

            while (TransportHelper.VerifyLastActive(connection))
            {
                if (connection.EnsureReconnecting())
                {
                    try
                    {
                        PerformConnect(reconnectUrl);
                        break;
                    }
                    catch (OperationCanceledException)
                    {
                        break;
                    }
                    catch (Exception ex)
                    {
                        connection.OnError(ex);
                    }
                    await Task.Delay(ReconnectDelay, CancellationToken.None).ConfigureAwait(false);
                }
                else
                {
                    break;
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Sets LastActiveAt to the current time
 /// </summary>
 void IConnection.MarkActive()
 {
     // Ensure that we haven't gone to sleep since our last "active" marking.
     if (TransportHelper.VerifyLastActive(this))
     {
         _lastActiveAt = DateTime.UtcNow;
     }
 }