Ejemplo n.º 1
0
        public async Task DisconnectAsync(bool gracefulDisconnect)
        {
            IsConnected = false;
            IsShutdown  = true;

            // we complete but no need to await the jobs
            _sendAnnouncementJobs.Complete();
            _sendBlockJobs.Complete();
            _sendTransactionJobs.Complete();

            _announcementStreamCall?.Dispose();
            _transactionStreamCall?.Dispose();
            _blockStreamCall?.Dispose();

            // send disconnect message if the peer is still connected and the connection
            // is stable.
            if (gracefulDisconnect && (_channel.State == ChannelState.Idle || _channel.State == ChannelState.Ready))
            {
                GrpcRequest request = new GrpcRequest {
                    ErrorMessage = "Error while sending disconnect."
                };

                try
                {
                    Metadata metadata = new Metadata {
                        { GrpcConstants.SessionIdMetadataKey, OutboundSessionId }
                    };

                    await RequestAsync(
                        () => _client.DisconnectAsync(new DisconnectReason
                    {
                        Why = DisconnectReason.Types.Reason.Shutdown
                    }, metadata), request);
                }
                catch (NetworkException)
                {
                    // swallow the exception, we don't care because we're disconnecting.
                }
            }

            try
            {
                await _channel.ShutdownAsync();
            }
            catch (InvalidOperationException)
            {
                // if channel already shutdown
            }
        }
Ejemplo n.º 2
0
 public async Task SendDisconnectAsync()
 {
     await _client.DisconnectAsync(new DisconnectReason { Why = DisconnectReason.Types.Reason.Shutdown });
 }