From 313e588e7e1173d7666b03a722e122ca10056998 Mon Sep 17 00:00:00 2001 From: Mons Anderson Date: Fri, 20 Mar 2015 04:10:55 +0300 Subject: [PATCH] gr fix --- gr.lua | 31 ++++++++++++++++++------------- gr/udp.lua | 4 ++++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/gr.lua b/gr.lua index bc30410..6ae251e 100644 --- a/gr.lua +++ b/gr.lua @@ -9,15 +9,21 @@ local old = rawget(_G,K) if old then -- todo signal old to shutdown - + for k,i in pairs(old) do + if type(i) == 'table' then + print("got key ",k," ",old[k]) + if i._c and i._c.fihish then + i._c:finish() + end + end + end end local function new ( name ) return { - name = name, - ok = false, - c = false, - warned = false, + _name = name, + _c = false, + _warned = false, } end @@ -27,27 +33,26 @@ local M = new('main') function M:config(host,port,proto) assert(type(self) == 'table', "Static call prohibited") - print("called on ",self," name=",self.name," param = ",param) if proto == 'tcp' then local cnn = tcp(host,port) - self.c = cnn + self._c = cnn elseif proto == 'udp' then local cnn = udp(host,port) - self.c = cnn + self._c = cnn else error("Bad protocol "..proto, 2) end end function M:send(key,value) - if not self.c then - if not self.warned then - self.warned = true - log._log( log.WARN, "Instance `%s' not configured prematurely", self.name ) + if not self._c then + if not self._warned then + self._warned = true + log._log( log.WARN, "Instance `%s' not configured prematurely", self._name ) end return end - self.c:send(key, value) + self._c:send(key, value) end setmetatable(M,{ diff --git a/gr/udp.lua b/gr/udp.lua index 18faef6..00eb373 100644 --- a/gr/udp.lua +++ b/gr/udp.lua @@ -7,6 +7,10 @@ setmetatable(M,{ __call = function(t,...) return t:new(...) end, }) +function M:finish() + +end + function M.new(class, host, port, opts) local self = setmetatable({},class)