Skip to content

Commit

Permalink
gr fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mons committed Mar 20, 2015
1 parent a82207a commit 313e588
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
31 changes: 18 additions & 13 deletions gr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,{
Expand Down
4 changes: 4 additions & 0 deletions gr/udp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 313e588

Please sign in to comment.