OCStackResult HandleKeepAliveResponse(const CAEndpoint_t *endPoint, OCStackResult responseCode, const OCRepPayload *respPayload) { VERIFY_NON_NULL(endPoint, FATAL, OC_STACK_INVALID_PARAM); OIC_LOG(DEBUG, TAG, "HandleKeepAliveResponse IN"); // Get entry from KeepAlive table. uint32_t index = 0; KeepAliveEntry_t *entry = GetEntryFromEndpoint(endPoint, &index); if (!entry) { // Receive response message about find /oic/ping request. OIC_LOG(ERROR, TAG, "There is no connection info in KeepAlive table"); if (OC_STACK_NO_RESOURCE == responseCode) { OIC_LOG(ERROR, TAG, "Server doesn't have a ping resource"); return OC_STACK_ERROR; } else if (OC_STACK_OK == responseCode) { int64_t *recvInterval = NULL; size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 }; OCRepPayloadGetIntArray(respPayload, INTERVAL_ARRAY, &recvInterval, dimensions); size_t serverIntervalSize = calcDimTotal(dimensions); entry = AddKeepAliveEntry(endPoint, OC_CLIENT, recvInterval); if (!entry) { OIC_LOG(ERROR, TAG, "Failed to add new KeepAlive entry"); return OC_STACK_ERROR; } if (serverIntervalSize) { // update interval size with received size of server. entry->intervalSize = serverIntervalSize; } // Send first ping message return SendPingMessage(entry); } } else { // Set sentPingMsg values with false. entry->sentPingMsg = false; } OIC_LOG(DEBUG, TAG, "HandleKeepAliveResponse OUT"); return OC_STACK_OK; }
void ProcessKeepAlive() { if (!g_isKeepAliveInitialized) { OIC_LOG(ERROR, TAG, "KeepAlive not initialized"); return; } uint32_t len = u_arraylist_length(g_keepAliveConnectionTable); for (uint32_t i = 0; i < len; i++) { KeepAliveEntry_t *entry = (KeepAliveEntry_t *)u_arraylist_get(g_keepAliveConnectionTable, i); if (NULL == entry) { continue; } uint64_t currentTime = OICGetCurrentTime(TIME_IN_US); if (OC_CLIENT == entry->mode) { if (entry->sentPingMsg) { /* * If an OIC Client does not receive the response within 1 minutes, * terminate the connection. * In this case the timeStamp means last time sent ping message. */ if ((KEEPALIVE_RESPONSE_TIMEOUT_SEC * USECS_PER_SEC) <= currentTime - entry->timeStamp) { OIC_LOG(DEBUG, TAG, "Client does not receive the response within 1 minutes."); // Send message to disconnect session. SendDisconnectMessage(entry); } } else { if ((entry->interval * KEEPALIVE_RESPONSE_TIMEOUT_SEC * USECS_PER_SEC) <= currentTime - entry->timeStamp) { // Increase interval value. IncreaseInterval(entry); OCStackResult result = SendPingMessage(entry); if (OC_STACK_OK != result) { OIC_LOG(ERROR, TAG, "Failed to send ping request"); continue; } } } } else if (OC_SERVER == entry->mode) { /* * If an OIC Server does not receive a PUT request to ping resource * within the specified interval time, terminate the connection. * In this case the timeStamp means last time received ping message. */ if ((entry->interval * KEEPALIVE_RESPONSE_TIMEOUT_SEC * USECS_PER_SEC) <= currentTime - entry->timeStamp) { OIC_LOG(DEBUG, TAG, "Server does not receive a PUT request."); SendDisconnectMessage(entry); } } } }
void CLevel::ClientSend () { if (GameID() == GAME_SINGLE || OnClient()) { if ( !net_HasBandwidth() ) return; }; #ifdef DEBUG if (g_bCalculatePing) SendPingMessage(); #endif // DEBUG NET_Packet P; u32 start = 0; //----------- for E3 ----------------------------- // if () { // if (!(Game().local_player) || Game().local_player->testFlag(GAME_PLAYER_FLAG_VERY_VERY_DEAD)) return; if (CurrentControlEntity()) { CObject* pObj = CurrentControlEntity(); if (!pObj->getDestroy() && pObj->net_Relevant()) { P.w_begin (M_CL_UPDATE); P.w_u16 (u16(pObj->ID()) ); P.w_u32 (0); //reserved place for client's ping pObj->net_Export (P); if (P.B.count>9) { if (OnServer()) { if (net_IsSyncronised() && IsDemoSave()) { DemoCS.Enter(); Demo_StoreData(P.B.data, P.B.count, DATA_CLIENT_PACKET); DemoCS.Leave(); } } else Send (P, net_flags(FALSE)); } } } }; if (OnClient()) return; //------------------------------------------------- while (1) { P.w_begin (M_UPDATE); start = Objects.net_Export (&P, start, max_objects_size); if (P.B.count>2) { Device.Statistic->TEST3.Begin(); Send (P, net_flags(FALSE)); Device.Statistic->TEST3.End(); }else break; } }