diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2007-03-12 04:08:40 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2007-03-12 04:08:40 +0000 |
commit | be2e467929be9f27fbe92fe7b94783635c920c06 (patch) | |
tree | 94054e38f33178d805a6144d3bd9cb76da4a4c76 /etc | |
parent | 8bf9fb51dd09fb066483247fccbfc979acc84071 (diff) | |
download | luasocket-be2e467929be9f27fbe92fe7b94783635c920c06.tar.gz luasocket-be2e467929be9f27fbe92fe7b94783635c920c06.tar.bz2 luasocket-be2e467929be9f27fbe92fe7b94783635c920c06.zip |
Couple bug fixes.
Diffstat (limited to 'etc')
-rw-r--r-- | etc/get.lua | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/etc/get.lua b/etc/get.lua index ebf3e75..09f639d 100644 --- a/etc/get.lua +++ b/etc/get.lua | |||
@@ -65,21 +65,23 @@ end | |||
65 | -- kind of copied from luasocket's manual callback examples | 65 | -- kind of copied from luasocket's manual callback examples |
66 | function stats(size) | 66 | function stats(size) |
67 | local start = socket.gettime() | 67 | local start = socket.gettime() |
68 | local last = start | ||
68 | local got = 0 | 69 | local got = 0 |
69 | return function(chunk) | 70 | return function(chunk) |
70 | -- elapsed time since start | 71 | -- elapsed time since start |
71 | local delta = socket.gettime() - start | 72 | local current = socket.gettime() |
72 | if chunk then | 73 | if chunk then |
73 | -- total bytes received | 74 | -- total bytes received |
74 | got = got + string.len(chunk) | 75 | got = got + string.len(chunk) |
75 | -- not enough time for estimate | 76 | -- not enough time for estimate |
76 | if delta > 0.1 then | 77 | if current - last > 1 then |
77 | io.stderr:write("\r", gauge(got, delta, size)) | 78 | io.stderr:write("\r", gauge(got, current - start, size)) |
78 | io.stderr:flush() | 79 | io.stderr:flush() |
80 | last = current | ||
79 | end | 81 | end |
80 | else | 82 | else |
81 | -- close up | 83 | -- close up |
82 | io.stderr:write("\r", gauge(got, delta), "\n") | 84 | io.stderr:write("\r", gauge(got, current - start), "\n") |
83 | end | 85 | end |
84 | return chunk | 86 | return chunk |
85 | end | 87 | end |