diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-22 08:33:29 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-22 08:33:29 +0000 |
| commit | d55a5826e81136a9ecf65c4cd407152a56684dc2 (patch) | |
| tree | 109ad44c75cee890ad5e98583e12b15b5e65a18e /etc/tftp.lua | |
| parent | a2b780bf7a78c66d54a248fa99b5fc862c12a127 (diff) | |
| download | luasocket-d55a5826e81136a9ecf65c4cd407152a56684dc2.tar.gz luasocket-d55a5826e81136a9ecf65c4cd407152a56684dc2.tar.bz2 luasocket-d55a5826e81136a9ecf65c4cd407152a56684dc2.zip | |
Few tweaks in installation, some missing files, etc.
Diffstat (limited to 'etc/tftp.lua')
| -rw-r--r-- | etc/tftp.lua | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/etc/tftp.lua b/etc/tftp.lua index 1b589fb..c028b20 100644 --- a/etc/tftp.lua +++ b/etc/tftp.lua | |||
| @@ -46,7 +46,7 @@ local function ACK(block) | |||
| 46 | local low, high | 46 | local low, high |
| 47 | low = math.mod(block, 256) | 47 | low = math.mod(block, 256) |
| 48 | high = (block - low)/256 | 48 | high = (block - low)/256 |
| 49 | return char(0, OP_ACK, high, low) | 49 | return char(0, OP_ACK, high, low) |
| 50 | end | 50 | end |
| 51 | 51 | ||
| 52 | local function get_OP(dgram) | 52 | local function get_OP(dgram) |
| @@ -71,7 +71,7 @@ local function get_ERROR(dgram) | |||
| 71 | end | 71 | end |
| 72 | 72 | ||
| 73 | ----------------------------------------------------------------------------- | 73 | ----------------------------------------------------------------------------- |
| 74 | -- The real work | 74 | -- The real work |
| 75 | ----------------------------------------------------------------------------- | 75 | ----------------------------------------------------------------------------- |
| 76 | local function tget(gett) | 76 | local function tget(gett) |
| 77 | local retries, dgram, sent, datahost, dataport, code | 77 | local retries, dgram, sent, datahost, dataport, code |
| @@ -83,15 +83,15 @@ local function tget(gett) | |||
| 83 | gett.host = try(socket.dns.toip(gett.host)) | 83 | gett.host = try(socket.dns.toip(gett.host)) |
| 84 | con:settimeout(1) | 84 | con:settimeout(1) |
| 85 | -- first packet gives data host/port to be used for data transfers | 85 | -- first packet gives data host/port to be used for data transfers |
| 86 | local path = string.gsub(gett.path or "", "^/", "") | 86 | local path = string.gsub(gett.path or "", "^/", "") |
| 87 | path = url.unescape(path) | 87 | path = url.unescape(path) |
| 88 | retries = 0 | 88 | retries = 0 |
| 89 | repeat | 89 | repeat |
| 90 | sent = try(con:sendto(RRQ(path, "octet"), gett.host, gett.port)) | 90 | sent = try(con:sendto(RRQ(path, "octet"), gett.host, gett.port)) |
| 91 | dgram, datahost, dataport = con:receivefrom() | 91 | dgram, datahost, dataport = con:receivefrom() |
| 92 | retries = retries + 1 | 92 | retries = retries + 1 |
| 93 | until dgram or datahost ~= "timeout" or retries > 5 | 93 | until dgram or datahost ~= "timeout" or retries > 5 |
| 94 | try(dgram, datahost) | 94 | try(dgram, datahost) |
| 95 | -- associate socket with data host/port | 95 | -- associate socket with data host/port |
| 96 | try(con:setpeername(datahost, dataport)) | 96 | try(con:setpeername(datahost, dataport)) |
| 97 | -- default sink | 97 | -- default sink |
| @@ -110,7 +110,7 @@ local function tget(gett) | |||
| 110 | last = block | 110 | last = block |
| 111 | end | 111 | end |
| 112 | -- last packet brings less than 512 bytes of data | 112 | -- last packet brings less than 512 bytes of data |
| 113 | if string.len(data) < 512 then | 113 | if string.len(data) < 512 then |
| 114 | try(con:send(ACK(block))) | 114 | try(con:send(ACK(block))) |
| 115 | try(con:close()) | 115 | try(con:close()) |
| 116 | try(sink(nil)) | 116 | try(sink(nil)) |
| @@ -118,7 +118,7 @@ local function tget(gett) | |||
| 118 | end | 118 | end |
| 119 | -- get the next packet | 119 | -- get the next packet |
| 120 | retries = 0 | 120 | retries = 0 |
| 121 | repeat | 121 | repeat |
| 122 | sent = try(con:send(ACK(last))) | 122 | sent = try(con:send(ACK(last))) |
| 123 | dgram, err = con:receive() | 123 | dgram, err = con:receive() |
| 124 | retries = retries + 1 | 124 | retries = retries + 1 |
| @@ -141,7 +141,7 @@ local function parse(u) | |||
| 141 | end | 141 | end |
| 142 | 142 | ||
| 143 | local function sget(u) | 143 | local function sget(u) |
| 144 | local gett = parse(u) | 144 | local gett = parse(u) |
| 145 | local t = {} | 145 | local t = {} |
| 146 | gett.sink = ltn12.sink.table(t) | 146 | gett.sink = ltn12.sink.table(t) |
| 147 | tget(gett) | 147 | tget(gett) |
