Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep copy options when creating a connection #19

Merged
merged 1 commit into from
Dec 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
}