diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-04-21 05:38:07 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-04-21 05:38:07 +0000 |
| commit | 9596c7f95d3ab990bb741107f7cf94ec5dff3e3b (patch) | |
| tree | a4f014b1a2ab769b7b0d8801e761a6b18a2cd97f | |
| parent | 434e8e014cb21b8d15d512b966ea4f397fd0d369 (diff) | |
| download | luasocket-9596c7f95d3ab990bb741107f7cf94ec5dff3e3b.tar.gz luasocket-9596c7f95d3ab990bb741107f7cf94ec5dff3e3b.tar.bz2 luasocket-9596c7f95d3ab990bb741107f7cf94ec5dff3e3b.zip | |
Bug in forward.lua. Wasn't breaking from the loop.
| -rw-r--r-- | samples/forward.lua | 23 | ||||
| -rw-r--r-- | src/ftp.lua | 4 | ||||
| -rw-r--r-- | src/tcp.c | 3 |
3 files changed, 18 insertions, 12 deletions
diff --git a/samples/forward.lua b/samples/forward.lua index e51c5ce..a53ab5d 100644 --- a/samples/forward.lua +++ b/samples/forward.lua | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | local socket = require"socket" | 2 | local socket = require"socket" |
| 3 | 3 | ||
| 4 | -- creates a new set data structure | 4 | -- creates a new set data structure |
| 5 | function newset() | 5 | function newset(a) |
| 6 | local reverse = {} | 6 | local reverse = {} |
| 7 | local set = {} | 7 | local set = {} |
| 8 | return setmetatable(set, {__index = { | 8 | return setmetatable(set, {__index = { |
| @@ -29,7 +29,7 @@ end | |||
| 29 | -- timeout before an inactive thread is kicked | 29 | -- timeout before an inactive thread is kicked |
| 30 | local TIMEOUT = 10 | 30 | local TIMEOUT = 10 |
| 31 | -- set of connections waiting to receive data | 31 | -- set of connections waiting to receive data |
| 32 | local receiving = newset() | 32 | local receiving = newset(1) |
| 33 | -- set of sockets waiting to send data | 33 | -- set of sockets waiting to send data |
| 34 | local sending = newset() | 34 | local sending = newset() |
| 35 | -- context for connections and servers | 35 | -- context for connections and servers |
| @@ -77,8 +77,8 @@ function connect(who, host, port) | |||
| 77 | wait(who, "output") | 77 | wait(who, "output") |
| 78 | ret, err = who:connect(host, port) | 78 | ret, err = who:connect(host, port) |
| 79 | if not ret and err ~= "already connected" then | 79 | if not ret and err ~= "already connected" then |
| 80 | kick(who) | ||
| 81 | kick(context[who].peer) | 80 | kick(context[who].peer) |
| 81 | kick(who) | ||
| 82 | return | 82 | return |
| 83 | end | 83 | end |
| 84 | end | 84 | end |
| @@ -87,11 +87,11 @@ end | |||
| 87 | 87 | ||
| 88 | -- gets rid of a client | 88 | -- gets rid of a client |
| 89 | function kick(who) | 89 | function kick(who) |
| 90 | if who and context[who] then | 90 | if who then |
| 91 | sending:remove(who) | 91 | sending:remove(who) |
| 92 | receiving:remove(who) | 92 | receiving:remove(who) |
| 93 | context[who] = nil | ||
| 94 | who:close() | 93 | who:close() |
| 94 | context[who] = nil | ||
| 95 | end | 95 | end |
| 96 | end | 96 | end |
| 97 | 97 | ||
| @@ -159,6 +159,7 @@ function forward(who) | |||
| 159 | if not rec_err then | 159 | if not rec_err then |
| 160 | kick(who) | 160 | kick(who) |
| 161 | kick(peer) | 161 | kick(peer) |
| 162 | break | ||
| 162 | end | 163 | end |
| 163 | end | 164 | end |
| 164 | end | 165 | end |
| @@ -171,13 +172,17 @@ function go() | |||
| 171 | readable, writable = socket.select(receiving, sending) | 172 | readable, writable = socket.select(receiving, sending) |
| 172 | -- for all readable connections, resume its thread | 173 | -- for all readable connections, resume its thread |
| 173 | for _, who in ipairs(readable) do | 174 | for _, who in ipairs(readable) do |
| 174 | receiving:remove(who) | 175 | if context[who] then |
| 175 | coroutine.resume(context[who].thread, who) | 176 | receiving:remove(who) |
| 177 | coroutine.resume(context[who].thread, who) | ||
| 178 | end | ||
| 176 | end | 179 | end |
| 177 | -- for all writable connections, do the same | 180 | -- for all writable connections, do the same |
| 178 | for _, who in ipairs(writable) do | 181 | for _, who in ipairs(writable) do |
| 179 | sending:remove(who) | 182 | if context[who] then |
| 180 | coroutine.resume(context[who].thread, who) | 183 | sending:remove(who) |
| 184 | coroutine.resume(context[who].thread, who) | ||
| 185 | end | ||
| 181 | end | 186 | end |
| 182 | -- put all inactive threads in death row | 187 | -- put all inactive threads in death row |
| 183 | local now = socket.gettime() | 188 | local now = socket.gettime() |
diff --git a/src/ftp.lua b/src/ftp.lua index 9b7c1e5..a793298 100644 --- a/src/ftp.lua +++ b/src/ftp.lua | |||
| @@ -105,7 +105,7 @@ function metat.__index:send(sendt) | |||
| 105 | if self.pasvt then self:pasvconnect() end | 105 | if self.pasvt then self:pasvconnect() end |
| 106 | -- get the transfer argument and command | 106 | -- get the transfer argument and command |
| 107 | local argument = sendt.argument or | 107 | local argument = sendt.argument or |
| 108 | url.unescape(string.gsub(sendt.path or "", "^/", "")) | 108 | url.unescape(string.gsub(sendt.path or "", "^[/\\]", "")) |
| 109 | if argument == "" then argument = nil end | 109 | if argument == "" then argument = nil end |
| 110 | local command = sendt.command or "stor" | 110 | local command = sendt.command or "stor" |
| 111 | -- send the transfer command and check the reply | 111 | -- send the transfer command and check the reply |
| @@ -138,7 +138,7 @@ function metat.__index:receive(recvt) | |||
| 138 | self.try(self.pasvt or self.server, "need port or pasv first") | 138 | self.try(self.pasvt or self.server, "need port or pasv first") |
| 139 | if self.pasvt then self:pasvconnect() end | 139 | if self.pasvt then self:pasvconnect() end |
| 140 | local argument = recvt.argument or | 140 | local argument = recvt.argument or |
| 141 | url.unescape(string.gsub(recvt.path or "", "^/", "")) | 141 | url.unescape(string.gsub(recvt.path or "", "^[/\\]", "")) |
| 142 | if argument == "" then argument = nil end | 142 | if argument == "" then argument = nil end |
| 143 | local command = recvt.command or "retr" | 143 | local command = recvt.command or "retr" |
| 144 | self.try(self.tp:command(command, argument)) | 144 | self.try(self.tp:command(command, argument)) |
| @@ -213,13 +213,14 @@ static int meth_connect(lua_State *L) | |||
| 213 | unsigned short port = (unsigned short) luaL_checknumber(L, 3); | 213 | unsigned short port = (unsigned short) luaL_checknumber(L, 3); |
| 214 | p_tm tm = tm_markstart(&tcp->tm); | 214 | p_tm tm = tm_markstart(&tcp->tm); |
| 215 | const char *err = inet_tryconnect(&tcp->sock, address, port, tm); | 215 | const char *err = inet_tryconnect(&tcp->sock, address, port, tm); |
| 216 | /* have to set the class even if it failed due to non-blocking connects */ | ||
| 217 | aux_setclass(L, "tcp{client}", 1); | ||
| 216 | if (err) { | 218 | if (err) { |
| 217 | lua_pushnil(L); | 219 | lua_pushnil(L); |
| 218 | lua_pushstring(L, err); | 220 | lua_pushstring(L, err); |
| 219 | return 2; | 221 | return 2; |
| 220 | } | 222 | } |
| 221 | /* turn master object into a client object */ | 223 | /* turn master object into a client object */ |
| 222 | aux_setclass(L, "tcp{client}", 1); | ||
| 223 | lua_pushnumber(L, 1); | 224 | lua_pushnumber(L, 1); |
| 224 | return 1; | 225 | return 1; |
| 225 | } | 226 | } |
