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"
|
||||
|
||||
-- creates a new set data structure
|
||||
function newset()
|
||||
function newset(a)
|
||||
local reverse = {}
|
||||
local set = {}
|
||||
return setmetatable(set, {__index = {
|
||||
@ -29,7 +29,7 @@ end
|
||||
-- timeout before an inactive thread is kicked
|
||||
local TIMEOUT = 10
|
||||
-- set of connections waiting to receive data
|
||||
local receiving = newset()
|
||||
local receiving = newset(1)
|
||||
-- set of sockets waiting to send data
|
||||
local sending = newset()
|
||||
-- context for connections and servers
|
||||
@ -77,8 +77,8 @@ function connect(who, host, port)
|
||||
wait(who, "output")
|
||||
ret, err = who:connect(host, port)
|
||||
if not ret and err ~= "already connected" then
|
||||
kick(who)
|
||||
kick(context[who].peer)
|
||||
kick(who)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -87,11 +87,11 @@ end
|
||||
|
||||
-- gets rid of a client
|
||||
function kick(who)
|
||||
if who and context[who] then
|
||||
if who then
|
||||
sending:remove(who)
|
||||
receiving:remove(who)
|
||||
context[who] = nil
|
||||
who:close()
|
||||
context[who] = nil
|
||||
end
|
||||
end
|
||||
|
||||
@ -159,6 +159,7 @@ function forward(who)
|
||||
if not rec_err then
|
||||
kick(who)
|
||||
kick(peer)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -171,14 +172,18 @@ function go()
|
||||
readable, writable = socket.select(receiving, sending)
|
||||
-- for all readable connections, resume its thread
|
||||
for _, who in ipairs(readable) do
|
||||
if context[who] then
|
||||
receiving:remove(who)
|
||||
coroutine.resume(context[who].thread, who)
|
||||
end
|
||||
end
|
||||
-- for all writable connections, do the same
|
||||
for _, who in ipairs(writable) do
|
||||
if context[who] then
|
||||
sending:remove(who)
|
||||
coroutine.resume(context[who].thread, who)
|
||||
end
|
||||
end
|
||||
-- put all inactive threads in death row
|
||||
local now = socket.gettime()
|
||||
local deathrow
|
||||
|
@ -105,7 +105,7 @@ function metat.__index:send(sendt)
|
||||
if self.pasvt then self:pasvconnect() end
|
||||
-- get the transfer argument and command
|
||||
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
|
||||
local command = sendt.command or "stor"
|
||||
-- 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")
|
||||
if self.pasvt then self:pasvconnect() end
|
||||
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
|
||||
local command = recvt.command or "retr"
|
||||
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);
|
||||
p_tm tm = tm_markstart(&tcp->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) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, err);
|
||||
return 2;
|
||||
}
|
||||
/* turn master object into a client object */
|
||||
aux_setclass(L, "tcp{client}", 1);
|
||||
lua_pushnumber(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user