From 8ef84c5d0813096c4cc6cd05e3f213118ba8a33b Mon Sep 17 00:00:00 2001 From: Matteo Nastasi Date: Sun, 5 Aug 2012 07:37:22 +0200 Subject: [PATCH] app level keepalive (new ping message) added --- web/Obj/sac-a-push.phh | 10 +++++++++- web/Obj/user.phh | 9 +++++++++ web/briskin5/index_wr.php | 7 +++++-- web/commons.js | 5 +++++ web/index_wr.php | 5 ++++- 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/web/Obj/sac-a-push.phh b/web/Obj/sac-a-push.phh index bc0ea87..4a325da 100644 --- a/web/Obj/sac-a-push.phh +++ b/web/Obj/sac-a-push.phh @@ -404,10 +404,18 @@ class Sac_a_push { if (isset($this->s2u[intval($sock)])) { $user = $this->s2u[intval($sock)]; $response = $user->rd_cache_get(); + if (($this->curtime - $user->lacc) <= (EXPIRE_TIME_RD / 2)) { + $user->ping_req = FALSE; + } if ($response == "") { $content = ""; $user->stream_main($content, $get, $post, $cookie); - + printf("[%s] [%d] [%d]\n", $user->name, $user->lacc, $this->curtime); + if ($content == "" && $user->ping_req == FALSE + && (($this->curtime - $user->lacc) > (EXPIRE_TIME_RD / 2))) { + $content = $user->stream_ping(); + $user->ping_req = TRUE; + } if ($content == "" && $user->rd_kalive_is_expired($this->curtime)) { $content = $user->stream_keepalive(); } diff --git a/web/Obj/user.phh b/web/Obj/user.phh index e94b4aa..b13f56e 100644 --- a/web/Obj/user.phh +++ b/web/Obj/user.phh @@ -941,6 +941,15 @@ push(null); // --> ", $this->rd_scristp++)); +} + +function stream_ping() +{ + return (sprintf("", $this->rd_scristp++)); + } static function base_get() diff --git a/web/briskin5/index_wr.php b/web/briskin5/index_wr.php index d865972..fbc37c5 100644 --- a/web/briskin5/index_wr.php +++ b/web/briskin5/index_wr.php @@ -42,6 +42,7 @@ function bin5_index_wr_main(&$bri, $remote_addr, $get, $post, $cookie) { GLOBAL $G_base, $G_dbasetype; + $curtime = time(); if ($bri == NULL) { return FALSE; } @@ -73,7 +74,10 @@ function bin5_index_wr_main(&$bri, $remote_addr, $get, $post, $cookie) log_wr('POSTSPLIT: '.$argz[0].' user->stat: ['.$user->stat.']'); log_wr($user->step, 'bin::index_wr.php: after get_user()'); - if (false && $argz[0] == 'shutdown') { + if ($argz[0] == 'ping') { + $user->lacc = $curtime; + } + else if (false && $argz[0] == 'shutdown') { log_auth($user_cur->sess, "Shutdown session. delegate to room gc the autologout"); log_rd2("bin5/index_wr.php: AUTO LOGOUT."); @@ -481,7 +485,6 @@ function bin5_index_wr_main(&$bri, $remote_addr, $get, $post, $cookie) $pt_cur = calculate_points(&$table); $plist = "$table->table_token|$user->table_orig|$table->player_n"; - $curtime = time(); $ucodes = array(); for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) { $user_cur = &$bri->user[$table->player[$i]]; diff --git a/web/commons.js b/web/commons.js index 94de832..f0ea078 100644 --- a/web/commons.js +++ b/web/commons.js @@ -329,6 +329,11 @@ function act_chatt(value) } /* Stat: ROOM */ +function act_ping() +{ + send_mesg("ping"); +} + function act_sitdown(table) { send_mesg("sitdown|"+table); diff --git a/web/index_wr.php b/web/index_wr.php index 99213b7..6995a18 100644 --- a/web/index_wr.php +++ b/web/index_wr.php @@ -199,7 +199,10 @@ function index_wr_main(&$room, $remote_addr, $get, $post, $cookie) log_wr($user->step, 'index_wr.php: after get_user()'); - if ($argz[0] == 'shutdown') { + if ($argz[0] == 'ping') { + $user->lacc = $curtime; + } + else if ($argz[0] == 'shutdown') { log_auth($user->sess, "Shutdown session."); $user->reset(); -- 2.17.1