aboutsummaryrefslogtreecommitdiff
path: root/etc/lp.lua
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-11-27 07:58:04 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-11-27 07:58:04 +0000
commit7c97e8e40aaa665226fb54449773dc3134e755b2 (patch)
tree47888d4c924fc24bf3b355bf58120ea3cdc74bc4 /etc/lp.lua
parenteb0fc857ddea6f084d338589e2a33d3e7d4eade6 (diff)
downloadluasocket-7c97e8e40aaa665226fb54449773dc3134e755b2.tar.gz
luasocket-7c97e8e40aaa665226fb54449773dc3134e755b2.tar.bz2
luasocket-7c97e8e40aaa665226fb54449773dc3134e755b2.zip
Almost ready for beta3
Diffstat (limited to 'etc/lp.lua')
-rw-r--r--etc/lp.lua23
1 files changed, 14 insertions, 9 deletions
diff --git a/etc/lp.lua b/etc/lp.lua
index b69cc02..a5327d1 100644
--- a/etc/lp.lua
+++ b/etc/lp.lua
@@ -9,9 +9,12 @@
9 if you have any questions: RFC 1179 9 if you have any questions: RFC 1179
10]] 10]]
11-- make sure LuaSocket is loaded 11-- make sure LuaSocket is loaded
12local io = require("io")
13local base = require("base")
14local string = require("string")
12local socket = require("socket") 15local socket = require("socket")
13local ltn12 = require("ltn12") 16local ltn12 = require("ltn12")
14local test = socket.try 17local lp = module("socket.lp")
15 18
16-- default port 19-- default port
17PORT = 515 20PORT = 515
@@ -28,7 +31,7 @@ local function connect(localhost, option)
28 local localport = 721 31 local localport = 721
29 local done, err 32 local done, err
30 repeat 33 repeat
31 skt = test(socket.tcp()) 34 skt = socket.try(socket.tcp())
32 try(skt:settimeout(30)) 35 try(skt:settimeout(30))
33 done, err = skt:bind(localhost, localport) 36 done, err = skt:bind(localhost, localport)
34 if not done then 37 if not done then
@@ -37,8 +40,8 @@ local function connect(localhost, option)
37 skt = nil 40 skt = nil
38 else break end 41 else break end
39 until localport > 731 42 until localport > 731
40 test(skt, err) 43 socket.try(skt, err)
41 else skt = test(socket.tcp()) end 44 else skt = socket.try(socket.tcp()) end
42 try(skt:connect(host, port)) 45 try(skt:connect(host, port))
43 return { skt = skt, try = try } 46 return { skt = skt, try = try }
44end 47end
@@ -241,9 +244,9 @@ local format_codes = {
241-- lp.send 244-- lp.send
242 245
243send = socket.protect(function(file, option) 246send = socket.protect(function(file, option)
244 test(file, "invalid file name") 247 socket.try(file, "invalid file name")
245 test(option and type(option) == "table", "invalid options") 248 socket.try(option and base.type(option) == "table", "invalid options")
246 local fh = test(io.open(file,"rb")) 249 local fh = socket.try(io.open(file,"rb"))
247 local datafile_size = fh:seek("end") -- get total size 250 local datafile_size = fh:seek("end") -- get total size
248 fh:seek("set") -- go back to start of file 251 fh:seek("set") -- go back to start of file
249 local localhost = socket.dns.gethostname() or os.getenv("COMPUTERNAME") 252 local localhost = socket.dns.gethostname() or os.getenv("COMPUTERNAME")
@@ -270,11 +273,11 @@ send = socket.protect(function(file, option)
270 lpfile, 273 lpfile,
271 ctlfn); -- mandatory part of ctl file 274 ctlfn); -- mandatory part of ctl file
272 if (option.banner) then cfile = cfile .. 'L'..user..'\10' end 275 if (option.banner) then cfile = cfile .. 'L'..user..'\10' end
273 if (option.indent) then cfile = cfile .. 'I'..tonumber(option.indent)..'\10' end 276 if (option.indent) then cfile = cfile .. 'I'..base.tonumber(option.indent)..'\10' end
274 if (option.mail) then cfile = cfile .. 'M'..string.sub((option.mail),1,128)..'\10' end 277 if (option.mail) then cfile = cfile .. 'M'..string.sub((option.mail),1,128)..'\10' end
275 if (fmt == 'p' and option.title) then cfile = cfile .. 'T'..string.sub((option.title),1,79)..'\10' end 278 if (fmt == 'p' and option.title) then cfile = cfile .. 'T'..string.sub((option.title),1,79)..'\10' end
276 if ((fmt == 'p' or fmt == 'l' or fmt == 'f') and option.width) then 279 if ((fmt == 'p' or fmt == 'l' or fmt == 'f') and option.width) then
277 cfile = cfile .. 'W'..tonumber(option,width)..'\10' 280 cfile = cfile .. 'W'..base.tonumber(option,width)..'\10'
278 end 281 end
279 282
280 con.skt:settimeout(option.timeout or 65) 283 con.skt:settimeout(option.timeout or 65)
@@ -314,3 +317,5 @@ query = socket.protect(function(p)
314 con.skt:close() 317 con.skt:close()
315 return data 318 return data
316end) 319end)
320
321base.setmetatable(lp, nil)