diff options
author | Sam Roberts <vieuxtech@gmail.com> | 2011-08-08 16:49:20 -0700 |
---|---|---|
committer | Sam Roberts <vieuxtech@gmail.com> | 2012-04-11 13:45:59 -0700 |
commit | c37f71d062379ff4f48658cddd724b94df20fb66 (patch) | |
tree | d71ae907fa73e2818f06abf2366fc90bc3764dcd | |
parent | 51acb54760dc91095d59839e8ea2256557f42781 (diff) | |
download | luasocket-c37f71d062379ff4f48658cddd724b94df20fb66.tar.gz luasocket-c37f71d062379ff4f48658cddd724b94df20fb66.tar.bz2 luasocket-c37f71d062379ff4f48658cddd724b94df20fb66.zip |
Test showing failure to receive a zero-length packet.
-rwxr-xr-x | test/udp-zero-length-send-recv | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/udp-zero-length-send-recv b/test/udp-zero-length-send-recv new file mode 100755 index 0000000..7d76c98 --- /dev/null +++ b/test/udp-zero-length-send-recv | |||
@@ -0,0 +1,35 @@ | |||
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 | ok, emsg = r:receive() | ||
28 | |||
29 | if not ok or string.len(ok) ~= 0 then | ||
30 | print("receive of zero failed with:", ok, emsg) | ||
31 | end | ||
32 | |||
33 | print"ok" | ||
34 | |||
35 | |||