From 3a7ae03f7914cc8912adbdf72c011a5e8a551d78 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Mon, 17 Oct 2016 13:12:42 +0200 Subject: [PATCH] lxip/udp_client: create new socket on every run Instead of creating one socket and re-using it each test run because the client shall also test the termination of pseudo-connections at components that implement hole punching for UDP. Ref #2139 --- .../src/test/lxip/udp_client/main.cc | 47 +++++++------------ 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/repos/dde_linux/src/test/lxip/udp_client/main.cc b/repos/dde_linux/src/test/lxip/udp_client/main.cc index 3bae2d04f..ee8f660cf 100644 --- a/repos/dde_linux/src/test/lxip/udp_client/main.cc +++ b/repos/dde_linux/src/test/lxip/udp_client/main.cc @@ -30,38 +30,27 @@ int main(void) { int s; static Timer::Connection _timer; - _timer.msleep(2000); - log("Create new socket ..."); - if((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - error("No socket available!"); - return -1; - } - log("Now, I will bind ..."); - struct sockaddr_in in_addr; - in_addr.sin_family = AF_INET; - in_addr.sin_port = htons(49252); - in_addr.sin_addr.s_addr = INADDR_ANY; - if(bind(s, (struct sockaddr*)&in_addr, sizeof(in_addr))) { - error("bind failed!"); - return -1; - } - enum { ADDR_STR_SZ = 16 }; - char serv_addr[ADDR_STR_SZ] = { 0 }; - Xml_node libc_node = config()->xml_node().sub_node("libc"); - try { libc_node.attribute("server_ip").value(serv_addr, ADDR_STR_SZ); } - catch(...) { - error("Missing \"server_ip\" attribute."); - throw Xml_node::Nonexistent_attribute(); - } - unsigned port = 0; - try { libc_node.attribute("server_port").value(&port); } - catch (...) { - error("Missing \"server_port\" attribute."); - throw Xml_node::Nonexistent_attribute(); - } log("Start the client loop ..."); for(int j = 0; j != 5; ++j) { _timer.msleep(2000); + if((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + error("No socket available!"); + return -1; + } + enum { ADDR_STR_SZ = 16 }; + char serv_addr[ADDR_STR_SZ] = { 0 }; + Xml_node libc_node = config()->xml_node().sub_node("libc"); + try { libc_node.attribute("server_ip").value(serv_addr, ADDR_STR_SZ); } + catch(...) { + error("Missing \"server_ip\" attribute."); + throw Xml_node::Nonexistent_attribute(); + } + unsigned port = 0; + try { libc_node.attribute("server_port").value(&port); } + catch (...) { + error("Missing \"server_port\" attribute."); + throw Xml_node::Nonexistent_attribute(); + } struct sockaddr_in addr; addr.sin_family = AF_INET; socklen_t len = sizeof(addr);