diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-07-02 23:47:52 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-07-02 23:47:52 +0000 |
commit | 471334c3d07f398e4b0859c43276341a28b91504 (patch) | |
tree | ff1894b013b093280b0878d16f1c827da85a3ea9 | |
parent | c3e0063b430beba5d7e6911c8f59fd37b8017e61 (diff) | |
download | luasocket-471334c3d07f398e4b0859c43276341a28b91504.tar.gz luasocket-471334c3d07f398e4b0859c43276341a28b91504.tar.bz2 luasocket-471334c3d07f398e4b0859c43276341a28b91504.zip |
Fixed stupid bugs.
-rw-r--r-- | etc/lp.lua | 4 | ||||
-rw-r--r-- | samples/lpr.lua | 10 |
2 files changed, 7 insertions, 7 deletions
@@ -26,10 +26,11 @@ local function connect(localhost, option) | |||
26 | if option.localbind then | 26 | if option.localbind then |
27 | -- bind to a local port (if we can) | 27 | -- bind to a local port (if we can) |
28 | local localport = 721 | 28 | local localport = 721 |
29 | local done, err | ||
29 | repeat | 30 | repeat |
30 | skt = test(socket.tcp()) | 31 | skt = test(socket.tcp()) |
31 | try(skt:settimeout(30)) | 32 | try(skt:settimeout(30)) |
32 | local done, err = skt:bind(localhost, localport) | 33 | done, err = skt:bind(localhost, localport) |
33 | if not done then | 34 | if not done then |
34 | localport = localport + 1 | 35 | localport = localport + 1 |
35 | skt:close() | 36 | skt:close() |
@@ -38,6 +39,7 @@ local function connect(localhost, option) | |||
38 | until localport > 731 | 39 | until localport > 731 |
39 | test(skt, err) | 40 | test(skt, err) |
40 | else skt = test(socket.tcp()) end | 41 | else skt = test(socket.tcp()) end |
42 | print("'" .. host .. "'") | ||
41 | try(skt:connect(host, port)) | 43 | try(skt:connect(host, port)) |
42 | return { skt = skt, try = try } | 44 | return { skt = skt, try = try } |
43 | end | 45 | end |
diff --git a/samples/lpr.lua b/samples/lpr.lua index c23ebee..d743026 100644 --- a/samples/lpr.lua +++ b/samples/lpr.lua | |||
@@ -27,16 +27,14 @@ if not arg or not arg[1] then | |||
27 | end | 27 | end |
28 | 28 | ||
29 | do | 29 | do |
30 | local s="opt = {" | 30 | local opt = {} |
31 | for i = 2 , table.getn(arg), 1 do | 31 | local pat = "[%s%c%p]*([%w]*)=([\"]?[%w%s_!@#$%%^&*()<>:;]+[\"]\?\.?)" |
32 | s = s .. string.gsub(arg[i],"[%s%c%p]*([%w]*)=([\"]?[%w%s_!@#$%%^&*()<>:;]+[\"]\?\.?)","%1%=\"%2\",\n") | 32 | for i = 2, table.getn(arg), 1 do |
33 | string.gsub(arg[i], pat, function(name, value) opt[name] = value end) | ||
33 | end | 34 | end |
34 | s = s .. "};\n" | ||
35 | assert(loadstring(s))(); | ||
36 | if not arg[2] then | 35 | if not arg[2] then |
37 | return usage() | 36 | return usage() |
38 | end | 37 | end |
39 | |||
40 | if arg[1] ~= "query" then | 38 | if arg[1] ~= "query" then |
41 | r,e=lp.send(arg[1],opt) | 39 | r,e=lp.send(arg[1],opt) |
42 | io.stdout:write(tostring(r or e),'\n') | 40 | io.stdout:write(tostring(r or e),'\n') |