private void OnCloseOrError(TcpClient client, Exception ex)
        {
            try { client.Close(); } catch { }
            lock (_lock)
            {
                if (_client != client)
                {
                    return; // skipping the RaiseError call below!
                }
                _client = null;
                _logger.LogWarning(ex, "Outgoing connection to {TargetEndPoint} lost while in state {ClientState} with {MessageQueueLength} messages in queue.",
                                   TargetEndPoint, _state, _messageQueue.Count);

                if (_state == State.Sending && _messageQueue.Count > 0)
                {
                    StartConnecting();
                }
                else
                {
                    _logger.LogInformation("Dropping messages from queue and remaining disconnected.");
                    _state = State.Disconnected;
                    _messageQueue.Clear();
                }

                if (_keepAliveTimer != null)
                {
                    _keepAliveTimer.Dispose();
                    _keepAliveTimer = null;
                }
            }
            if (ex != null)
            {
                Transport.RaiseError(ex);
            }
        }
Beispiel #2
0
        private void OnCloseOrError(TcpClient client, Exception ex)
        {
            try { client.Close(); } catch { }
            lock (_lock)
            {
                if (_client != client)
                {
                    return; // skipping the RaiseError call below!
                }
                _client = null;

                if (_state == State.Sending && _messageQueue.Count > 0)
                {
                    StartConnecting();
                }
                else
                {
                    _state = State.Disconnected;
                    _messageQueue.Clear();
                }

                if (_keepAliveTimer != null)
                {
                    _keepAliveTimer.Dispose();
                    _keepAliveTimer = null;
                }
            }
            if (ex != null)
            {
                Transport.RaiseError(ex);
            }
        }