public void Open(IPEndPoint endpoint, Action <Connection> connectionInitializer = null) { if (endpoint == null) { throw new InvalidOperationException("No EndPoint specified"); } if (node != null) { throw new InvalidOperationException("Already opened"); } var tmp = new ClientNode(this, endpoint); try { Exception ex; if ((ex = tmp.TryOpen(connectionInitializer)) != null) { throw ex; } else if (Interlocked.CompareExchange(ref node, tmp, null) == null) { tmp = null; } } finally { if (tmp != null) { tmp.Close(); } } }
public void Open(IPEndPoint endpoint, Action<Connection> connectionInitializer = null) { if (endpoint == null) throw new InvalidOperationException("No EndPoint specified"); if (node != null) throw new InvalidOperationException("Already opened"); var tmp = new ClientNode(this, endpoint); try { Exception ex; if ((ex = tmp.TryOpen(connectionInitializer)) != null) { throw ex; } else if (Interlocked.CompareExchange(ref node, tmp, null) == null) { tmp = null; } } finally { if (tmp != null) tmp.Close(); } }