当前位置: 首页>>代码示例>>C#>>正文


C# Connection.DestroySilent方法代码示例

本文整理汇总了C#中System.Net.Connection.DestroySilent方法的典型用法代码示例。如果您正苦于以下问题:C# Connection.DestroySilent方法的具体用法?C# Connection.DestroySilent怎么用?C# Connection.DestroySilent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Connection的用法示例。


在下文中一共展示了Connection.DestroySilent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: getConnection

        /// <summary>Try to obtain correct Connection (or create one if not yet existent) </summary>
        protected virtual Connection getConnection(Address dest, Address primaryAddress, bool reEstablishCon, bool isPrimary, bool withFirstNIC,bool connectingFirstTime)
        {
            Connection conn = null;
            System.Net.Sockets.Socket sock;
            Address peer_addr = null;
            try
            {
                if (primaryAddress == null) primaryAddress = dest;
                if (withFirstNIC)
                {
                    if (isPrimary)
                        conn = (Connection)conns_NIC_1[dest];
                    else
                        conn = (Connection)secondayrConns_NIC_1[dest];
                }
                else
                {
                    if (isPrimary)
                        conn = (Connection)conns_NIC_2[primaryAddress];
                    else
                        conn = (Connection)secondayrConns_NIC_2[primaryAddress];
                }

                if ((conn == null ||!connectingFirstTime) && reEstablishCon)
                {

                    try
                    {
                        if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ConnectionTable.getConnection()",   "No Connetion was found found with " + dest.ToString());
                        if (local_addr == null) return null; //cluster being stopped.

                        sock = Connect(dest, withFirstNIC);
                       

                        conn = new Connection(this, sock, primaryAddress, this.NCacheLog, isPrimary, nagglingSize, _retries, _retryInterval);
                        conn.MemManager = MemManager;
                        conn.IamInitiater = true;
                        ConnectInfo conInfo = null;
                        try
                        {
                            byte connectStatus = connectingFirstTime ? ConnectInfo.CONNECT_FIRST_TIME : ConnectInfo.RECONNECTING;
                            
                            conn.sendLocalAddress(local_addr,connectingFirstTime);
                            conn.readPeerAddress(sock,ref peer_addr);
                            if (((Address)local_addr).CompareTo((Address)dest) > 0)
                            {
                                conInfo = new ConnectInfo(connectStatus, GetConnectionId());
                                if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ConnectionTable.getConnection",   dest + " I should send connect_info");
                                conn.SendConnectInfo(conInfo);
                            }
                            else
                            {
                                conInfo = conn.ReadConnectInfo(sock);
                            }
                            //log.Error("ConnectionTable.getConnection",   " conn_info :" + conInfo);
                            conn.ConInfo = conInfo;
                        }
                        catch (System.Exception e)
                        {
                            NCacheLog.Error("ConnectionTable.getConnection()",   e.Message);
                            conn.DestroySilent();
                            return null;
                        }
                        if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ConnectionTable.getConnection",   "b4 lock conns.SyncRoot");
                        try
                        {
                            conn_syn_lock.AcquireWriterLock(Timeout.Infinite);
                            if (isPrimary)
                            {
                                if (withFirstNIC)
                                {
                                    if (conns_NIC_1.ContainsKey(dest))
                                    {
                                        if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ConnectionTable.getConnection()",   "connection is already in the table");
                                        Connection tmpConn = (Connection)conns_NIC_1[dest];
                                        
                                        if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ConnectionTable.getConnection",   "table_con id :" + tmpConn.ConInfo.Id + " new_con id :" + conn.ConInfo.Id);
                                        if (conn.ConInfo.Id < tmpConn.ConInfo.Id)
                                        {
                                            conn.Destroy();
                                            return tmpConn;
                                        }
                                        else
                                        {
                                            if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ConnectionTable.getConnection()",   dest + "--->connection present in the table is terminated");
                                            
                                            tmpConn.Destroy();
                                             conns_NIC_1.Remove(dest);
                                         }
                                    }

                                    notifyConnectionOpened(dest);
                                }
                                else
                                {
                                    if (conns_NIC_2.ContainsKey(primaryAddress))
                                    {
                                        if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ConnectionTable.getConnection()",   "connection is already in the table");
                                        Connection tmpConn = (Connection)conns_NIC_1[dest];
//.........这里部分代码省略.........
开发者ID:javithalion,项目名称:NCache,代码行数:101,代码来源:ConnectionTable.cs

示例2: Run


//.........这里部分代码省略.........
                                    Connection tmpConn = (Connection)conns_NIC_1[peer_addr];

                                    if (conn.ConInfo.Id < tmpConn.ConInfo.Id && conn.ConInfo.ConnectStatus != ConnectInfo.CONNECT_FIRST_TIME)

                                    {

                                        NCacheLog.CriticalInfo("ConnectionTable.Run", "1. Destroying Connection (conn.ConInfo.Id < tmpConn.ConInfo.Id)" + conn.ConInfo.Id.ToString() + ":" + tmpConn.ConInfo.Id.ToString() + conn.ToString());

                                        conn.Destroy();
                                        continue;
                                    }
                                    else
                                    {
                                        if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ConnectionTable.Run()", "-->connection present in the talble is terminated");
                                        
                                        tmpConn.Destroy();
                                        conns_NIC_1.Remove(peer_addr);
                                    }

                                }

                            }
                            
                        }

                        else
                        {
                            if (conns_NIC_2.ContainsKey(peer_addr))
                            {
                                if (!secondayrConns_NIC_2.Contains(peer_addr) && useDualConnection)
                                {
                                    secondayrConns_NIC_2[peer_addr] = conn;
                                    isPrimary = false;
                                }
                                else
                                {
                                    if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ConnectionTable.Run()", "connection alrady exists in the table");
                                    Connection tmpConn = (Connection)conns_NIC_2[peer_addr];

                                  
                                    if (conn.ConInfo.Id < tmpConn.ConInfo.Id)
                                    {
                                        conn.Destroy();
                                        continue;
                                    }
                                    else
                                    {
                                        NCacheLog.Error("ConnectionTable.Run()", "connection present in the talble is terminated");
                                        tmpConn.Destroy();
                                        conns_NIC_2.Remove(peer_addr);
                                    }
                                }
                            }
                        }
                        conn.IsPrimary = isPrimary;
                        addConnection(peer_addr, conn, isPrimary, isPrimaryListener);

                        conn.MemManager = memManager;

                        if (useDedicatedSender) AddDedicatedMessageSender(conn.peer_addr, conn, isPrimaryListener);

                        conn.init(); 
                    }
                    finally
                    {
                        conn_syn_lock.ReleaseWriterLock();
                    }
                    if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ConnectionTable.run", "after lock conns.SyncRoot");

                    if (isPrimary && isPrimaryListener)

                        notifyConnectionOpened(peer_addr);



                    if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ConnectionTable.Run()", "connection working now");
                }
                catch (ExtSocketException sock_ex)
                {
                    NCacheLog.Error("ConnectionTable.Run", "exception is " + sock_ex);

                    if (conn != null)
                        conn.DestroySilent();
                    if (srv_sock1 == null)
                        break; // socket was closed, therefore stop
                }
                catch (System.Exception ex)
                {
                    NCacheLog.Error("ConnectionTable.Run", "exception is " + ex);

                    if (srv_sock1 == null)
                        break; // socket was closed, therefore stop

                }
                finally
                {

                }
            }
        }
开发者ID:javithalion,项目名称:NCache,代码行数:101,代码来源:ConnectionTable.cs


注:本文中的System.Net.Connection.DestroySilent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。