Ejemplo n.º 1
0
        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();
                }
            }
        }
Ejemplo n.º 2
0
        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();
            }
        }