@@ -484,24 +484,32 @@ bool Countly::updateSession() {
484484 auto duration = std::chrono::duration_cast<std::chrono::seconds>(getSessionDuration ());
485485 mutex.lock ();
486486
487- if (!no_events) {
488- std::map<std::string, std::string> data = {
489- {" app_key" , session_params[" app_key" ].get <std::string>()},
490- {" device_id" , session_params[" device_id" ].get <std::string>()},
491- {" events" , events.dump ()}
492- };
487+ if (no_events) {
488+ if (duration.count () > COUNTLY_KEEPALIVE_INTERVAL) {
489+ std::map<std::string, std::string> data = {
490+ {" app_key" , session_params[" app_key" ].get <std::string>()},
491+ {" device_id" , session_params[" device_id" ].get <std::string>()},
492+ {" session_duration" , std::to_string (duration.count ())}
493+ };
494+ if (!sendHTTP (" /i" , Countly::serializeForm (data)).success ) {
495+ mutex.unlock ();
496+ return false ;
497+ }
493498
494- if (!sendHTTP (" /i" , Countly::serializeForm (data)).success ) {
495- mutex.unlock ();
496- return false ;
499+ last_sent += duration;
497500 }
501+
502+ mutex.unlock ();
503+ return true ;
498504 }
499505
500506 std::map<std::string, std::string> data = {
501- {" app_key" , session_params[" app_key" ].get <std::string>()},
502- {" device_id" , session_params[" device_id" ].get <std::string>()},
503- {" session_duration" , std::to_string (duration.count ())}
507+ {" app_key" , session_params[" app_key" ].get <std::string>()},
508+ {" device_id" , session_params[" device_id" ].get <std::string>()},
509+ {" session_duration" , std::to_string (duration.count ())},
510+ {" events" , events.dump ()}
504511 };
512+
505513 if (!sendHTTP (" /i" , Countly::serializeForm (data)).success ) {
506514 mutex.unlock ();
507515 return false ;
@@ -819,8 +827,9 @@ void Countly::updateLoop() {
819827 }
820828 size_t last_wait_milliseconds = wait_milliseconds;
821829 mutex.unlock ();
822- std::this_thread::sleep_for (std::chrono::milliseconds (last_wait_milliseconds));
823830 updateSession ();
831+ std::this_thread::sleep_for (std::chrono::milliseconds (last_wait_milliseconds));
832+
824833 }
825834 mutex.lock ();
826835 running = false ;
0 commit comments