samples: net: zperf: Fix only IPv4/only IPv6 build, better messages
The code couldn't really build with only CONFIG_NET_IPV4 or CONFIG_NET_IPV6 enabled, because some parts weren't covered by #ifdef's. Regroup the code to get it covered. Also, improve error/notice messages. Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
This commit is contained in:
parent
6f88c28487
commit
6bab4998ba
1 changed files with 27 additions and 23 deletions
|
@ -32,8 +32,12 @@
|
|||
static K_THREAD_STACK_DEFINE(zperf_rx_stack, RX_THREAD_STACK_SIZE);
|
||||
static struct k_thread zperf_rx_thread_data;
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
static struct sockaddr_in6 *in6_addr_my;
|
||||
#endif
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
static struct sockaddr_in *in4_addr_my;
|
||||
#endif
|
||||
|
||||
#define MAX_DBG_PRINT 64
|
||||
|
||||
|
@ -150,6 +154,7 @@ static void udp_received(struct net_context *context,
|
|||
frag = pkt->frags;
|
||||
|
||||
if (net_pkt_appdatalen(pkt) < sizeof(struct zperf_udp_datagram)) {
|
||||
printk(TAG "ERROR! short iperf packet!\n");
|
||||
net_pkt_unref(pkt);
|
||||
return;
|
||||
}
|
||||
|
@ -297,10 +302,13 @@ static void udp_received(struct net_context *context,
|
|||
/* RX thread entry point */
|
||||
static void zperf_rx_thread(int port)
|
||||
{
|
||||
struct net_context *context4 = NULL, *context6 = NULL;
|
||||
int ret, fail = 0;
|
||||
|
||||
printk(TAG "Listening to port %d\n", port);
|
||||
#if defined(CONFIG_NET_IPV4) && defined(MY_IP4ADDR)
|
||||
struct net_context *context4 = NULL;
|
||||
#endif
|
||||
#if defined(CONFIG_NET_IPV6) && defined(MY_IP6ADDR)
|
||||
struct net_context *context6 = NULL;
|
||||
#endif
|
||||
int ret;
|
||||
|
||||
#if defined(CONFIG_NET_IPV4) && defined(MY_IP4ADDR)
|
||||
ret = net_context_get(AF_INET, SOCK_DGRAM, IPPROTO_UDP, &context4);
|
||||
|
@ -319,6 +327,17 @@ static void zperf_rx_thread(int port)
|
|||
net_sprint_ipv4_addr(&in4_addr_my->sin_addr));
|
||||
|
||||
in4_addr_my->sin_port = htons(port);
|
||||
|
||||
if (context4) {
|
||||
ret = net_context_bind(context4,
|
||||
(struct sockaddr *)in4_addr_my,
|
||||
sizeof(struct sockaddr_in));
|
||||
if (ret < 0) {
|
||||
printk(TAG "Cannot bind IPv4 UDP port %d (%d)\n",
|
||||
ntohs(in4_addr_my->sin_port), ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_IPV6) && defined(MY_IP6ADDR)
|
||||
|
@ -339,7 +358,6 @@ static void zperf_rx_thread(int port)
|
|||
net_sprint_ipv6_addr(&in6_addr_my->sin6_addr));
|
||||
|
||||
in6_addr_my->sin6_port = htons(port);
|
||||
#endif
|
||||
|
||||
if (context6) {
|
||||
ret = net_context_bind(context6,
|
||||
|
@ -348,26 +366,10 @@ static void zperf_rx_thread(int port)
|
|||
if (ret < 0) {
|
||||
printk(TAG "Cannot bind IPv6 UDP port %d (%d)\n",
|
||||
ntohs(in6_addr_my->sin6_port), ret);
|
||||
|
||||
fail++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (context4) {
|
||||
ret = net_context_bind(context4,
|
||||
(struct sockaddr *)in4_addr_my,
|
||||
sizeof(struct sockaddr_in));
|
||||
if (ret < 0) {
|
||||
printk(TAG "Cannot bind IPv4 UDP port %d (%d)\n",
|
||||
ntohs(in4_addr_my->sin_port), ret);
|
||||
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
|
||||
if (fail > 1) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
ret = net_context_recv(context6, udp_received, K_NO_WAIT, NULL);
|
||||
|
@ -383,6 +385,8 @@ static void zperf_rx_thread(int port)
|
|||
}
|
||||
#endif /* CONFIG_NET_IPV4 */
|
||||
|
||||
printk(TAG "Listening on port %d\n", port);
|
||||
|
||||
k_sleep(K_FOREVER);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue