public static bool isValidforPack(SessionPack sessionPack) { if (!LongConnector.isAvailable()) { sessionPack.mConnectMode = 2; sessionPack.mCacheBodyBuffer = null; } int mConnectMode = sessionPack.mConnectMode; if (mConnectMode == 1) { return(LongConnector.isValid()); } if (mConnectMode != 2) { return(false); } if (string.IsNullOrEmpty(sessionPack.mCmdUri)) { Log.e("Network", "Cannot send pack via http without uri, will been cancelled. seq= " + sessionPack.mSeqID); sessionPack.mCanceled = true; return(false); } return(ShortConnector.isValid()); }
public static void checkReady() { checkConnectStatus(); checkNeedKeepAliveInShortConn(60000.0); LongConnector.checkReady(); ShortConnector.checkReady(); }
public static void close() { Log.i("Network", "close connector. "); LongConnector.close(); ShortConnector.close(); onPrepareSend(false); }
public bool sendPack(SessionPack sessionPack) { if (sessionPack == null) { Log.e("Network", "CMD to Network: null pack"); return(false); } Log.i("Network", string.Concat(new object[] { "CMD to Network: cmd=", (CmdConst)sessionPack.mCmdID, " seq=", sessionPack.mSeqID })); mRetryAuthLeft = 3; Connector.onPrepareSend(false); LongConnector.setEnable(true); sessionPack.timeInCmd = Util.getNowMilliseconds(); if ((sessionPack.mCmdID == 1) && SessionPackMgr.isAuthing()) { Log.e("Network", "isAuthing, don't send auth request"); return(false); } if (sessionPack.mCmdID == 1 || sessionPack.mCmdID == 0xb2) { SessionPackMgr.putToHead(sessionPack); } else { SessionPackMgr.putToTail(sessionPack); } NetHandler.wakeUp(); return(true); }
public void closeSender() { Log.i("Network", "close sender , clearn all."); LongConnector.setEnable(false); Connector.close(); SessionPackMgr.cancelAllPacket(); SessionPackMgr.getAccount().reset(); SessionPackMgr.setAuthStatus(0); }
public static void onPrepareSend(bool needCheckAlive) { NetHandler.startup(); LongConnector.onPrepare(); ShortConnector.onPrepare(); if (needCheckAlive) { checkNeedKeepAliveInShortConn(0.0); } }
public static void onSendFailed(bool needReconnect) { mFailedCount++; if (mFailedCount > 3) { LongConnector.setAvailable(true); } close(); HostService.mShortConnHosts.onCurrentHostFailed(); }
public static List <RawPackBody> receiveBodyList() { mListRecvPack.Clear(); LongConnector.receive(mListRecvPack); ShortConnector.receiveList(mListRecvPack); if (mListRecvPack.Count > 0) { mLastActiveTimestamp = SessionPack.getNow(); } return(mListRecvPack); }
public static void onSendFailed(bool needReconnect, int connMode) { if ((connMode & 1) != 0) { LongConnector.onSendFailed(needReconnect); } if ((connMode & 2) != 0) { ShortConnector.onSendFailed(needReconnect); } }
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); }
private static void checkNeedKeepAliveInShortConn(double interval) {//NetworkDeviceWatcher.isNetworkAvailable() && if ((!LongConnector.isAvailable()) && ShortConnector.isValid()) { double num = Util.getNowMilliseconds(); if (mLastShortKeepAliveTimestamp == 0.0) { mLastShortKeepAliveTimestamp = num; } if (num >= (mLastShortKeepAliveTimestamp + interval)) { Log.i("Network", "need keep alive in short connnector mode, post event to sync."); EventCenter.postEvent(EventConst.ON_NETSCENE_NOTIFY_SYNC_REQ, null, null); mLastShortKeepAliveTimestamp = num; } } }
private static void checkConnectStatus() { //if (!NetworkDeviceWatcher.isNetworkAvailable()) //{ // setConnectorStatus(ConntectorStatus.Disconnect); //} //else if (!LongConnector.isAvailable() || (mConnectorStatus == ConntectorStatus.Disconnect)) { if (ShortConnector.isAvailable()) { setConnectorStatus(ConntectorStatus.Connected); } else { setConnectorStatus(ConntectorStatus.Disconnect); } } }