Better connection handling.

This commit is contained in:
Diego Nehab 2005-04-21 03:15:34 +00:00
parent 4e3cf63c95
commit 434e8e014c
4 changed files with 26 additions and 16 deletions

3
TODO
View File

@ -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.

View File

@ -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

View File

@ -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 = {
return setmetatable(set, {__index = {
insert = function(set, value)
table.insert(set, value)
reverse[value] = table.getn(set)
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()

View File

@ -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);