diff --git a/NATS/Conn.cs b/NATS/Conn.cs index 0acece651..0781dfc4a 100755 --- a/NATS/Conn.cs +++ b/NATS/Conn.cs @@ -453,7 +453,7 @@ private Connection() { } internal Connection(Options opts) { - this.opts = opts; + this.opts = new Options(opts); this.pongs = createPongs(); this.ps = new Parser(this); diff --git a/NATS/Options.cs b/NATS/Options.cs index db4bf5b06..a8e426f14 100755 --- a/NATS/Options.cs +++ b/NATS/Options.cs @@ -55,9 +55,53 @@ public sealed class Options internal int subChanLen = 40000; - // Options can only be created through ConnectionFactory.GetDefaultOptions(); + // Options can only be publicly created through + // ConnectionFactory.GetDefaultOptions(); internal Options() { } + // Copy constructor + internal Options(Options o) + { + this.allowReconnect = o.allowReconnect; + this.AsyncErrorEventHandler = o.AsyncErrorEventHandler; + this.ClosedEventHandler = o.ClosedEventHandler; + this.DisconnectedEventHandler = o.DisconnectedEventHandler; + this.maxPingsOut = o.maxPingsOut; + this.maxReconnect = o.maxReconnect; + + if (o.name != null) + { + this.name = new string(o.name.ToCharArray()); + } + + this.noRandomize = o.noRandomize; + this.pedantic = o.pedantic; + this.pingInterval = o.pingInterval; + this.ReconnectedEventHandler = o.ReconnectedEventHandler; + this.reconnectWait = o.reconnectWait; + this.secure = o.secure; + + if (o.servers != null) + { + this.servers = new string[o.servers.Length]; + Array.Copy(o.servers, this.servers, o.servers.Length); + } + + this.subChanLen = o.subChanLen; + this.timeout = o.timeout; + this.TLSRemoteCertificationValidationCallback = o.TLSRemoteCertificationValidationCallback; + + if (o.url != null) + { + this.url = new String(o.url.ToCharArray()); + } + + if (o.certificates != null) + { + this.certificates = new X509Certificate2Collection(o.certificates); + } + } + /// /// Gets or sets the url used to connect to the NATs server. This may /// contain user information. diff --git a/NATSUnitTests/UnitTestSub.cs b/NATSUnitTests/UnitTestSub.cs index 9fc5aa65a..647c830e2 100755 --- a/NATSUnitTests/UnitTestSub.cs +++ b/NATSUnitTests/UnitTestSub.cs @@ -268,7 +268,7 @@ public void TestAsyncErrHandler() { using (s = c.SubscribeAsync("foo")) { - opts.AsyncErrorEventHandler = (sender, args) => + c.Opts.AsyncErrorEventHandler = (sender, args) => { lock (subLock) { @@ -299,7 +299,7 @@ public void TestAsyncErrHandler() return; Console.WriteLine("Subscriber Waiting...."); - Assert.IsTrue(Monitor.Wait(subLock, 10000)); + Assert.IsTrue(Monitor.Wait(subLock, 500)); Console.WriteLine("Subscriber done."); blockedOnSubscriber = true; } @@ -314,7 +314,7 @@ public void TestAsyncErrHandler() { c.Publish("foo", null); } - + try { c.Flush(1000); diff --git a/NATSUnitTests/UnitTestUtilities.cs b/NATSUnitTests/UnitTestUtilities.cs index 003fc68ca..28b058c3f 100755 --- a/NATSUnitTests/UnitTestUtilities.cs +++ b/NATSUnitTests/UnitTestUtilities.cs @@ -194,10 +194,16 @@ internal static String GetFullCertificatePath(TestContext context, string certif internal static void CleanupExistingServers() { - Process[] procs = Process.GetProcessesByName("gnatsd"); + try + { + Process[] procs = Process.GetProcessesByName("gnatsd"); - foreach (Process proc in procs) - proc.Kill(); + foreach (Process proc in procs) + { + proc.Kill(); + } + } + catch (Exception) { } // ignore } } }