示例#1
0
        private void SocketConnected(int source, int session, string method, byte[] param)
        {
            ClusterClientSocketConnected socketConnected = new ClusterClientSocketConnected(param);
            string ipEndpoint = string.Format("{0}:{1}", socketConnected.ip, socketConnected.port);

            long tempConnection = 0;
            bool isExist        = m_node2conn.TryGetValue(ipEndpoint, out tempConnection);

            if (isExist)
            {
                m_node2conn.Remove(ipEndpoint);
            }
            m_node2conn.Add(ipEndpoint, socketConnected.connection);

            Queue <WaitForSendRequest> waitQueue = null;

            isExist = m_waitForSendRequests.TryGetValue(ipEndpoint, out waitQueue);
            if (isExist)
            {
                int count = waitQueue.Count;
                for (int i = 0; i < count; i++)
                {
                    WaitForSendRequest request = waitQueue.Dequeue();
                    RemoteRequest(request.Source, request.Method, request.Request, socketConnected.connection, request.Session);
                }
                m_waitForSendRequests.Remove(ipEndpoint);
            }
        }
示例#2
0
        private void SocketError(int source, int session, string method, byte[] param)
        {
            NetSprotoType.SocketError error = new NetSprotoType.SocketError(param);

            long connectionId = 0;
            bool canFind      = m_node2conn.TryGetValue(error.remoteEndPoint, out connectionId);

            // if connection already exist, that means queue of waitForRequest is empty, because
            // it will send and clear after connect success
            if (canFind)
            {
                Debug.Assert(connectionId == error.connection);

                Dictionary <int, WaitForResponseRequest> waitForResponseRequests = null;
                bool isExist = m_conn2sessions.TryGetValue(error.connection, out waitForResponseRequests);
                if (isExist)
                {
                    Queue <int> tempRemoteSessions = new Queue <int>();
                    foreach (var pair in waitForResponseRequests)
                    {
                        tempRemoteSessions.Enqueue(pair.Key);
                    }

                    int count = tempRemoteSessions.Count;
                    for (int i = 0; i < count; i++)
                    {
                        int remoteSession = tempRemoteSessions.Dequeue();
                        ProcessRemoteResponse(remoteSession, null, RPCError.SocketDisconnected);
                    }
                    m_conn2sessions.Remove(error.connection);
                    m_node2conn.Remove(error.remoteEndPoint);
                }
            }
            else
            {
                string ipEndpoint = error.remoteEndPoint;
                Queue <WaitForSendRequest> waitQueue = null;
                bool isExist = m_waitForSendRequests.TryGetValue(ipEndpoint, out waitQueue);
                if (isExist)
                {
                    int count = waitQueue.Count;
                    for (int i = 0; i < count; i++)
                    {
                        WaitForSendRequest req = waitQueue.Dequeue();
                        DoError(req.Source, req.Session, RPCError.SocketDisconnected, string.Format("RemoteCall {0} failure", req.Method));
                    }

                    m_waitForSendRequests.Remove(ipEndpoint);
                }
            }
        }
示例#3
0
        private void CacheRequest(int source, int session, string method, ClusterClientRequest request, string remoteNode)
        {
            string ipEndpoint = m_clusterConfig[remoteNode].ToString();
            Queue <WaitForSendRequest> waittingQueue = null;
            bool isExist = m_waitForSendRequests.TryGetValue(ipEndpoint, out waittingQueue);

            if (!isExist)
            {
                waittingQueue = new Queue <WaitForSendRequest>();
                m_waitForSendRequests.Add(ipEndpoint, waittingQueue);
            }

            if (waittingQueue.Count <= 0)
            {
                string[] ipResult   = ipEndpoint.Split(':');
                string   remoteIp   = ipResult[0];
                int      remotePort = Int32.Parse(ipResult[1]);

                ConnectMessage connectMessage = new ConnectMessage();
                connectMessage.IP          = remoteIp;
                connectMessage.Port        = remotePort;
                connectMessage.TcpObjectId = m_tcpObjectId;
                connectMessage.Type        = SocketMessageType.Connect;

                NetworkPacketQueue.GetInstance().Push(connectMessage);
            }

            WaitForSendRequest waitRequest = new WaitForSendRequest();

            waitRequest.Source  = source;
            waitRequest.Session = session;
            waitRequest.Method  = method;
            waitRequest.Request = request;

            waittingQueue.Enqueue(waitRequest);
        }