diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2002-12-03 07:20:34 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2002-12-03 07:20:34 +0000 |
| commit | 7da19138e37c4e0123860f1fecbceb80c3d2627d (patch) | |
| tree | 8453f003a9ba212807d9c9590c2f2b850d323f0f | |
| parent | d7e80592a69c076991ed4f4cc15d5390e14d1f0b (diff) | |
| download | luasocket-7da19138e37c4e0123860f1fecbceb80c3d2627d.tar.gz luasocket-7da19138e37c4e0123860f1fecbceb80c3d2627d.tar.bz2 luasocket-7da19138e37c4e0123860f1fecbceb80c3d2627d.zip | |
Faltam testes de ftp e smtp. O resto passa.
| -rw-r--r-- | src/buffer.c | 4 | ||||
| -rw-r--r-- | src/http.lua | 6 | ||||
| -rw-r--r-- | src/select.c | 2 | ||||
| -rw-r--r-- | src/timeout.c | 6 | ||||
| -rw-r--r-- | src/url.lua | 6 | ||||
| -rw-r--r-- | test/httptest.lua | 88 | ||||
| -rw-r--r-- | test/testclnt.lua | 169 | ||||
| -rw-r--r-- | test/testsrvr.lua | 6 | ||||
| -rw-r--r-- | test/urltest.lua | 2 |
9 files changed, 141 insertions, 148 deletions
diff --git a/src/buffer.c b/src/buffer.c index a9a9782..4260f20 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -74,7 +74,7 @@ int buf_send(lua_State *L, p_buf buf) | |||
| 74 | } | 74 | } |
| 75 | priv_pusherror(L, err); | 75 | priv_pusherror(L, err); |
| 76 | lua_pushnumber(L, total); | 76 | lua_pushnumber(L, total); |
| 77 | #ifdef _DEBUG | 77 | #ifdef LUASOCKET_DEBUG |
| 78 | /* push time elapsed during operation as the last return value */ | 78 | /* push time elapsed during operation as the last return value */ |
| 79 | lua_pushnumber(L, tm_getelapsed(&base->base_tm)/1000.0); | 79 | lua_pushnumber(L, tm_getelapsed(&base->base_tm)/1000.0); |
| 80 | #endif | 80 | #endif |
| @@ -139,7 +139,7 @@ int buf_receive(lua_State *L, p_buf buf) | |||
| 139 | for ( ; arg <= top; arg++) lua_pushnil(L); | 139 | for ( ; arg <= top; arg++) lua_pushnil(L); |
| 140 | /* last return is an error code */ | 140 | /* last return is an error code */ |
| 141 | priv_pusherror(L, err); | 141 | priv_pusherror(L, err); |
| 142 | #ifdef _DEBUG | 142 | #ifdef LUASOCKET_DEBUG |
| 143 | /* push time elapsed during operation as the last return value */ | 143 | /* push time elapsed during operation as the last return value */ |
| 144 | lua_pushnumber(L, tm_getelapsed(&base->base_tm)/1000.0); | 144 | lua_pushnumber(L, tm_getelapsed(&base->base_tm)/1000.0); |
| 145 | #endif | 145 | #endif |
diff --git a/src/http.lua b/src/http.lua index dce3ac8..9543d59 100644 --- a/src/http.lua +++ b/src/http.lua | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | ----------------------------------------------------------------------------- | 8 | ----------------------------------------------------------------------------- |
| 9 | 9 | ||
| 10 | local Public, Private = {}, {} | 10 | local Public, Private = {}, {} |
| 11 | HTTP = Public | 11 | http = Public |
| 12 | 12 | ||
| 13 | ----------------------------------------------------------------------------- | 13 | ----------------------------------------------------------------------------- |
| 14 | -- Program constants | 14 | -- Program constants |
| @@ -195,7 +195,7 @@ end | |||
| 195 | function Private.receivebody_bylength(sock, length, receive_cb) | 195 | function Private.receivebody_bylength(sock, length, receive_cb) |
| 196 | local uerr, go | 196 | local uerr, go |
| 197 | while length > 0 do | 197 | while length > 0 do |
| 198 | local size = min(Public.BLOCKSIZE, length) | 198 | local size = math.min(Public.BLOCKSIZE, length) |
| 199 | local chunk, err = sock:receive(size) | 199 | local chunk, err = sock:receive(size) |
| 200 | if err then | 200 | if err then |
| 201 | go, uerr = receive_cb(nil, err) | 201 | go, uerr = receive_cb(nil, err) |
| @@ -542,7 +542,7 @@ function Public.request_cb(request, response) | |||
| 542 | scheme = "http" | 542 | scheme = "http" |
| 543 | }) | 543 | }) |
| 544 | if parsed.scheme ~= "http" then | 544 | if parsed.scheme ~= "http" then |
| 545 | response.error = format("unknown scheme '%s'", parsed.scheme) | 545 | response.error = string.format("unknown scheme '%s'", parsed.scheme) |
| 546 | return response | 546 | return response |
| 547 | end | 547 | end |
| 548 | -- explicit authentication info overrides that given by the URL | 548 | -- explicit authentication info overrides that given by the URL |
diff --git a/src/select.c b/src/select.c index 1aaa7fe..5c08730 100644 --- a/src/select.c +++ b/src/select.c | |||
| @@ -31,8 +31,6 @@ void select_open(lua_State *L) | |||
| 31 | { | 31 | { |
| 32 | /* push select auxiliar lua function and register | 32 | /* push select auxiliar lua function and register |
| 33 | * select_lua_select with it as an upvalue */ | 33 | * select_lua_select with it as an upvalue */ |
| 34 | #ifdef LUASOCKET_DEBUG | ||
| 35 | #endif | ||
| 36 | luaL_loadfile(L, "lsselect.lua"); | 34 | luaL_loadfile(L, "lsselect.lua"); |
| 37 | lua_call(L, 0, 1); | 35 | lua_call(L, 0, 1); |
| 38 | lua_pushcclosure(L, select_lua_select, 1); | 36 | lua_pushcclosure(L, select_lua_select, 1); |
diff --git a/src/timeout.c b/src/timeout.c index fdbc47a..940ddca 100644 --- a/src/timeout.c +++ b/src/timeout.c | |||
| @@ -20,7 +20,7 @@ | |||
| 20 | /*=========================================================================*\ | 20 | /*=========================================================================*\ |
| 21 | * Internal function prototypes | 21 | * Internal function prototypes |
| 22 | \*=========================================================================*/ | 22 | \*=========================================================================*/ |
| 23 | #ifdef _DEBUG | 23 | #ifdef LUASOCKET_DEBUG |
| 24 | static int tm_lua_time(lua_State *L); | 24 | static int tm_lua_time(lua_State *L); |
| 25 | static int tm_lua_sleep(lua_State *L); | 25 | static int tm_lua_sleep(lua_State *L); |
| 26 | #endif | 26 | #endif |
| @@ -123,7 +123,7 @@ int tm_gettime(void) | |||
| 123 | void tm_open(lua_State *L) | 123 | void tm_open(lua_State *L) |
| 124 | { | 124 | { |
| 125 | (void) L; | 125 | (void) L; |
| 126 | #ifdef _DEBUG | 126 | #ifdef LUASOCKET_DEBUG |
| 127 | lua_pushcfunction(L, tm_lua_time); | 127 | lua_pushcfunction(L, tm_lua_time); |
| 128 | priv_newglobal(L, "_time"); | 128 | priv_newglobal(L, "_time"); |
| 129 | lua_pushcfunction(L, tm_lua_sleep); | 129 | lua_pushcfunction(L, tm_lua_sleep); |
| @@ -137,7 +137,7 @@ void tm_open(lua_State *L) | |||
| 137 | /*-------------------------------------------------------------------------*\ | 137 | /*-------------------------------------------------------------------------*\ |
| 138 | * Returns the time the system has been up, in secconds. | 138 | * Returns the time the system has been up, in secconds. |
| 139 | \*-------------------------------------------------------------------------*/ | 139 | \*-------------------------------------------------------------------------*/ |
| 140 | #ifdef _DEBUG | 140 | #ifdef LUASOCKET_DEBUG |
| 141 | static int tm_lua_time(lua_State *L) | 141 | static int tm_lua_time(lua_State *L) |
| 142 | { | 142 | { |
| 143 | lua_pushnumber(L, tm_gettime()/1000.0); | 143 | lua_pushnumber(L, tm_gettime()/1000.0); |
diff --git a/src/url.lua b/src/url.lua index 0ecec3c..4d2bfa7 100644 --- a/src/url.lua +++ b/src/url.lua | |||
| @@ -143,8 +143,8 @@ function Public.parse_path(path) | |||
| 143 | for i = 1, table.getn(parsed) do | 143 | for i = 1, table.getn(parsed) do |
| 144 | parsed[i] = Code.unescape(parsed[i]) | 144 | parsed[i] = Code.unescape(parsed[i]) |
| 145 | end | 145 | end |
| 146 | if stringsub(path, 1, 1) == "/" then parsed.is_absolute = 1 end | 146 | if string.sub(path, 1, 1) == "/" then parsed.is_absolute = 1 end |
| 147 | if stringsub(path, -1, -1) == "/" then parsed.is_directory = 1 end | 147 | if string.sub(path, -1, -1) == "/" then parsed.is_directory = 1 end |
| 148 | return parsed | 148 | return parsed |
| 149 | end | 149 | end |
| 150 | 150 | ||
| @@ -214,7 +214,7 @@ end | |||
| 214 | -- corresponding absolute path | 214 | -- corresponding absolute path |
| 215 | ----------------------------------------------------------------------------- | 215 | ----------------------------------------------------------------------------- |
| 216 | function Private.absolute_path(base_path, relative_path) | 216 | function Private.absolute_path(base_path, relative_path) |
| 217 | if stringsub(relative_path, 1, 1) == "/" then return relative_path end | 217 | if string.sub(relative_path, 1, 1) == "/" then return relative_path end |
| 218 | local path = string.gsub(base_path, "[^/]*$", "") | 218 | local path = string.gsub(base_path, "[^/]*$", "") |
| 219 | path = path .. relative_path | 219 | path = path .. relative_path |
| 220 | path = string.gsub(path, "([^/]*%./)", function (s) | 220 | path = string.gsub(path, "([^/]*%./)", function (s) |
diff --git a/test/httptest.lua b/test/httptest.lua index 85c8bd8..2941390 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
| @@ -7,21 +7,21 @@ | |||
| 7 | dofile("noglobals.lua") | 7 | dofile("noglobals.lua") |
| 8 | 8 | ||
| 9 | local similar = function(s1, s2) | 9 | local similar = function(s1, s2) |
| 10 | return strlower(gsub(s1 or "", "%s", "")) == | 10 | return string.lower(string.gsub(s1 or "", "%s", "")) == |
| 11 | strlower(gsub(s2 or "", "%s", "")) | 11 | string.lower(string.gsub(s2 or "", "%s", "")) |
| 12 | end | 12 | end |
| 13 | 13 | ||
| 14 | local fail = function(s) | 14 | local fail = function(s) |
| 15 | s = s or "failed!" | 15 | s = s or "failed!" |
| 16 | print(s) | 16 | print(s) |
| 17 | exit() | 17 | os.exit() |
| 18 | end | 18 | end |
| 19 | 19 | ||
| 20 | local readfile = function(name) | 20 | local readfile = function(name) |
| 21 | local f = readfrom(name) | 21 | local f = io.open(name, "r") |
| 22 | if not f then return nil end | 22 | if not f then return nil end |
| 23 | local s = read("*a") | 23 | local s = f:read("*a") |
| 24 | readfrom() | 24 | f:close() |
| 25 | return s | 25 | return s |
| 26 | end | 26 | end |
| 27 | 27 | ||
| @@ -31,7 +31,7 @@ local check = function (v, e) | |||
| 31 | end | 31 | end |
| 32 | 32 | ||
| 33 | local check_request = function(request, expect, ignore) | 33 | local check_request = function(request, expect, ignore) |
| 34 | local response = HTTP.request(request) | 34 | local response = http.request(request) |
| 35 | for i,v in response do | 35 | for i,v in response do |
| 36 | if not ignore[i] then | 36 | if not ignore[i] then |
| 37 | if v ~= expect[i] then %fail(i .. " differs!") end | 37 | if v ~= expect[i] then %fail(i .. " differs!") end |
| @@ -45,30 +45,28 @@ local check_request = function(request, expect, ignore) | |||
| 45 | print("ok") | 45 | print("ok") |
| 46 | end | 46 | end |
| 47 | 47 | ||
| 48 | dofile("../src/modules/http.lua") | ||
| 49 | |||
| 50 | local request, response, ignore, expect, index, prefix, cgiprefix | 48 | local request, response, ignore, expect, index, prefix, cgiprefix |
| 51 | 49 | ||
| 52 | local t = _time() | 50 | local t = socket._time() |
| 53 | 51 | ||
| 54 | HOST = HOST or "localhost" | 52 | HOST = HOST or "localhost" |
| 55 | prefix = prefix or "/luasocket-test" | 53 | prefix = prefix or "/luasocket" |
| 56 | cgiprefix = cgiprefix or "/luasocket-test-cgi" | 54 | cgiprefix = cgiprefix or "/luasocket/cgi" |
| 57 | index = readfile("index.html") | 55 | index = readfile("test/index.html") |
| 58 | 56 | ||
| 59 | write("testing request uri correctness: ") | 57 | io.write("testing request uri correctness: ") |
| 60 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" | 58 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" |
| 61 | local back = HTTP.get("http://" .. HOST .. forth) | 59 | local back = http.get("http://" .. HOST .. forth) |
| 62 | if similar(back, forth) then print("ok") | 60 | if similar(back, forth) then print("ok") |
| 63 | else fail("failed!") end | 61 | else fail("failed!") end |
| 64 | 62 | ||
| 65 | write("testing query string correctness: ") | 63 | io.write("testing query string correctness: ") |
| 66 | forth = "this+is+the+query+string" | 64 | forth = "this+is+the+query+string" |
| 67 | back = HTTP.get("http://" .. HOST .. cgiprefix .. "/query-string?" .. forth) | 65 | back = http.get("http://" .. HOST .. cgiprefix .. "/query-string?" .. forth) |
| 68 | if similar(back, forth) then print("ok") | 66 | if similar(back, forth) then print("ok") |
| 69 | else fail("failed!") end | 67 | else fail("failed!") end |
| 70 | 68 | ||
| 71 | write("testing document retrieval: ") | 69 | io.write("testing document retrieval: ") |
| 72 | request = { | 70 | request = { |
| 73 | url = "http://" .. HOST .. prefix .. "/index.html" | 71 | url = "http://" .. HOST .. prefix .. "/index.html" |
| 74 | } | 72 | } |
| @@ -82,7 +80,7 @@ ignore = { | |||
| 82 | } | 80 | } |
| 83 | check_request(request, expect, ignore) | 81 | check_request(request, expect, ignore) |
| 84 | 82 | ||
| 85 | write("testing HTTP redirection: ") | 83 | io.write("testing http redirection: ") |
| 86 | request = { | 84 | request = { |
| 87 | url = "http://" .. HOST .. prefix | 85 | url = "http://" .. HOST .. prefix |
| 88 | } | 86 | } |
| @@ -97,7 +95,7 @@ ignore = { | |||
| 97 | check_request(request, expect, ignore) | 95 | check_request(request, expect, ignore) |
| 98 | 96 | ||
| 99 | 97 | ||
| 100 | write("testing automatic auth failure: ") | 98 | io.write("testing automatic auth failure: ") |
| 101 | request = { | 99 | request = { |
| 102 | url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html" | 100 | url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html" |
| 103 | } | 101 | } |
| @@ -111,7 +109,7 @@ ignore = { | |||
| 111 | } | 109 | } |
| 112 | check_request(request, expect, ignore) | 110 | check_request(request, expect, ignore) |
| 113 | 111 | ||
| 114 | write("testing HTTP redirection failure: ") | 112 | io.write("testing http redirection failure: ") |
| 115 | request = { | 113 | request = { |
| 116 | url = "http://" .. HOST .. prefix, | 114 | url = "http://" .. HOST .. prefix, |
| 117 | stay = 1 | 115 | stay = 1 |
| @@ -126,29 +124,29 @@ ignore = { | |||
| 126 | } | 124 | } |
| 127 | check_request(request, expect, ignore) | 125 | check_request(request, expect, ignore) |
| 128 | 126 | ||
| 129 | write("testing host not found: ") | 127 | io.write("testing host not found: ") |
| 130 | request = { | 128 | request = { |
| 131 | url = "http://wronghost/does/not/exist" | 129 | url = "http://wronghost/does/not/exist" |
| 132 | } | 130 | } |
| 133 | local c, e = connect("wronghost", 80) | 131 | local c, e = socket.connect("wronghost", 80) |
| 134 | expect = { | 132 | expect = { |
| 135 | error = e | 133 | error = e |
| 136 | } | 134 | } |
| 137 | ignore = {} | 135 | ignore = {} |
| 138 | check_request(request, expect, ignore) | 136 | check_request(request, expect, ignore) |
| 139 | 137 | ||
| 140 | write("testing invalid url: ") | 138 | io.write("testing invalid url: ") |
| 141 | request = { | 139 | request = { |
| 142 | url = HOST .. prefix | 140 | url = HOST .. prefix |
| 143 | } | 141 | } |
| 144 | local c, e = connect("", 80) | 142 | local c, e = socket.connect("", 80) |
| 145 | expect = { | 143 | expect = { |
| 146 | error = e | 144 | error = e |
| 147 | } | 145 | } |
| 148 | ignore = {} | 146 | ignore = {} |
| 149 | check_request(request, expect, ignore) | 147 | check_request(request, expect, ignore) |
| 150 | 148 | ||
| 151 | write("testing document not found: ") | 149 | io.write("testing document not found: ") |
| 152 | request = { | 150 | request = { |
| 153 | url = "http://" .. HOST .. "/wrongdocument.html" | 151 | url = "http://" .. HOST .. "/wrongdocument.html" |
| 154 | } | 152 | } |
| @@ -162,7 +160,7 @@ ignore = { | |||
| 162 | } | 160 | } |
| 163 | check_request(request, expect, ignore) | 161 | check_request(request, expect, ignore) |
| 164 | 162 | ||
| 165 | write("testing auth failure: ") | 163 | io.write("testing auth failure: ") |
| 166 | request = { | 164 | request = { |
| 167 | url = "http://" .. HOST .. prefix .. "/auth/index.html" | 165 | url = "http://" .. HOST .. prefix .. "/auth/index.html" |
| 168 | } | 166 | } |
| @@ -176,7 +174,7 @@ ignore = { | |||
| 176 | } | 174 | } |
| 177 | check_request(request, expect, ignore) | 175 | check_request(request, expect, ignore) |
| 178 | 176 | ||
| 179 | write("testing manual basic auth: ") | 177 | io.write("testing manual basic auth: ") |
| 180 | request = { | 178 | request = { |
| 181 | url = "http://" .. HOST .. prefix .. "/auth/index.html", | 179 | url = "http://" .. HOST .. prefix .. "/auth/index.html", |
| 182 | headers = { | 180 | headers = { |
| @@ -193,7 +191,7 @@ ignore = { | |||
| 193 | } | 191 | } |
| 194 | check_request(request, expect, ignore) | 192 | check_request(request, expect, ignore) |
| 195 | 193 | ||
| 196 | write("testing automatic basic auth: ") | 194 | io.write("testing automatic basic auth: ") |
| 197 | request = { | 195 | request = { |
| 198 | url = "http://luasocket:password@" .. HOST .. prefix .. "/auth/index.html" | 196 | url = "http://luasocket:password@" .. HOST .. prefix .. "/auth/index.html" |
| 199 | } | 197 | } |
| @@ -207,7 +205,7 @@ ignore = { | |||
| 207 | } | 205 | } |
| 208 | check_request(request, expect, ignore) | 206 | check_request(request, expect, ignore) |
| 209 | 207 | ||
| 210 | write("testing auth info overriding: ") | 208 | io.write("testing auth info overriding: ") |
| 211 | request = { | 209 | request = { |
| 212 | url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html", | 210 | url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html", |
| 213 | user = "luasocket", | 211 | user = "luasocket", |
| @@ -223,7 +221,7 @@ ignore = { | |||
| 223 | } | 221 | } |
| 224 | check_request(request, expect, ignore) | 222 | check_request(request, expect, ignore) |
| 225 | 223 | ||
| 226 | write("testing cgi output retrieval (probably chunked...): ") | 224 | io.write("testing cgi output retrieval (probably chunked...): ") |
| 227 | request = { | 225 | request = { |
| 228 | url = "http://" .. HOST .. cgiprefix .. "/cat-index-html" | 226 | url = "http://" .. HOST .. cgiprefix .. "/cat-index-html" |
| 229 | } | 227 | } |
| @@ -237,7 +235,7 @@ ignore = { | |||
| 237 | } | 235 | } |
| 238 | check_request(request, expect, ignore) | 236 | check_request(request, expect, ignore) |
| 239 | 237 | ||
| 240 | write("testing redirect loop: ") | 238 | io.write("testing redirect loop: ") |
| 241 | request = { | 239 | request = { |
| 242 | url = "http://" .. HOST .. cgiprefix .. "/redirect-loop" | 240 | url = "http://" .. HOST .. cgiprefix .. "/redirect-loop" |
| 243 | } | 241 | } |
| @@ -251,7 +249,7 @@ ignore = { | |||
| 251 | } | 249 | } |
| 252 | check_request(request, expect, ignore) | 250 | check_request(request, expect, ignore) |
| 253 | 251 | ||
| 254 | write("testing post method: ") | 252 | io.write("testing post method: ") |
| 255 | request = { | 253 | request = { |
| 256 | url = "http://" .. HOST .. cgiprefix .. "/cat", | 254 | url = "http://" .. HOST .. cgiprefix .. "/cat", |
| 257 | method = "POST", | 255 | method = "POST", |
| @@ -267,7 +265,7 @@ ignore = { | |||
| 267 | } | 265 | } |
| 268 | check_request(request, expect, ignore) | 266 | check_request(request, expect, ignore) |
| 269 | 267 | ||
| 270 | write("testing wrong scheme: ") | 268 | io.write("testing wrong scheme: ") |
| 271 | request = { | 269 | request = { |
| 272 | url = "wrong://" .. HOST .. cgiprefix .. "/cat", | 270 | url = "wrong://" .. HOST .. cgiprefix .. "/cat", |
| 273 | method = "GET" | 271 | method = "GET" |
| @@ -280,31 +278,31 @@ ignore = { | |||
| 280 | check_request(request, expect, ignore) | 278 | check_request(request, expect, ignore) |
| 281 | 279 | ||
| 282 | local body | 280 | local body |
| 283 | write("testing simple get function: ") | 281 | io.write("testing simple get function: ") |
| 284 | body = HTTP.get("http://" .. HOST .. prefix .. "/index.html") | 282 | body = http.get("http://" .. HOST .. prefix .. "/index.html") |
| 285 | check(body == index) | 283 | check(body == index) |
| 286 | 284 | ||
| 287 | write("testing simple get function with table args: ") | 285 | io.write("testing simple get function with table args: ") |
| 288 | body = HTTP.get { | 286 | body = http.get { |
| 289 | url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html", | 287 | url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html", |
| 290 | user = "luasocket", | 288 | user = "luasocket", |
| 291 | password = "password" | 289 | password = "password" |
| 292 | } | 290 | } |
| 293 | check(body == index) | 291 | check(body == index) |
| 294 | 292 | ||
| 295 | write("testing simple post function: ") | 293 | io.write("testing simple post function: ") |
| 296 | body = HTTP.post("http://" .. HOST .. cgiprefix .. "/cat", index) | 294 | body = http.post("http://" .. HOST .. cgiprefix .. "/cat", index) |
| 297 | check(body == index) | 295 | check(body == index) |
| 298 | 296 | ||
| 299 | write("testing simple post function with table args: ") | 297 | io.write("testing simple post function with table args: ") |
| 300 | body = HTTP.post { | 298 | body = http.post { |
| 301 | url = "http://" .. HOST .. cgiprefix .. "/cat", | 299 | url = "http://" .. HOST .. cgiprefix .. "/cat", |
| 302 | body = index | 300 | body = index |
| 303 | } | 301 | } |
| 304 | check(body == index) | 302 | check(body == index) |
| 305 | 303 | ||
| 306 | write("testing HEAD method: ") | 304 | io.write("testing HEAD method: ") |
| 307 | response = HTTP.request { | 305 | response = http.request { |
| 308 | method = "HEAD", | 306 | method = "HEAD", |
| 309 | url = "http://www.tecgraf.puc-rio.br/~diego/" | 307 | url = "http://www.tecgraf.puc-rio.br/~diego/" |
| 310 | } | 308 | } |
| @@ -312,4 +310,4 @@ check(response and response.headers) | |||
| 312 | 310 | ||
| 313 | print("passed all tests") | 311 | print("passed all tests") |
| 314 | 312 | ||
| 315 | print(format("done in %.2fs", _time() - t)) | 313 | print(string.format("done in %.2fs", socket._time() - t)) |
diff --git a/test/testclnt.lua b/test/testclnt.lua index 73c10de..15f1dd8 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua | |||
| @@ -2,32 +2,32 @@ HOST = HOST or "localhost" | |||
| 2 | PORT = PORT or "8080" | 2 | PORT = PORT or "8080" |
| 3 | 3 | ||
| 4 | function pass(...) | 4 | function pass(...) |
| 5 | local s = call(format, arg) | 5 | local s = string.format(unpack(arg)) |
| 6 | write(s, "\n") | 6 | io.write(s, "\n") |
| 7 | end | 7 | end |
| 8 | 8 | ||
| 9 | function fail(...) | 9 | function fail(...) |
| 10 | local s = call(format, arg) | 10 | local s = string.format(unpack(arg)) |
| 11 | write("ERROR: ", s, "!\n") | 11 | io.write("ERROR: ", s, "!\n") |
| 12 | exit() | 12 | os.exit() |
| 13 | end | 13 | end |
| 14 | 14 | ||
| 15 | function warn(...) | 15 | function warn(...) |
| 16 | local s = call(format, arg) | 16 | local s = format(unpack(arg)) |
| 17 | write("WARNING: ", s, "\n") | 17 | io.write("WARNING: ", s, "\n") |
| 18 | end | 18 | end |
| 19 | 19 | ||
| 20 | function remote(...) | 20 | function remote(...) |
| 21 | local s = call(format, arg) | 21 | local s = string.format(unpack(arg)) |
| 22 | s = gsub(s, "\n", ";") | 22 | s = string.gsub(s, "\n", ";") |
| 23 | s = gsub(s, "%s+", " ") | 23 | s = string.gsub(s, "%s+", " ") |
| 24 | s = gsub(s, "^%s*", "") | 24 | s = string.gsub(s, "^%s*", "") |
| 25 | control:send(s, "\n") | 25 | control:send(s, "\n") |
| 26 | control:receive() | 26 | control:receive() |
| 27 | end | 27 | end |
| 28 | 28 | ||
| 29 | function test(test) | 29 | function test(test) |
| 30 | write("----------------------------------------------\n", | 30 | io.write("----------------------------------------------\n", |
| 31 | "testing: ", test, "\n", | 31 | "testing: ", test, "\n", |
| 32 | "----------------------------------------------\n") | 32 | "----------------------------------------------\n") |
| 33 | end | 33 | end |
| @@ -66,51 +66,69 @@ function check_timeout(tm, sl, elapsed, err, opp, mode, alldone) | |||
| 66 | end | 66 | end |
| 67 | end | 67 | end |
| 68 | 68 | ||
| 69 | write("----------------------------------------------\n", | 69 | io.write("----------------------------------------------\n", |
| 70 | "LuaSocket Test Procedures\n", | 70 | "LuaSocket Test Procedures\n", |
| 71 | "----------------------------------------------\n") | 71 | "----------------------------------------------\n") |
| 72 | 72 | ||
| 73 | if not _time or not _sleep then fail("not compiled with _DEBUG") end | 73 | if not socket._time or not socket._sleep then |
| 74 | fail("not compiled with _DEBUG") | ||
| 75 | end | ||
| 74 | 76 | ||
| 75 | start = _time() | 77 | start = socket._time() |
| 76 | 78 | ||
| 77 | function tcpreconnect() | 79 | function tcpreconnect() |
| 78 | write("attempting data connection... ") | 80 | io.write("attempting data connection... ") |
| 79 | if data then data:close() end | 81 | if data then data:close() end |
| 80 | remote [[ | 82 | remote [[ |
| 81 | if data then data:close() data = nil end | 83 | if data then data:close() data = nil end |
| 82 | data = server:accept() | 84 | data = server:accept() |
| 83 | ]] | 85 | ]] |
| 84 | data, error = connect(HOST, PORT) | 86 | data, err = socket.connect(HOST, PORT) |
| 85 | if not data then fail(error) | 87 | if not data then fail(err) |
| 86 | else pass("connected!") end | 88 | else pass("connected!") end |
| 87 | end | 89 | end |
| 88 | reconnect = tcpreconnect | 90 | reconnect = tcpreconnect |
| 89 | 91 | ||
| 90 | pass("attempting control connection...") | 92 | pass("attempting control connection...") |
| 91 | control, error = connect(HOST, PORT) | 93 | control, err = socket.connect(HOST, PORT) |
| 92 | if error then fail(error) | 94 | if err then fail(err) |
| 93 | else pass("connected!") end | 95 | else pass("connected!") end |
| 94 | 96 | ||
| 95 | ------------------------------------------------------------------------ | 97 | ------------------------------------------------------------------------ |
| 96 | test("bugs") | 98 | test("bugs") |
| 97 | 99 | ||
| 98 | write("empty host connect: ") | 100 | io.write("empty host connect: ") |
| 99 | function empty_connect() | 101 | function empty_connect() |
| 100 | if data then data:close() data = nil end | 102 | if data then data:close() data = nil end |
| 101 | remote [[ | 103 | remote [[ |
| 102 | if data then data:close() data = nil end | 104 | if data then data:close() data = nil end |
| 103 | data = server:accept() | 105 | data = server:accept() |
| 104 | ]] | 106 | ]] |
| 105 | data, err = connect("", PORT) | 107 | data, err = socket.connect("", PORT) |
| 106 | if not data then | 108 | if not data then |
| 107 | pass("ok") | 109 | pass("ok") |
| 108 | data = connect(HOST, PORT) | 110 | data = socket.connect(HOST, PORT) |
| 109 | else fail("should not have connected!") end | 111 | else fail("should not have connected!") end |
| 110 | end | 112 | end |
| 111 | 113 | ||
| 112 | empty_connect() | 114 | empty_connect() |
| 113 | 115 | ||
| 116 | io.write("active close: ") | ||
| 117 | function active_close() | ||
| 118 | reconnect() | ||
| 119 | if socket._isclosed(data) then fail("should not be closed") end | ||
| 120 | data:close() | ||
| 121 | if not socket._isclosed(data) then fail("should be closed") end | ||
| 122 | data = nil | ||
| 123 | local udp = socket.udp() | ||
| 124 | if socket._isclosed(udp) then fail("should not be closed") end | ||
| 125 | udp:close() | ||
| 126 | if not socket._isclosed(udp) then fail("should be closed") end | ||
| 127 | pass("ok") | ||
| 128 | end | ||
| 129 | |||
| 130 | active_close() | ||
| 131 | |||
| 114 | ------------------------------------------------------------------------ | 132 | ------------------------------------------------------------------------ |
| 115 | test("method registration") | 133 | test("method registration") |
| 116 | 134 | ||
| @@ -133,7 +151,7 @@ test_methods(control, { | |||
| 133 | }) | 151 | }) |
| 134 | 152 | ||
| 135 | if udpsocket then | 153 | if udpsocket then |
| 136 | test_methods(udpsocket(), { | 154 | test_methods(socket.udp(), { |
| 137 | "close", | 155 | "close", |
| 138 | "timeout", | 156 | "timeout", |
| 139 | "send", | 157 | "send", |
| @@ -147,50 +165,27 @@ if udpsocket then | |||
| 147 | }) | 165 | }) |
| 148 | end | 166 | end |
| 149 | 167 | ||
| 150 | test_methods(bind("*", 0), { | 168 | test_methods(socket.bind("*", 0), { |
| 151 | "close", | 169 | "close", |
| 152 | "timeout", | 170 | "timeout", |
| 153 | "accept" | 171 | "accept" |
| 154 | }) | 172 | }) |
| 155 | 173 | ||
| 156 | if pipe then | ||
| 157 | local p1, p2 = pipe() | ||
| 158 | test_methods(p1, { | ||
| 159 | "close", | ||
| 160 | "timeout", | ||
| 161 | "send", | ||
| 162 | "receive" | ||
| 163 | }) | ||
| 164 | test_methods(p2, { | ||
| 165 | "close", | ||
| 166 | "timeout", | ||
| 167 | "send", | ||
| 168 | "receive" | ||
| 169 | }) | ||
| 170 | end | ||
| 171 | |||
| 172 | if filesocket then | ||
| 173 | test_methods(filesocket(0), { | ||
| 174 | "close", | ||
| 175 | "timeout", | ||
| 176 | "send", | ||
| 177 | "receive" | ||
| 178 | }) | ||
| 179 | end | ||
| 180 | |||
| 181 | ------------------------------------------------------------------------ | 174 | ------------------------------------------------------------------------ |
| 182 | test("select function") | 175 | test("select function") |
| 183 | function test_selectbugs() | 176 | function test_selectbugs() |
| 184 | local r, s, e = select(nil, nil, 0.1) | 177 | local r, s, e = socket.select(nil, nil, 0.1) |
| 185 | assert(type(r) == "table" and type(s) == "table" and e == "timeout") | 178 | assert(type(r) == "table" and type(s) == "table" and e == "timeout") |
| 186 | pass("both nil: ok") | 179 | pass("both nil: ok") |
| 187 | local udp = udpsocket() | 180 | local udp = socket.udp() |
| 188 | udp:close() | 181 | udp:close() |
| 189 | r, s, e = select({ data }, { data }, 0.1) | 182 | r, s, e = socket.select({ udp }, { udp }, 0.1) |
| 190 | assert(type(r) == "table" and type(s) == "table" and e == "timeout") | 183 | assert(type(r) == "table" and type(s) == "table" and e == "timeout") |
| 191 | pass("closed sockets: ok") | 184 | pass("closed sockets: ok") |
| 192 | e = call(select, {"wrong", 1, 0.1}, "x", nil) | 185 | e = pcall(socket.select, "wrong", 1, 0.1) |
| 193 | assert(e == nil) | 186 | assert(e == false) |
| 187 | e = pcall(socket.select, {}, 1, 0.1) | ||
| 188 | assert(e == false) | ||
| 194 | pass("invalid input: ok") | 189 | pass("invalid input: ok") |
| 195 | end | 190 | end |
| 196 | 191 | ||
| @@ -202,8 +197,8 @@ reconnect() | |||
| 202 | 197 | ||
| 203 | function test_asciiline(len) | 198 | function test_asciiline(len) |
| 204 | local str, str10, back, err | 199 | local str, str10, back, err |
| 205 | str = strrep("x", mod(len, 10)) | 200 | str = string.rep("x", math.mod(len, 10)) |
| 206 | str10 = strrep("aZb.c#dAe?", floor(len/10)) | 201 | str10 = string.rep("aZb.c#dAe?", math.floor(len/10)) |
| 207 | str = str .. str10 | 202 | str = str .. str10 |
| 208 | pass(len .. " byte(s) line") | 203 | pass(len .. " byte(s) line") |
| 209 | remote "str = data:receive()" | 204 | remote "str = data:receive()" |
| @@ -229,8 +224,9 @@ reconnect() | |||
| 229 | 224 | ||
| 230 | function test_rawline(len) | 225 | function test_rawline(len) |
| 231 | local str, str10, back, err | 226 | local str, str10, back, err |
| 232 | str = strrep(strchar(47), mod(len, 10)) | 227 | str = string.rep(string.char(47), math.mod(len, 10)) |
| 233 | str10 = strrep(strchar(120,21,77,4,5,0,7,36,44,100), floor(len/10)) | 228 | str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100), |
| 229 | math.floor(len/10)) | ||
| 234 | str = str .. str10 | 230 | str = str .. str10 |
| 235 | pass(len .. " byte(s) line") | 231 | pass(len .. " byte(s) line") |
| 236 | remote "str = data:receive()" | 232 | remote "str = data:receive()" |
| @@ -260,12 +256,12 @@ test("raw transfer") | |||
| 260 | reconnect() | 256 | reconnect() |
| 261 | 257 | ||
| 262 | function test_raw(len) | 258 | function test_raw(len) |
| 263 | local half = floor(len/2) | 259 | local half = math.floor(len/2) |
| 264 | local s1, s2, back, err | 260 | local s1, s2, back, err |
| 265 | s1 = strrep("x", half) | 261 | s1 = string.rep("x", half) |
| 266 | s2 = strrep("y", len-half) | 262 | s2 = string.rep("y", len-half) |
| 267 | pass(len .. " byte(s) block") | 263 | pass(len .. " byte(s) block") |
| 268 | remote (format("str = data:receive(%d)", len)) | 264 | remote (string.format("str = data:receive(%d)", len)) |
| 269 | err = data:send(s1) | 265 | err = data:send(s1) |
| 270 | if err then fail(err) end | 266 | if err then fail(err) end |
| 271 | err = data:send(s2) | 267 | err = data:send(s2) |
| @@ -312,17 +308,18 @@ test("mixed patterns") | |||
| 312 | reconnect() | 308 | reconnect() |
| 313 | 309 | ||
| 314 | function test_mixed(len) | 310 | function test_mixed(len) |
| 315 | local inter = floor(len/3) | 311 | local inter = math.floor(len/3) |
| 316 | local p1 = "unix " .. strrep("x", inter) .. "line\n" | 312 | local p1 = "unix " .. string.rep("x", inter) .. "line\n" |
| 317 | local p2 = "dos " .. strrep("y", inter) .. "line\r\n" | 313 | local p2 = "dos " .. string.rep("y", inter) .. "line\r\n" |
| 318 | local p3 = "raw " .. strrep("z", inter) .. "bytes" | 314 | local p3 = "raw " .. string.rep("z", inter) .. "bytes" |
| 319 | local bp1, bp2, bp3 | 315 | local bp1, bp2, bp3 |
| 320 | pass(len .. " byte(s) patterns") | 316 | pass(len .. " byte(s) patterns") |
| 321 | remote (format("str = data:receive(%d)", strlen(p1)+strlen(p2)+strlen(p3))) | 317 | remote (string.format("str = data:receive(%d)", |
| 318 | string.len(p1)+string.len(p2)+string.len(p3))) | ||
| 322 | err = data:send(p1, p2, p3) | 319 | err = data:send(p1, p2, p3) |
| 323 | if err then fail(err) end | 320 | if err then fail(err) end |
| 324 | remote "data:send(str)" | 321 | remote "data:send(str)" |
| 325 | bp1, bp2, bp3, err = data:receive("*lu", "*l", strlen(p3)) | 322 | bp1, bp2, bp3, err = data:receive("*lu", "*l", string.len(p3)) |
| 326 | if err then fail(err) end | 323 | if err then fail(err) end |
| 327 | if bp1.."\n" == p1 and bp2.."\r\n" == p2 and bp3 == p3 then | 324 | if bp1.."\n" == p1 and bp2.."\r\n" == p2 and bp3 == p3 then |
| 328 | pass("patterns match") | 325 | pass("patterns match") |
| @@ -349,7 +346,7 @@ function test_closed() | |||
| 349 | local str = 'little string' | 346 | local str = 'little string' |
| 350 | reconnect() | 347 | reconnect() |
| 351 | pass("trying read detection") | 348 | pass("trying read detection") |
| 352 | remote (format ([[ | 349 | remote (string.format ([[ |
| 353 | data:send('%s') | 350 | data:send('%s') |
| 354 | data:close() | 351 | data:close() |
| 355 | data = nil | 352 | data = nil |
| @@ -366,7 +363,7 @@ function test_closed() | |||
| 366 | data:close() | 363 | data:close() |
| 367 | data = nil | 364 | data = nil |
| 368 | ]] | 365 | ]] |
| 369 | err, total = data:send(strrep("ugauga", 100000)) | 366 | err, total = data:send(string.rep("ugauga", 100000)) |
| 370 | if not err then | 367 | if not err then |
| 371 | pass("failed: output buffer is at least %d bytes long!", total) | 368 | pass("failed: output buffer is at least %d bytes long!", total) |
| 372 | elseif err ~= "closed" then | 369 | elseif err ~= "closed" then |
| @@ -384,19 +381,19 @@ function test_blockingtimeoutreceive(len, tm, sl) | |||
| 384 | local str, err, total | 381 | local str, err, total |
| 385 | reconnect() | 382 | reconnect() |
| 386 | pass("%d bytes, %ds return timeout, %ds pause", len, tm, sl) | 383 | pass("%d bytes, %ds return timeout, %ds pause", len, tm, sl) |
| 387 | remote (format ([[ | 384 | remote (string.format ([[ |
| 388 | data:timeout(%d) | 385 | data:timeout(%d) |
| 389 | str = strrep('a', %d) | 386 | str = string.rep('a', %d) |
| 390 | data:send(str) | 387 | data:send(str) |
| 391 | print('server: sleeping for %ds') | 388 | print('server: sleeping for %ds') |
| 392 | _sleep(%d) | 389 | socket._sleep(%d) |
| 393 | print('server: woke up') | 390 | print('server: woke up') |
| 394 | data:send(str) | 391 | data:send(str) |
| 395 | ]], 2*tm, len, sl, sl)) | 392 | ]], 2*tm, len, sl, sl)) |
| 396 | data:timeout(tm, "return") | 393 | data:timeout(tm, "return") |
| 397 | str, err, elapsed = data:receive(2*len) | 394 | str, err, elapsed = data:receive(2*len) |
| 398 | check_timeout(tm, sl, elapsed, err, "receive", "return", | 395 | check_timeout(tm, sl, elapsed, err, "receive", "return", |
| 399 | strlen(str) == 2*len) | 396 | string.len(str) == 2*len) |
| 400 | end | 397 | end |
| 401 | test_blockingtimeoutreceive(800091, 1, 3) | 398 | test_blockingtimeoutreceive(800091, 1, 3) |
| 402 | test_blockingtimeoutreceive(800091, 2, 3) | 399 | test_blockingtimeoutreceive(800091, 2, 3) |
| @@ -409,16 +406,16 @@ function test_returntimeoutsend(len, tm, sl) | |||
| 409 | local str, err, total | 406 | local str, err, total |
| 410 | reconnect() | 407 | reconnect() |
| 411 | pass("%d bytes, %ds return timeout, %ds pause", len, tm, sl) | 408 | pass("%d bytes, %ds return timeout, %ds pause", len, tm, sl) |
| 412 | remote (format ([[ | 409 | remote (string.format ([[ |
| 413 | data:timeout(%d) | 410 | data:timeout(%d) |
| 414 | str = data:receive(%d) | 411 | str = data:receive(%d) |
| 415 | print('server: sleeping for %ds') | 412 | print('server: sleeping for %ds') |
| 416 | _sleep(%d) | 413 | socket._sleep(%d) |
| 417 | print('server: woke up') | 414 | print('server: woke up') |
| 418 | str = data:receive(%d) | 415 | str = data:receive(%d) |
| 419 | ]], 2*tm, len, sl, sl, len)) | 416 | ]], 2*tm, len, sl, sl, len)) |
| 420 | data:timeout(tm, "return") | 417 | data:timeout(tm, "return") |
| 421 | str = strrep("a", 2*len) | 418 | str = string.rep("a", 2*len) |
| 422 | err, total, elapsed = data:send(str) | 419 | err, total, elapsed = data:send(str) |
| 423 | check_timeout(tm, sl, elapsed, err, "send", "return", | 420 | check_timeout(tm, sl, elapsed, err, "send", "return", |
| 424 | total == 2*len) | 421 | total == 2*len) |
| @@ -435,19 +432,19 @@ function test_blockingtimeoutreceive(len, tm, sl) | |||
| 435 | local str, err, total | 432 | local str, err, total |
| 436 | reconnect() | 433 | reconnect() |
| 437 | pass("%d bytes, %ds blocking timeout, %ds pause", len, tm, sl) | 434 | pass("%d bytes, %ds blocking timeout, %ds pause", len, tm, sl) |
| 438 | remote (format ([[ | 435 | remote (string.format ([[ |
| 439 | data:timeout(%d) | 436 | data:timeout(%d) |
| 440 | str = strrep('a', %d) | 437 | str = string.rep('a', %d) |
| 441 | data:send(str) | 438 | data:send(str) |
| 442 | print('server: sleeping for %ds') | 439 | print('server: sleeping for %ds') |
| 443 | _sleep(%d) | 440 | socket._sleep(%d) |
| 444 | print('server: woke up') | 441 | print('server: woke up') |
| 445 | data:send(str) | 442 | data:send(str) |
| 446 | ]], 2*tm, len, sl, sl)) | 443 | ]], 2*tm, len, sl, sl)) |
| 447 | data:timeout(tm) | 444 | data:timeout(tm) |
| 448 | str, err, elapsed = data:receive(2*len) | 445 | str, err, elapsed = data:receive(2*len) |
| 449 | check_timeout(tm, sl, elapsed, err, "receive", "blocking", | 446 | check_timeout(tm, sl, elapsed, err, "receive", "blocking", |
| 450 | strlen(str) == 2*len) | 447 | string.len(str) == 2*len) |
| 451 | end | 448 | end |
| 452 | test_blockingtimeoutreceive(800091, 1, 3) | 449 | test_blockingtimeoutreceive(800091, 1, 3) |
| 453 | test_blockingtimeoutreceive(800091, 2, 3) | 450 | test_blockingtimeoutreceive(800091, 2, 3) |
| @@ -461,16 +458,16 @@ function test_blockingtimeoutsend(len, tm, sl) | |||
| 461 | local str, err, total | 458 | local str, err, total |
| 462 | reconnect() | 459 | reconnect() |
| 463 | pass("%d bytes, %ds blocking timeout, %ds pause", len, tm, sl) | 460 | pass("%d bytes, %ds blocking timeout, %ds pause", len, tm, sl) |
| 464 | remote (format ([[ | 461 | remote (string.format ([[ |
| 465 | data:timeout(%d) | 462 | data:timeout(%d) |
| 466 | str = data:receive(%d) | 463 | str = data:receive(%d) |
| 467 | print('server: sleeping for %ds') | 464 | print('server: sleeping for %ds') |
| 468 | _sleep(%d) | 465 | socket._sleep(%d) |
| 469 | print('server: woke up') | 466 | print('server: woke up') |
| 470 | str = data:receive(%d) | 467 | str = data:receive(%d) |
| 471 | ]], 2*tm, len, sl, sl, len)) | 468 | ]], 2*tm, len, sl, sl, len)) |
| 472 | data:timeout(tm) | 469 | data:timeout(tm) |
| 473 | str = strrep("a", 2*len) | 470 | str = string.rep("a", 2*len) |
| 474 | err, total, elapsed = data:send(str) | 471 | err, total, elapsed = data:send(str) |
| 475 | check_timeout(tm, sl, elapsed, err, "send", "blocking", | 472 | check_timeout(tm, sl, elapsed, err, "send", "blocking", |
| 476 | total == 2*len) | 473 | total == 2*len) |
| @@ -481,4 +478,4 @@ test_blockingtimeoutsend(800091, 3, 2) | |||
| 481 | test_blockingtimeoutsend(800091, 3, 1) | 478 | test_blockingtimeoutsend(800091, 3, 1) |
| 482 | 479 | ||
| 483 | ------------------------------------------------------------------------ | 480 | ------------------------------------------------------------------------ |
| 484 | test(format("done in %.2fs", _time() - start)) | 481 | test(string.format("done in %.2fs", socket._time() - start)) |
diff --git a/test/testsrvr.lua b/test/testsrvr.lua index 227e341..141c058 100644 --- a/test/testsrvr.lua +++ b/test/testsrvr.lua | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | HOST = HOST or "localhost" | 1 | HOST = HOST or "localhost" |
| 2 | PORT = PORT or "8080" | 2 | PORT = PORT or "8080" |
| 3 | 3 | ||
| 4 | server, error = bind(HOST, PORT) | 4 | server, error = socket.bind(HOST, PORT) |
| 5 | if not server then print("server: " .. tostring(error)) exit() end | 5 | if not server then print("server: " .. tostring(error)) os.exit() end |
| 6 | while 1 do | 6 | while 1 do |
| 7 | print("server: waiting for client connection..."); | 7 | print("server: waiting for client connection..."); |
| 8 | control = server:accept() | 8 | control = server:accept() |
| @@ -19,6 +19,6 @@ while 1 do | |||
| 19 | print("server: closing connection...") | 19 | print("server: closing connection...") |
| 20 | break | 20 | break |
| 21 | end | 21 | end |
| 22 | dostring(command) | 22 | (loadstring(command))() |
| 23 | end | 23 | end |
| 24 | end | 24 | end |
diff --git a/test/urltest.lua b/test/urltest.lua index da7475a..8ca36fe 100644 --- a/test/urltest.lua +++ b/test/urltest.lua | |||
| @@ -30,7 +30,7 @@ end | |||
| 30 | 30 | ||
| 31 | local check_parse_path = function(path, expect) | 31 | local check_parse_path = function(path, expect) |
| 32 | local parsed = URL.parse_path(path) | 32 | local parsed = URL.parse_path(path) |
| 33 | for i = 1, max(getn(parsed), getn(expect)) do | 33 | for i = 1, math.max(table.getn(parsed), table.getn(expect)) do |
| 34 | if parsed[i] ~= expect[i] then | 34 | if parsed[i] ~= expect[i] then |
| 35 | print(path) | 35 | print(path) |
| 36 | write("segment: ", i, " = '", Code.hexa(tostring(parsed[i])), | 36 | write("segment: ", i, " = '", Code.hexa(tostring(parsed[i])), |
