From 6368caeb5ab5f628b8021c8ebf4d6df436162aaf Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Thu, 23 Aug 2012 19:31:15 -0300 Subject: 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". --- test/udpconnectclnt.lua | 19 +++++++++++++++++++ test/udpconnectsrvr.lua | 16 ++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/udpconnectclnt.lua create mode 100644 test/udpconnectsrvr.lua (limited to 'test') 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 @@ +local socket = require"socket" +local udp = socket.udp +local localhost = "127.0.0.1" +local port = arg[1] + +se = udp(); se:setoption("reuseaddr", true) +se:setsockname(localhost, 5062) +print("se", se:getsockname()) +sc = udp(); sc:setoption("reuseaddr", true) +sc:setsockname(localhost, 5061) +print("sc", sc:getsockname()) + +se:sendto("this is a test from se", localhost, port) +socket.sleep(1) +sc:sendto("this is a test from sc", localhost, port) +socket.sleep(1) +se:sendto("this is a test from se", localhost, port) +socket.sleep(1) +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 @@ +local socket = require"socket" +local udp = socket.udp +local localhost = "127.0.0.1" +local s = assert(udp()) +assert(tostring(s):find("udp{unconnected}")) +print("setpeername", s:setpeername(localhost, 5061)) +print("getsockname", s:getsockname()) +assert(tostring(s):find("udp{connected}")) +print(s:receive()) +print("setpeername", s:setpeername("*")) +print("getsockname", s:getsockname()) +s:sendto("a", localhost, 12345) +print("getsockname", s:getsockname()) +assert(tostring(s):find("udp{unconnected}")) +print(s:receivefrom()) +s:close() -- cgit v1.2.3-55-g6feb