mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-11-08 06:18:21 +01:00
Better connection handling.
This commit is contained in:
parent
4e3cf63c95
commit
434e8e014c
3
TODO
3
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.
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user