diff options
author | Emil Renner Berthing <esmil@mailme.dk> | 2012-12-11 23:59:37 +0100 |
---|---|---|
committer | Emil Renner Berthing <esmil@mailme.dk> | 2012-12-17 10:11:06 +0100 |
commit | f25118928aa35861b370a6529c651a28f5c8859b (patch) | |
tree | 63f07f33cd207f947ea43bef5d92f5311b2e758b /test | |
parent | b738f523cc7a56602e07ff54bd11203355a64af9 (diff) | |
download | lem-f25118928aa35861b370a6529c651a28f5c8859b.tar.gz lem-f25118928aa35861b370a6529c651a28f5c8859b.tar.xz lem-f25118928aa35861b370a6529c651a28f5c8859b.zip |
io: rework streams
Diffstat (limited to 'test')
-rwxr-xr-x | test/ctest.lua | 8 | ||||
-rwxr-xr-x | test/httptest.lua | 15 | ||||
-rwxr-xr-x | test/multiplexing.lua | 2 | ||||
-rwxr-xr-x | test/stest.lua | 9 |
4 files changed, 18 insertions, 16 deletions
diff --git a/test/ctest.lua b/test/ctest.lua index e33b372..399fd3a 100755 --- a/test/ctest.lua +++ b/test/ctest.lua @@ -22,12 +22,12 @@ print('Entered ' .. arg[0]) local utils = require 'lem.utils' local io = require 'lem.io' -local iconn, oconn = assert(io.tcp_connect('127.0.0.1', arg[1] or 8080)) +local conn = assert(io.tcp_connect('127.0.0.1', arg[1] or 8080)) for i = 1, 10 do - assert(oconn:write('ping\n')) + assert(conn:write('ping\n')) - local line, err = iconn:read('*l') + local line, err = conn:read('*l') if not line then if err == 'closed' then print("Server closed connection") @@ -40,7 +40,7 @@ for i = 1, 10 do print("Server answered: '" .. line .. "'") end -oconn:write('quit\n') +conn:write('quit\n') print('Exiting ' .. arg[0]) diff --git a/test/httptest.lua b/test/httptest.lua index 85d21d1..1e88f28 100755 --- a/test/httptest.lua +++ b/test/httptest.lua @@ -27,22 +27,23 @@ local concat = table.concat local done = false utils.spawn(function() - --local istream, ostream = assert(io.tcp_connect('www.google.dk', 80)) - local istream, ostream = assert(io.tcp_connect('127.0.0.1', 8080)) + local conn = assert(io.tcp_connect('www.google.dk', 80)) + --local conn = assert(io.tcp_connect('127.0.0.1', 8080)) print('\nConnected.') for i = 1, 2 do - --assert(ostream:write('GET / HTTP/1.1\r\nHost: www.google.dk\r\nConnection: close\r\n\r\n')) - assert(ostream:write('GET / HTTP/1.1\r\nHost: www.google.dk\r\n\r\n')) + --assert(conn:write('GET / HTTP/1.1\r\nHost: www.google.dk\r\nConnection: close\r\n\r\n')) + assert(conn:write('GET / HTTP/1.1\r\nHost: www.google.dk\r\n\r\n')) - local res = assert(istream:read('HTTPResponse')) + local res = assert(conn:read('HTTPResponse')) print(format('\nHTTP/%s %d %s', res.version, res.status, res.text)) for k, v in pairs(res.headers) do print(format('%s: %s', k, v)) end + --print(format('\n#body = %d', #assert(conn:read('*a')))) print(format('\n#body = %d', #assert(res:body()))) end @@ -50,9 +51,11 @@ utils.spawn(function() end) local write, yield = io.write, utils.yield +local sleeper = utils.newsleeper() repeat write('.') - yield() + --yield() + sleeper:sleep(0.001) until done -- vim: set ts=2 sw=2 noet: diff --git a/test/multiplexing.lua b/test/multiplexing.lua index fc421cb..d66d710 100755 --- a/test/multiplexing.lua +++ b/test/multiplexing.lua @@ -27,7 +27,7 @@ local stdout = queue.wrap(io.stdout) do local format = string.format - function queue.QOStream:printf(...) + function queue.Stream:printf(...) return self:write(format(...)) end end diff --git a/test/stest.lua b/test/stest.lua index b791bc8..60ea03d 100755 --- a/test/stest.lua +++ b/test/stest.lua @@ -31,12 +31,12 @@ utils.spawn(function() server:close() end) -local ok, err = server:autospawn(function(i, o) +local ok, err = server:autospawn(function(client) print 'Accepted a connection' local sleeper = utils.newsleeper() while true do - local line, err = i:read('*l') + local line, err = client:read('*l') if not line then if err == 'closed' then print("Client closed connection") @@ -50,12 +50,11 @@ local ok, err = server:autospawn(function(i, o) if line ~= 'ping' then break end sleeper:sleep(0.4) - assert(o:write('pong\n')) + assert(client:write('pong\n')) end print "Ok, I'm out" - assert(i:close()) - assert(o:close()) + assert(client:close()) end) if not ok and err ~= 'interrupted' then error(err) end |