diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-07-18 22:56:14 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-07-18 22:56:14 +0000 |
| commit | c8b402e00442cd249397d4d33d2723a1f08a8108 (patch) | |
| tree | d72a1ace55b42aa9d41c741fa2f757d92fad6592 /test | |
| parent | e4e2223cff658a7016724a625ebbd3dacb92a8f9 (diff) | |
| download | luasocket-c8b402e00442cd249397d4d33d2723a1f08a8108.tar.gz luasocket-c8b402e00442cd249397d4d33d2723a1f08a8108.tar.bz2 luasocket-c8b402e00442cd249397d4d33d2723a1f08a8108.zip | |
Changed send function.
Diffstat (limited to 'test')
| -rw-r--r-- | test/testclnt.lua | 86 | ||||
| -rw-r--r-- | test/testsrvr.lua | 33 |
2 files changed, 70 insertions, 49 deletions
diff --git a/test/testclnt.lua b/test/testclnt.lua index f98a504..356350a 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua | |||
| @@ -25,7 +25,7 @@ function remote(...) | |||
| 25 | s = string.gsub(s, "\n", ";") | 25 | s = string.gsub(s, "\n", ";") |
| 26 | s = string.gsub(s, "%s+", " ") | 26 | s = string.gsub(s, "%s+", " ") |
| 27 | s = string.gsub(s, "^%s*", "") | 27 | s = string.gsub(s, "^%s*", "") |
| 28 | control:send(s, "\n") | 28 | control:send(s .. "\n") |
| 29 | control:receive() | 29 | control:receive() |
| 30 | end | 30 | end |
| 31 | 31 | ||
| @@ -120,7 +120,7 @@ function test_mixed(len) | |||
| 120 | local bp1, bp2, bp3, bp4 | 120 | local bp1, bp2, bp3, bp4 |
| 121 | remote (string.format("str = data:receive(%d)", | 121 | remote (string.format("str = data:receive(%d)", |
| 122 | string.len(p1)+string.len(p2)+string.len(p3)+string.len(p4))) | 122 | string.len(p1)+string.len(p2)+string.len(p3)+string.len(p4))) |
| 123 | sent, err = data:send(p1, p2, p3, p4) | 123 | sent, err = data:send(p1..p2..p3..p4) |
| 124 | if err then fail(err) end | 124 | if err then fail(err) end |
| 125 | remote "data:send(str); data:close()" | 125 | remote "data:send(str); data:close()" |
| 126 | bp1, err = data:receive() | 126 | bp1, err = data:receive() |
| @@ -144,9 +144,9 @@ function test_asciiline(len) | |||
| 144 | str10 = string.rep("aZb.c#dAe?", math.floor(len/10)) | 144 | str10 = string.rep("aZb.c#dAe?", math.floor(len/10)) |
| 145 | str = str .. str10 | 145 | str = str .. str10 |
| 146 | remote "str = data:receive()" | 146 | remote "str = data:receive()" |
| 147 | sent, err = data:send(str, "\n") | 147 | sent, err = data:send(str.."\n") |
| 148 | if err then fail(err) end | 148 | if err then fail(err) end |
| 149 | remote "data:send(str, '\\n')" | 149 | remote "data:send(str ..'\\n')" |
| 150 | back, err = data:receive() | 150 | back, err = data:receive() |
| 151 | if err then fail(err) end | 151 | if err then fail(err) end |
| 152 | if back == str then pass("lines match") | 152 | if back == str then pass("lines match") |
| @@ -162,9 +162,9 @@ function test_rawline(len) | |||
| 162 | math.floor(len/10)) | 162 | math.floor(len/10)) |
| 163 | str = str .. str10 | 163 | str = str .. str10 |
| 164 | remote "str = data:receive()" | 164 | remote "str = data:receive()" |
| 165 | sent, err = data:send(str, "\n") | 165 | sent, err = data:send(str.."\n") |
| 166 | if err then fail(err) end | 166 | if err then fail(err) end |
| 167 | remote "data:send(str, '\\n')" | 167 | remote "data:send(str..'\\n')" |
| 168 | back, err = data:receive() | 168 | back, err = data:receive() |
| 169 | if err then fail(err) end | 169 | if err then fail(err) end |
| 170 | if back == str then pass("lines match") | 170 | if back == str then pass("lines match") |
| @@ -457,7 +457,62 @@ function getstats_test() | |||
| 457 | print("ok") | 457 | print("ok") |
| 458 | end | 458 | end |
| 459 | 459 | ||
| 460 | |||
| 460 | ------------------------------------------------------------------------ | 461 | ------------------------------------------------------------------------ |
| 462 | function test_nonblocking(size) | ||
| 463 | reconnect() | ||
| 464 | remote(string.format([[ | ||
| 465 | data:send(string.rep("a", %d)) | ||
| 466 | socket.sleep(0.5) | ||
| 467 | data:send(string.rep("b", %d)) | ||
| 468 | ]], size, size)) | ||
| 469 | local err = "timeout" | ||
| 470 | local part = "" | ||
| 471 | local str | ||
| 472 | data:settimeout(0) | ||
| 473 | while 1 do | ||
| 474 | str, err, part = data:receive(2*size - string.len(part), part) | ||
| 475 | if err ~= "timeout" then break end | ||
| 476 | end | ||
| 477 | assert(str == (string.rep("a", size) .. string.rep("b", size))) | ||
| 478 | reconnect() | ||
| 479 | remote(string.format([[ | ||
| 480 | str = data:receive(%d) | ||
| 481 | socket.sleep(0.5) | ||
| 482 | str = data:receive(%d, str) | ||
| 483 | str = data:receive("*l", str) | ||
| 484 | data:send(str) | ||
| 485 | data:send("\n") | ||
| 486 | ]], size, size)) | ||
| 487 | data:settimeout(0) | ||
| 488 | local sofar = 1 | ||
| 489 | while 1 do | ||
| 490 | _, err, part = data:send(str, sofar) | ||
| 491 | if err ~= "timeout" then break end | ||
| 492 | sofar = sofar + part | ||
| 493 | end | ||
| 494 | data:send("\n") | ||
| 495 | data:settimeout(-1) | ||
| 496 | local back = data:receive() | ||
| 497 | assert(back == str) | ||
| 498 | print("ok") | ||
| 499 | end | ||
| 500 | |||
| 501 | |||
| 502 | ------------------------------------------------------------------------ | ||
| 503 | test("non-blocking transfer") | ||
| 504 | test_nonblocking(1) | ||
| 505 | test_nonblocking(17) | ||
| 506 | test_nonblocking(200) | ||
| 507 | test_nonblocking(4091) | ||
| 508 | test_nonblocking(80199) | ||
| 509 | test_nonblocking(8000000) | ||
| 510 | test_nonblocking(80199) | ||
| 511 | test_nonblocking(4091) | ||
| 512 | test_nonblocking(200) | ||
| 513 | test_nonblocking(17) | ||
| 514 | test_nonblocking(1) | ||
| 515 | |||
| 461 | test("method registration") | 516 | test("method registration") |
| 462 | test_methods(socket.tcp(), { | 517 | test_methods(socket.tcp(), { |
| 463 | "accept", | 518 | "accept", |
| @@ -548,7 +603,6 @@ test_mixed(1) | |||
| 548 | 603 | ||
| 549 | 604 | ||
| 550 | test("binary line") | 605 | test("binary line") |
| 551 | reconnect() | ||
| 552 | test_rawline(1) | 606 | test_rawline(1) |
| 553 | test_rawline(17) | 607 | test_rawline(17) |
| 554 | test_rawline(200) | 608 | test_rawline(200) |
| @@ -562,24 +616,6 @@ test_rawline(17) | |||
| 562 | test_rawline(1) | 616 | test_rawline(1) |
| 563 | 617 | ||
| 564 | test("raw transfer") | 618 | test("raw transfer") |
| 565 | reconnect() | ||
| 566 | test_raw(1) | ||
| 567 | test_raw(17) | ||
| 568 | test_raw(200) | ||
| 569 | test_raw(4091) | ||
| 570 | test_raw(80199) | ||
| 571 | test_raw(8000000) | ||
| 572 | test_raw(80199) | ||
| 573 | test_raw(4091) | ||
| 574 | test_raw(200) | ||
| 575 | test_raw(17) | ||
| 576 | test_raw(1) | ||
| 577 | |||
| 578 | test("non-blocking transfer") | ||
| 579 | reconnect() | ||
| 580 | -- the value is not important, we only want | ||
| 581 | -- to test non-blocking I/O anyways | ||
| 582 | data:settimeout(200) | ||
| 583 | test_raw(1) | 619 | test_raw(1) |
| 584 | test_raw(17) | 620 | test_raw(17) |
| 585 | test_raw(200) | 621 | test_raw(200) |
diff --git a/test/testsrvr.lua b/test/testsrvr.lua index 969f95b..23e3850 100644 --- a/test/testsrvr.lua +++ b/test/testsrvr.lua | |||
| @@ -1,29 +1,14 @@ | |||
| 1 | socket = require"socket" | 1 | socket = require("socket"); |
| 2 | 2 | host = host or "localhost"; | |
| 3 | host = host or "localhost" | 3 | port = port or "8080"; |
| 4 | port = port or "8080" | 4 | server = assert(socket.bind(host, port)); |
| 5 | 5 | ack = "\n"; | |
| 6 | server, error = socket.bind(host, port) | ||
| 7 | if not server then print("server: " .. tostring(error)) os.exit() end | ||
| 8 | ack = "\n" | ||
| 9 | while 1 do | 6 | while 1 do |
| 10 | print("server: waiting for client connection..."); | 7 | print("server: waiting for client connection..."); |
| 11 | control, error = server:accept() | 8 | control = assert(server:accept()); |
| 12 | assert(control, error) | ||
| 13 | -- control:setoption("nodelay", true) | ||
| 14 | while 1 do | 9 | while 1 do |
| 15 | command, error = control:receive() | 10 | command = assert(control:receive()); |
| 16 | if error then | 11 | assert(control:send(ack)); |
| 17 | control:close() | 12 | (loadstring(command))(); |
| 18 | print("server: closing connection...") | ||
| 19 | break | ||
| 20 | end | ||
| 21 | sent, error = control:send(ack) | ||
| 22 | if error then | ||
| 23 | control:close() | ||
| 24 | print("server: closing connection...") | ||
| 25 | break | ||
| 26 | end | ||
| 27 | (loadstring(command))() | ||
| 28 | end | 13 | end |
| 29 | end | 14 | end |
