mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-26 04:28:20 +01:00
Bug in forward.lua. Wasn't breaking from the loop.
This commit is contained in:
parent
434e8e014c
commit
9596c7f95d
@ -2,7 +2,7 @@
|
|||||||
local socket = require"socket"
|
local socket = require"socket"
|
||||||
|
|
||||||
-- creates a new set data structure
|
-- creates a new set data structure
|
||||||
function newset()
|
function newset(a)
|
||||||
local reverse = {}
|
local reverse = {}
|
||||||
local set = {}
|
local set = {}
|
||||||
return setmetatable(set, {__index = {
|
return setmetatable(set, {__index = {
|
||||||
@ -29,7 +29,7 @@ end
|
|||||||
-- timeout before an inactive thread is kicked
|
-- timeout before an inactive thread is kicked
|
||||||
local TIMEOUT = 10
|
local TIMEOUT = 10
|
||||||
-- set of connections waiting to receive data
|
-- set of connections waiting to receive data
|
||||||
local receiving = newset()
|
local receiving = newset(1)
|
||||||
-- set of sockets waiting to send data
|
-- set of sockets waiting to send data
|
||||||
local sending = newset()
|
local sending = newset()
|
||||||
-- context for connections and servers
|
-- context for connections and servers
|
||||||
@ -77,8 +77,8 @@ function connect(who, host, port)
|
|||||||
wait(who, "output")
|
wait(who, "output")
|
||||||
ret, err = who:connect(host, port)
|
ret, err = who:connect(host, port)
|
||||||
if not ret and err ~= "already connected" then
|
if not ret and err ~= "already connected" then
|
||||||
kick(who)
|
|
||||||
kick(context[who].peer)
|
kick(context[who].peer)
|
||||||
|
kick(who)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -87,11 +87,11 @@ end
|
|||||||
|
|
||||||
-- gets rid of a client
|
-- gets rid of a client
|
||||||
function kick(who)
|
function kick(who)
|
||||||
if who and context[who] then
|
if who then
|
||||||
sending:remove(who)
|
sending:remove(who)
|
||||||
receiving:remove(who)
|
receiving:remove(who)
|
||||||
context[who] = nil
|
|
||||||
who:close()
|
who:close()
|
||||||
|
context[who] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -159,6 +159,7 @@ function forward(who)
|
|||||||
if not rec_err then
|
if not rec_err then
|
||||||
kick(who)
|
kick(who)
|
||||||
kick(peer)
|
kick(peer)
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -171,13 +172,17 @@ function go()
|
|||||||
readable, writable = socket.select(receiving, sending)
|
readable, writable = socket.select(receiving, sending)
|
||||||
-- for all readable connections, resume its thread
|
-- for all readable connections, resume its thread
|
||||||
for _, who in ipairs(readable) do
|
for _, who in ipairs(readable) do
|
||||||
receiving:remove(who)
|
if context[who] then
|
||||||
coroutine.resume(context[who].thread, who)
|
receiving:remove(who)
|
||||||
|
coroutine.resume(context[who].thread, who)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
-- for all writable connections, do the same
|
-- for all writable connections, do the same
|
||||||
for _, who in ipairs(writable) do
|
for _, who in ipairs(writable) do
|
||||||
sending:remove(who)
|
if context[who] then
|
||||||
coroutine.resume(context[who].thread, who)
|
sending:remove(who)
|
||||||
|
coroutine.resume(context[who].thread, who)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
-- put all inactive threads in death row
|
-- put all inactive threads in death row
|
||||||
local now = socket.gettime()
|
local now = socket.gettime()
|
||||||
|
@ -105,7 +105,7 @@ function metat.__index:send(sendt)
|
|||||||
if self.pasvt then self:pasvconnect() end
|
if self.pasvt then self:pasvconnect() end
|
||||||
-- get the transfer argument and command
|
-- get the transfer argument and command
|
||||||
local argument = sendt.argument or
|
local argument = sendt.argument or
|
||||||
url.unescape(string.gsub(sendt.path or "", "^/", ""))
|
url.unescape(string.gsub(sendt.path or "", "^[/\\]", ""))
|
||||||
if argument == "" then argument = nil end
|
if argument == "" then argument = nil end
|
||||||
local command = sendt.command or "stor"
|
local command = sendt.command or "stor"
|
||||||
-- send the transfer command and check the reply
|
-- send the transfer command and check the reply
|
||||||
@ -138,7 +138,7 @@ function metat.__index:receive(recvt)
|
|||||||
self.try(self.pasvt or self.server, "need port or pasv first")
|
self.try(self.pasvt or self.server, "need port or pasv first")
|
||||||
if self.pasvt then self:pasvconnect() end
|
if self.pasvt then self:pasvconnect() end
|
||||||
local argument = recvt.argument or
|
local argument = recvt.argument or
|
||||||
url.unescape(string.gsub(recvt.path or "", "^/", ""))
|
url.unescape(string.gsub(recvt.path or "", "^[/\\]", ""))
|
||||||
if argument == "" then argument = nil end
|
if argument == "" then argument = nil end
|
||||||
local command = recvt.command or "retr"
|
local command = recvt.command or "retr"
|
||||||
self.try(self.tp:command(command, argument))
|
self.try(self.tp:command(command, argument))
|
||||||
|
@ -213,13 +213,14 @@ static int meth_connect(lua_State *L)
|
|||||||
unsigned short port = (unsigned short) luaL_checknumber(L, 3);
|
unsigned short port = (unsigned short) luaL_checknumber(L, 3);
|
||||||
p_tm tm = tm_markstart(&tcp->tm);
|
p_tm tm = tm_markstart(&tcp->tm);
|
||||||
const char *err = inet_tryconnect(&tcp->sock, address, port, tm);
|
const char *err = inet_tryconnect(&tcp->sock, address, port, tm);
|
||||||
|
/* have to set the class even if it failed due to non-blocking connects */
|
||||||
|
aux_setclass(L, "tcp{client}", 1);
|
||||||
if (err) {
|
if (err) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_pushstring(L, err);
|
lua_pushstring(L, err);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
/* turn master object into a client object */
|
/* turn master object into a client object */
|
||||||
aux_setclass(L, "tcp{client}", 1);
|
|
||||||
lua_pushnumber(L, 1);
|
lua_pushnumber(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user