diff --git a/TODO b/TODO index 19c9319..460165f 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,4 @@ -BUG NO SET DO TINYIRC!!! SINISTRO. talk about the non-blocking connect in the manual test it on Windows!!! @@ -41,3 +40,5 @@ testar os options! - inet_ntoa também é uma merda. eliminate globals from namespaces created by module(). + +* BUG NO SET DO TINYIRC!!! SINISTRO. diff --git a/samples/forward.lua b/samples/forward.lua index ff65b84..e51c5ce 100644 --- a/samples/forward.lua +++ b/samples/forward.lua @@ -76,13 +76,13 @@ function connect(who, host, port) if not ret and err == "timeout" then wait(who, "output") ret, err = who:connect(host, port) + if not ret and err ~= "already connected" then + kick(who) + kick(context[who].peer) + return + end end - if not ret then - kick(who) - kick(context[who].peer) - else - return forward(who) - end + return forward(who) end -- gets rid of a client diff --git a/samples/tinyirc.lua b/samples/tinyirc.lua index 684e7c0..e3dd517 100644 --- a/samples/tinyirc.lua +++ b/samples/tinyirc.lua @@ -24,20 +24,29 @@ io.write("Servers bound\n") -- simple set implementation -- the select function doesn't care about what is passed to it as long as -- it behaves like a table +-- creates a new set data structure function newset() local reverse = {} local set = {} - setmetatable(set, { __index = { - insert = function(set, value) - table.insert(set, value) - reverse[value] = table.getn(set) + return setmetatable(set, {__index = { + insert = function(set, value) + if not reverse[value] then + table.insert(set, value) + reverse[value] = table.getn(set) + end end, remove = function(set, value) - table.remove(set, reverse[value]) - reverse[value] = nil - end, + local index = reverse[value] + if index then + reverse[value] = nil + local top = table.remove(set) + if top ~= value then + reverse[top] = index + set[index] = top + end + end + end }}) - return set end set = newset() diff --git a/src/tcp.c b/src/tcp.c index e4b1375..eb84997 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -208,7 +208,7 @@ static int meth_bind(lua_State *L) \*-------------------------------------------------------------------------*/ static int meth_connect(lua_State *L) { - p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{master}", 1); + p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{any}", 1); const char *address = luaL_checkstring(L, 2); unsigned short port = (unsigned short) luaL_checknumber(L, 3); p_tm tm = tm_markstart(&tcp->tm);