コード例 #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();
                }
            }
        }
コード例 #2
0
ファイル: TcpClient.cs プロジェクト: ReinhardHsu/NetGain
        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();
            }
        }