From b59bf13125a79a38b9280d3c8b744948443bffa8 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Fri, 12 Dec 2014 16:43:14 +0100 Subject: [PATCH] MT#10601 dlgcnt: remove central counters when it reaches to 0 Change-Id: I67c4339b90fe5862b41b01ca4b3d5352a11e39b4 --- ngcp/dlgcnt.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ngcp/dlgcnt.lua b/ngcp/dlgcnt.lua index da9e5a5..4a013c5 100644 --- a/ngcp/dlgcnt.lua +++ b/ngcp/dlgcnt.lua @@ -74,6 +74,17 @@ end return client; end + function NGCPDlgCounters._decr(self, key) + local res = self.central:decr(key); + if res == 0 then + self.central:del(key); + sr.log("dbg", string.format("central:del[%s] counter is 0\n", key)); + else + sr.log("dbg", string.format("central:decr[%s]=>[%s]\n", key, tostring(res))); + end + return res; + end + function NGCPDlgCounters:set(callid, key) if not self._test_connection(self.central) then self.central = self._connect(self.config.central); @@ -96,8 +107,7 @@ end if not self._test_connection(self.central) then self.central = self._connect(self.config.central); end - local res = self.central:decr(key); - sr.log("dbg", string.format("central:decr[%s]=>[%s]\n", key, tostring(res))); + self:_decr(key); end function NGCPDlgCounters:del(callid) @@ -111,10 +121,8 @@ end if not self._test_connection(self.central) then self.central = self._connect(self.config.central); end - local res; while key do - res = self.central:decr(key); - sr.log("dbg", string.format("central:decr[%s]=>[%s]\n", key, tostring(res))); + self:_decr(key); sr.log("dbg", string.format("pair:lpop[%s]=>[%s]\n", callid, key)); key = self.pair:lpop(callid); end