diff options
author | Diego Nehab <diego@impa.br> | 2012-08-23 19:31:15 -0300 |
---|---|---|
committer | Diego Nehab <diego@impa.br> | 2012-08-23 19:31:15 -0300 |
commit | 6368caeb5ab5f628b8021c8ebf4d6df436162aaf (patch) | |
tree | 2a2005f2e27ee81e8ced7e4fc84098728e106af0 /test | |
parent | 03ba06f70c9ad5cdc9b49d816490fc28d6dbbdc5 (diff) | |
download | luasocket-6368caeb5ab5f628b8021c8ebf4d6df436162aaf.tar.gz luasocket-6368caeb5ab5f628b8021c8ebf4d6df436162aaf.tar.bz2 luasocket-6368caeb5ab5f628b8021c8ebf4d6df436162aaf.zip |
Fix udp:setpeername("*")
There seems to be a curious difference between MacOS and
Linux and I am not sure if this is documented. When you
break a "connection" on Mac OS, you only eliminate the peer
association, but the local address remains bound. On Linux,
breaking a "connection" eliminates the binding to the local
address. Have you guys ever come accross this?
Another irritating difference is that connect() returns the
error EAFNOSUPPORT on Mac OS. I am going to ignore all
errors when the reason for calling connect() is simply to
break the "connection".
Diffstat (limited to 'test')
-rw-r--r-- | test/udpconnectclnt.lua | 19 | ||||
-rw-r--r-- | test/udpconnectsrvr.lua | 16 |
2 files changed, 35 insertions, 0 deletions
diff --git a/test/udpconnectclnt.lua b/test/udpconnectclnt.lua new file mode 100644 index 0000000..effe13a --- /dev/null +++ b/test/udpconnectclnt.lua | |||
@@ -0,0 +1,19 @@ | |||
1 | local socket = require"socket" | ||
2 | local udp = socket.udp | ||
3 | local localhost = "127.0.0.1" | ||
4 | local port = arg[1] | ||
5 | |||
6 | se = udp(); se:setoption("reuseaddr", true) | ||
7 | se:setsockname(localhost, 5062) | ||
8 | print("se", se:getsockname()) | ||
9 | sc = udp(); sc:setoption("reuseaddr", true) | ||
10 | sc:setsockname(localhost, 5061) | ||
11 | print("sc", sc:getsockname()) | ||
12 | |||
13 | se:sendto("this is a test from se", localhost, port) | ||
14 | socket.sleep(1) | ||
15 | sc:sendto("this is a test from sc", localhost, port) | ||
16 | socket.sleep(1) | ||
17 | se:sendto("this is a test from se", localhost, port) | ||
18 | socket.sleep(1) | ||
19 | sc:sendto("this is a test from sc", localhost, port) | ||
diff --git a/test/udpconnectsrvr.lua b/test/udpconnectsrvr.lua new file mode 100644 index 0000000..5a9772e --- /dev/null +++ b/test/udpconnectsrvr.lua | |||
@@ -0,0 +1,16 @@ | |||
1 | local socket = require"socket" | ||
2 | local udp = socket.udp | ||
3 | local localhost = "127.0.0.1" | ||
4 | local s = assert(udp()) | ||
5 | assert(tostring(s):find("udp{unconnected}")) | ||
6 | print("setpeername", s:setpeername(localhost, 5061)) | ||
7 | print("getsockname", s:getsockname()) | ||
8 | assert(tostring(s):find("udp{connected}")) | ||
9 | print(s:receive()) | ||
10 | print("setpeername", s:setpeername("*")) | ||
11 | print("getsockname", s:getsockname()) | ||
12 | s:sendto("a", localhost, 12345) | ||
13 | print("getsockname", s:getsockname()) | ||
14 | assert(tostring(s):find("udp{unconnected}")) | ||
15 | print(s:receivefrom()) | ||
16 | s:close() | ||