You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by bl...@apache.org on 2020/04/01 17:39:08 UTC

[pulsar-dotpulsar] 04/10: found mini optimization on connector.

This is an automated email from the ASF dual-hosted git repository.

blankensteiner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-dotpulsar.git

commit ba46dd94fc970cc14ef5e6f70defde39f28dc1ae
Author: SeĢrgio Silveira <sd...@gmail.com>
AuthorDate: Sun Mar 29 19:32:20 2020 +0200

    found mini optimization on connector.
---
 src/DotPulsar/Internal/Connector.cs              | 11 +++++++++--
 src/DotPulsar/Internal/Process.cs                |  8 ++++----
 src/DotPulsar/Internal/ProducerChannelFactory.cs |  1 +
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/DotPulsar/Internal/Connector.cs b/src/DotPulsar/Internal/Connector.cs
index e5dce0a..b5d70f7 100644
--- a/src/DotPulsar/Internal/Connector.cs
+++ b/src/DotPulsar/Internal/Connector.cs
@@ -91,10 +91,17 @@ namespace DotPulsar.Internal
             }
             catch
             {
+#if NETSTANDARD2_0
                 if (sslStream is null)
                     stream.Dispose();
                 else
                     sslStream.Dispose();
+#else
+                if (sslStream is null)
+                    await stream.DisposeAsync().ConfigureAwait(false);
+                else
+                    await sslStream.DisposeAsync().ConfigureAwait(false);
+#endif
 
                 throw;
             }
@@ -119,9 +126,9 @@ namespace DotPulsar.Internal
                 chain.ChainPolicy.ExtraStore.Add(_trustedCertificateAuthority);
                 _ = chain.Build((X509Certificate2) certificate);
 
-                for (var i = 0; i < chain.ChainElements.Count; i++)
+                foreach (var element in chain.ChainElements)
                 {
-                    if (chain.ChainElements[i].Certificate.Thumbprint == _trustedCertificateAuthority.Thumbprint)
+                    if (element.Certificate.Thumbprint == _trustedCertificateAuthority.Thumbprint)
                         return true;
                 }
 
diff --git a/src/DotPulsar/Internal/Process.cs b/src/DotPulsar/Internal/Process.cs
index e442740..28299b9 100644
--- a/src/DotPulsar/Internal/Process.cs
+++ b/src/DotPulsar/Internal/Process.cs
@@ -22,20 +22,20 @@ namespace DotPulsar.Internal
 {
     public abstract class Process : IProcess
     {
+        protected readonly CancellationTokenSource CancellationTokenSource = new CancellationTokenSource();
+
         protected ChannelState ChannelState;
         protected ExecutorState ExecutorState;
-        protected CancellationTokenSource CancellationTokenSource;
-
-        public Guid CorrelationId { get; }
 
         public Process(Guid correlationId)
         {
             ChannelState = ChannelState.Disconnected;
             ExecutorState = ExecutorState.Ok;
-            CancellationTokenSource = new CancellationTokenSource();
             CorrelationId = correlationId;
         }
 
+        public Guid CorrelationId { get; }
+
         protected abstract void CalculateState();
 
         public void Start() => CalculateState();
diff --git a/src/DotPulsar/Internal/ProducerChannelFactory.cs b/src/DotPulsar/Internal/ProducerChannelFactory.cs
index 1b291fc..c8432f3 100644
--- a/src/DotPulsar/Internal/ProducerChannelFactory.cs
+++ b/src/DotPulsar/Internal/ProducerChannelFactory.cs
@@ -57,6 +57,7 @@ namespace DotPulsar.Internal
             var connection = await _connectionPool.FindConnectionForTopic(_commandProducer.Topic, cancellationToken).ConfigureAwait(false);
             var channel = new Channel(_correlationId, _eventRegister, new AsyncQueue<MessagePackage>());
             var response = await connection.Send(_commandProducer, channel, cancellationToken).ConfigureAwait(false);
+            
             return new ProducerChannel(response.ProducerId, response.ProducerName, _sequenceId, connection);
         }
     }