本文整理汇总了C#中System.Net.Connection.SendConnectInfo方法的典型用法代码示例。如果您正苦于以下问题:C# Connection.SendConnectInfo方法的具体用法?C# Connection.SendConnectInfo怎么用?C# Connection.SendConnectInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Connection
的用法示例。
在下文中一共展示了Connection.SendConnectInfo方法的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];
//.........这里部分代码省略.........
示例2: Run
/// <summary> Acceptor thread. Continuously accept new connections. Create a new thread for each new
/// connection and put it in conns. When the thread should stop, it is
/// interrupted by the thread creator.
/// </summary>
public virtual void Run(Object arg)
{
Object[] objArr = arg as object[];
TcpListener listener = objArr[0] as TcpListener;
bool isPrimaryListener = (bool)objArr[1];
System.Net.Sockets.Socket client_sock;
Connection conn = null;
Address peer_addr = null;
while (listener != null)
{
try
{
client_sock = listener.AcceptSocket();
int cport = ((IPEndPoint)client_sock.RemoteEndPoint).Port;
if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ConnectionTable.Run()", "CONNECTION ACCPETED Remote port = " + cport);
client_sock.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1);
client_sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, send_buf_size);
client_sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, recv_buf_size);
object size = client_sock.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer);
size = client_sock.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer);
// create new thread and add to conn table
conn = new Connection(this, client_sock, null, _ncacheLog, true, nagglingSize, _retries, _retryInterval); // will call receive(msg)
// get peer's address
bool connectingFirstTime = conn.readPeerAddress(client_sock, ref peer_addr);
conn.sendLocalAddress(local_addr,connectingFirstTime);
ConnectInfo conInfo = null;
if (((Address)local_addr).CompareTo((Address)peer_addr) > 0)
{
conInfo = new ConnectInfo(ConnectInfo.CONNECT_FIRST_TIME, GetConnectionId());
if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ConnectionTable.Run", peer_addr + " I should send connect_info");
conn.SendConnectInfo(conInfo);
}
else
{
conInfo = conn.ReadConnectInfo(client_sock);
}
conn.ConInfo = conInfo;
conn.ConInfo.ConnectStatus = connectingFirstTime ? ConnectInfo.CONNECT_FIRST_TIME : ConnectInfo.RECONNECTING;
if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ConnectionTable.Run()", "Read peer address " + peer_addr.ToString() + "at port" + cport);
conn.PeerAddress = peer_addr;
if (conInfo.ConnectStatus == ConnectInfo.RECONNECTING)
{
//if other node is reconnecting then we should check for its member ship first.
bool ismember = enclosingInstance.IsMember(peer_addr);
if (!ismember)
{
NCacheLog.CriticalInfo("ConnectionTa ble.Run", "ConnectionTable.Run" + peer_addr + " has connected. but it is no more part of the membership");
conn.SendLeaveNotification();
Thread.Sleep(1000); //just to make sure that peer node receives the leave notification.
conn.Destroy();
continue;
}
}
bool isPrimary = true;
if (NCacheLog.IsInfoEnabled) NCacheLog.Info("ConnectionTable.run", "b4 lock conns.SyncRoot");
try
{
conn_syn_lock.AcquireWriterLock(Timeout.Infinite);
if (isPrimaryListener)
{
if (conns_NIC_1.ContainsKey(peer_addr))
{
if (!secondayrConns_NIC_1.Contains(peer_addr) && useDualConnection)
{
secondayrConns_NIC_1[peer_addr] = conn;
isPrimary = false;
}
else
{
Connection tmpConn = (Connection)conns_NIC_1[peer_addr];
if (conn.ConInfo.Id < tmpConn.ConInfo.Id && conn.ConInfo.ConnectStatus != ConnectInfo.CONNECT_FIRST_TIME)
//.........这里部分代码省略.........