diff options
| author | Sam Roberts <vieuxtech@gmail.com> | 2012-04-11 14:18:20 -0700 |
|---|---|---|
| committer | Sam Roberts <vieuxtech@gmail.com> | 2012-04-11 14:18:20 -0700 |
| commit | 4b671f4551e98ac9e1d9a7407d3dffdd7eb1d3dc (patch) | |
| tree | ba92aa753ae1b145760cb1c5e69c886d3bf11328 /test | |
| parent | f399ab25fcecad2ff96a5977e8eaf069bb45473c (diff) | |
| parent | 195b2a74bb3f368b1f31f9c8bbc1ce0f54de2035 (diff) | |
| download | luasocket-4b671f4551e98ac9e1d9a7407d3dffdd7eb1d3dc.tar.gz luasocket-4b671f4551e98ac9e1d9a7407d3dffdd7eb1d3dc.tar.bz2 luasocket-4b671f4551e98ac9e1d9a7407d3dffdd7eb1d3dc.zip | |
Merge branch 'git-sam' into diego-sam-mwild-integration
Conflicts in options.c were just due to independent small functions
being close to each other.
unix.c in mwild was broken, it wasn't using LUASOCKET_API.
serial.c needed luaL_reg renamed, and to use LUASOCKET_API.
makefile didn't respect standard DESTDIR and prefix makefile
variables, and didn't allow LUAV variable to select lua version to build
against.
I've tested the top-level install-both target builds and installs
against both lua5.1 and lua5.2, but not done further testing.
Conflicts:
README
config
gem/ltn012.tex
makefile
src/makefile
src/options.c
src/options.h
src/tcp.c
src/usocket.c
Diffstat (limited to 'test')
| -rwxr-xr-x | test/find-connect-limit | 32 | ||||
| -rwxr-xr-x | test/tcp-getoptions | 41 | ||||
| -rw-r--r-- | test/testsrvr.lua | 7 | ||||
| -rwxr-xr-x | test/udp-zero-length-send | 25 | ||||
| -rwxr-xr-x | test/udp-zero-length-send-recv | 37 |
5 files changed, 141 insertions, 1 deletions
diff --git a/test/find-connect-limit b/test/find-connect-limit new file mode 100755 index 0000000..ad0c3f5 --- /dev/null +++ b/test/find-connect-limit | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | #!/usr/bin/env lua | ||
| 2 | --[[ | ||
| 3 | Find out how many TCP connections we can make. | ||
| 4 | |||
| 5 | Use ulimit to increase the max number of descriptors: | ||
| 6 | |||
| 7 | ulimit -n 10000 | ||
| 8 | ulimit -n | ||
| 9 | |||
| 10 | You'll probably need to be root to do this. | ||
| 11 | ]] | ||
| 12 | |||
| 13 | require "socket" | ||
| 14 | |||
| 15 | host = arg[1] or "google.com" | ||
| 16 | port = arg[2] or 80 | ||
| 17 | |||
| 18 | connections = {} | ||
| 19 | |||
| 20 | repeat | ||
| 21 | c = assert(socket.connect(hostip or host, 80)) | ||
| 22 | table.insert(connections, c) | ||
| 23 | |||
| 24 | if not hostip then | ||
| 25 | hostip = c:getpeername() | ||
| 26 | print("resolved", host, "to", hostip) | ||
| 27 | end | ||
| 28 | |||
| 29 | print("connection #", #connections, c, "fd", c:getfd()) | ||
| 30 | |||
| 31 | until false | ||
| 32 | |||
diff --git a/test/tcp-getoptions b/test/tcp-getoptions new file mode 100755 index 0000000..f9b3d1b --- /dev/null +++ b/test/tcp-getoptions | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | #!/usr/bin/env lua | ||
| 2 | |||
| 3 | require"socket" | ||
| 4 | |||
| 5 | port = 8765 | ||
| 6 | |||
| 7 | function options(o) | ||
| 8 | print("options for", o) | ||
| 9 | |||
| 10 | for _, opt in ipairs{"keepalive", "reuseaddr", "tcp-nodelay"} do | ||
| 11 | print("getoption", opt, o:getoption(opt)) | ||
| 12 | end | ||
| 13 | |||
| 14 | print("getoption", "linger", | ||
| 15 | "on", o:getoption("linger").on, | ||
| 16 | "timeout", o:getoption("linger").timeout) | ||
| 17 | end | ||
| 18 | |||
| 19 | local m = socket.tcp() | ||
| 20 | |||
| 21 | options(m) | ||
| 22 | |||
| 23 | assert(m:bind("*", port)) | ||
| 24 | assert(m:listen()) | ||
| 25 | |||
| 26 | options(m) | ||
| 27 | |||
| 28 | m:close() | ||
| 29 | |||
| 30 | local m = socket.bind("*", port) | ||
| 31 | |||
| 32 | options(m) | ||
| 33 | |||
| 34 | local c = socket.connect("localhost", port) | ||
| 35 | |||
| 36 | options(c) | ||
| 37 | |||
| 38 | local s = m:accept() | ||
| 39 | |||
| 40 | options(s) | ||
| 41 | |||
diff --git a/test/testsrvr.lua b/test/testsrvr.lua index 7ddff6e..ff31442 100644 --- a/test/testsrvr.lua +++ b/test/testsrvr.lua | |||
| @@ -7,7 +7,12 @@ while 1 do | |||
| 7 | print("server: waiting for client connection..."); | 7 | print("server: waiting for client connection..."); |
| 8 | control = assert(server:accept()); | 8 | control = assert(server:accept()); |
| 9 | while 1 do | 9 | while 1 do |
| 10 | command = assert(control:receive()); | 10 | command, emsg = control:receive(); |
| 11 | if emsg == "closed" then | ||
| 12 | control:close() | ||
| 13 | break | ||
| 14 | end | ||
| 15 | assert(command, emsg) | ||
| 11 | assert(control:send(ack)); | 16 | assert(control:send(ack)); |
| 12 | print(command); | 17 | print(command); |
| 13 | (load(command))(); | 18 | (load(command))(); |
diff --git a/test/udp-zero-length-send b/test/udp-zero-length-send new file mode 100755 index 0000000..a594944 --- /dev/null +++ b/test/udp-zero-length-send | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | #!/usr/bin/lua | ||
| 2 | |||
| 3 | --[[ | ||
| 4 | Show that luasocket returns an error message on zero-length UDP sends, | ||
| 5 | even though the send is valid, and in fact the UDP packet is sent | ||
| 6 | to the peer: | ||
| 7 | |||
| 8 | % sudo tcpdump -i lo -n | ||
| 9 | tcpdump: verbose output suppressed, use -v or -vv for full protocol decode | ||
| 10 | listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes | ||
| 11 | 13:40:16.652808 IP 127.0.0.1.56573 > 127.0.0.1.5432: UDP, length 0 | ||
| 12 | |||
| 13 | ]] | ||
| 14 | |||
| 15 | require"socket" | ||
| 16 | |||
| 17 | s = assert(socket.udp()) | ||
| 18 | r = assert(socket.udp()) | ||
| 19 | assert(r:setsockname("*", 5432)) | ||
| 20 | assert(s:setpeername("127.0.0.1", 5432)) | ||
| 21 | |||
| 22 | ssz, emsg = s:send("") | ||
| 23 | |||
| 24 | print(ssz == 0 and "OK" or "FAIL",[[send:("")]], ssz, emsg) | ||
| 25 | |||
diff --git a/test/udp-zero-length-send-recv b/test/udp-zero-length-send-recv new file mode 100755 index 0000000..541efd4 --- /dev/null +++ b/test/udp-zero-length-send-recv | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | #!/usr/bin/lua | ||
| 2 | |||
| 3 | --[[ | ||
| 4 | Show that luasocket returns an error message on zero-length UDP sends, | ||
| 5 | even though the send is valid, and in fact the UDP packet is sent | ||
| 6 | to the peer: | ||
| 7 | |||
| 8 | % sudo tcpdump -i lo -n | ||
| 9 | tcpdump: verbose output suppressed, use -v or -vv for full protocol decode | ||
| 10 | listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes | ||
| 11 | 13:40:16.652808 IP 127.0.0.1.56573 > 127.0.0.1.5432: UDP, length 0 | ||
| 12 | |||
| 13 | ]] | ||
| 14 | |||
| 15 | require"socket" | ||
| 16 | |||
| 17 | s = assert(socket.udp()) | ||
| 18 | r = assert(socket.udp()) | ||
| 19 | assert(r:setsockname("*", 5432)) | ||
| 20 | assert(s:setpeername("127.0.0.1", 5432)) | ||
| 21 | |||
| 22 | ok, emsg = s:send("") | ||
| 23 | if ok ~= 0 then | ||
| 24 | print("send of zero failed with:", ok, emsg) | ||
| 25 | end | ||
| 26 | |||
| 27 | assert(r:settimeout(2)) | ||
| 28 | |||
| 29 | ok, emsg = r:receive() | ||
| 30 | |||
| 31 | if not ok or string.len(ok) ~= 0 then | ||
| 32 | print("fail - receive of zero failed with:", ok, emsg) | ||
| 33 | os.exit(1) | ||
| 34 | end | ||
| 35 | |||
| 36 | print"ok" | ||
| 37 | |||
