private static bool checkReadyEx() { if (isValid()) { if ((mLastConnectedTimestamp != 0.0) && (SessionPack.getNow() > (mLastConnectedTimestamp + 30000.0))) { EventCenter.postEvent(EventConst.ON_NET_LONGCONN_KEEPALIVE, null, null); mLastConnectedTimestamp = 0.0; } return(true); } if (mReconnectLeft <= 0) { if (mReconnectLeft == 0) { Log.e("Network", "no chance to try connect."); mReconnectLeft = -1; } return(false); } double num = SessionPack.getNow(); double num2 = mLastConnTimestamp + getSleepTime(mReconnectLeft); if ((mReconnectLeft == 3) || (num >= num2)) { mLastConnTimestamp = num; mReconnectLeft--; Connector.setConnectorStatus(ConntectorStatus.Connecting); mSocketClient = new SocketClient(); HostService.HostInfo info = HostService.mLongConnHosts.getAvailableHost(); SocketError error = mSocketClient.Connect(info.mHost, info.mPort); if (error == ((SocketError)((int)SocketError.Success))) { Log.i("Network", "connect success."); mLastConnectedTimestamp = num; //NetworkDeviceWatcher.onConnected(); mReconnectLeft = 2; mFirstKeepAlivePointAfterConnected = restartKeepAlivePoint(0xbb8); mConnFailedCount = 0; Connector.setConnectorStatus(ConntectorStatus.Connected); return(true); } if (error == ((SocketError)((int)SocketError.HostNotFound))) { HostService.setDNSFailed(); } Log.e("Network", "connect error:" + error.ToString()); close(); mConnFailedCount++; if (mConnFailedCount >= 3) { Log.i("Network", "longconnect is not available as connect failed(3/3)."); setAvailable(false); mConnFailedCount = 0; } HostService.mLongConnHosts.onCurrentHostFailed(); Connector.setConnectorStatus(ConntectorStatus.Disconnect); } return(false); }
public static bool checkKeepAlive() { if (mNextHelloTimestamp == 0.0) { return(false); } if (SessionPack.getNow() < mNextHelloTimestamp) { return(false); } if (!SessionPackMgr.getAccount().isValid() || !SessionPackMgr.isValidSessionKey()) { stopKeepAlivePoint(); return(false); } if (mFirstKeepAlivePointAfterConnected == mNextHelloTimestamp) { EventCenter.postEvent(EventConst.ON_NET_MM_NET_NOOP, null, null); } else { EventCenter.postEvent(EventConst.ON_NET_MM_NET_NOOP, null, null); } restartKeepAlivePoint(0xea60); return(true); }
public static List <RawPackBody> receiveBodyList() { mListRecvPack.Clear(); LongConnector.receive(mListRecvPack); ShortConnector.receiveList(mListRecvPack); if (mListRecvPack.Count > 0) { mLastActiveTimestamp = SessionPack.getNow(); } return(mListRecvPack); }
public static bool sendPack(SessionPack sessionPack) { mLastActiveTimestamp = SessionPack.getNow(); switch (sessionPack.mConnectMode) { case 1: return(LongConnector.sendPack(sessionPack)); case 2: return(ShortConnector.sendPack(sessionPack)); } return(true); }
public static int getIdleTime() { double num = SessionPack.getNow(); double mLastActiveTimestamp = Connector.mLastActiveTimestamp; int num3 = (int)((num - mLastActiveTimestamp) / 100.0); if (num3 > 0x3e8) { num3 = 0x3e8; } if (num3 < 10) { num3 = 10; } return(num3); }
public static double restartKeepAlivePoint(int interval) { mNextHelloTimestamp = SessionPack.getNow() + interval; return(mNextHelloTimestamp); }