Skip to content

Commit

Permalink
Merge pull request #19 from nats-io/copy_options
Browse files Browse the repository at this point in the history
Deep copy options when creating a connection
  • Loading branch information
Colin Sullivan committed Dec 10, 2015
2 parents 5195057 + f07bb7c commit 8a40038
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
2 changes: 1 addition & 1 deletion NATS/Conn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
46 changes: 45 additions & 1 deletion NATS/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/// <summary>
/// Gets or sets the url used to connect to the NATs server. This may
/// contain user information.
Expand Down
6 changes: 3 additions & 3 deletions NATSUnitTests/UnitTestSub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public void TestAsyncErrHandler()
{
using (s = c.SubscribeAsync("foo"))
{
opts.AsyncErrorEventHandler = (sender, args) =>
c.Opts.AsyncErrorEventHandler = (sender, args) =>
{
lock (subLock)
{
Expand Down Expand Up @@ -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;
}
Expand All @@ -314,7 +314,7 @@ public void TestAsyncErrHandler()
{
c.Publish("foo", null);
}

try
{
c.Flush(1000);
Expand Down
12 changes: 9 additions & 3 deletions NATSUnitTests/UnitTestUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit 8a40038

Please sign in to comment.