Exemplo n.º 1
0
        public void Send(byte[] buffer, int length, TransportMessage message)
        {
            if (!CanSendOrConnect(message))
            {
                return;
            }

            if (_socket !.TrySend(buffer, 0, length, out var error))
            {
                _failedSendCount = 0;
                return;
            }

            var hasReachedHighWaterMark = error == ZmqErrorCode.EAGAIN;
            var errorMesage             = hasReachedHighWaterMark ? "High water mark reached" : error.ToErrorMessage();

            _logger.ErrorFormat("Unable to send message, destination peer: {0}, MessageTypeId: {1}, MessageId: {2}, Error: {3}", PeerId, message.MessageTypeId, message.Id, errorMesage);
            _errorHandler.OnSendFailed(PeerId, EndPoint, message.MessageTypeId, message.Id);

            if (_failedSendCount >= _options.SendRetriesBeforeSwitchingToClosedState)
            {
                SwitchToClosedState(_options.ClosedStateDurationAfterSendFailure);
            }

            ++_failedSendCount;
        }
Exemplo n.º 2
0
        public void Send(byte[] buffer, int length, TransportMessage message)
        {
            if (!CanSendOrConnect(message))
            {
                return;
            }

            var stopwatch = Stopwatch.StartNew();
            var spinWait  = new SpinWait();

            ZmqErrorCode error;

            while (true)
            {
                if (_socket.TrySend(buffer, 0, length, out error))
                {
                    _failedSendCount = 0;
                    return;
                }

                // EAGAIN: Non-blocking mode was requested and the message cannot be sent at the moment.
                if (error == ZmqErrorCode.EAGAIN && stopwatch.Elapsed < _options.SendTimeout)
                {
                    spinWait.SpinOnce();
                    continue;
                }

                break;
            }

            _logger.ErrorFormat("Unable to send message, destination peer: {0}, MessageTypeId: {1}, MessageId: {2}, Error: {3}", PeerId, message.MessageTypeId, message.Id, error.ToErrorMessage());
            _errorHandler.OnSendFailed(PeerId, EndPoint, message.MessageTypeId, message.Id);

            if (_failedSendCount >= _options.SendRetriesBeforeSwitchingToClosedState)
            {
                SwitchToClosedState(_options.ClosedStateDurationAfterSendFailure);
            }

            ++_failedSendCount;
        }
Exemplo n.º 3
0
        public void Send(byte[] buffer, int length, TransportMessage message)
        {
            if (!CanSendOrConnect(message))
            {
                return;
            }

            if (_socket.SendWithTimeout(buffer, length, _options.SendTimeout) >= 0)
            {
                _failedSendCount = 0;
                return;
            }

            _logger.ErrorFormat("Unable to send message, destination peer: {0}, MessageTypeId: {1}, MessageId: {2}", PeerId, message.MessageTypeId, message.Id);
            _errorHandler.OnSendFailed(PeerId, EndPoint, message.MessageTypeId, message.Id);

            if (_failedSendCount >= _options.SendRetriesBeforeSwitchingToClosedState)
            {
                SwitchToClosedState(_options.ClosedStateDurationAfterSendFailure);
            }

            ++_failedSendCount;
        }