|
From: | Hensel, Christian |
Subject: | [lwip-users] How do I handle the ETHERNET cable unplug/replug on the server side using LWIP in a correct way? |
Date: | Mon, 29 Aug 2022 16:16:06 +0000 |
Hi there,
your help on the following topic is highly appreciated! Thank You for any help!
How can I handle the unplug replug on the server side using LWIP?
SETUP: currently I try to get a server application on a STM32H7 running using freeRTOS 10.3 and LWIP 2.1.2. Code skleton is generated using CubeIDE 6.6 and H7 FW 1.10 CODE:
1) the MX_LWIP_Init() function generated by CubeIDE (see below for details) - setting the addresses and call back functions - starting the Ethernet thread
2) the physLinkTread - indicating the cable connection by a notification by static void ethernet_link_status_updated(struct netif *netif)
3) the serverThread calling the following functions in this order
listen_sock = lwip_socket() // listen_sock will be = 0 if successful
//
BaseType_t xTrueValue = pdTRUE;
setsockopt( listen_sock , SOL_SOCKET, SO_REUSEADDR , ( void * ) &xTrueValue, sizeof( xTrueValue )) // wait 10 sec for a client request to come in when accept was succsessful
struct timeval xRcvValue;
xRcvValue.tv_sec = 10U; xRcvValue.tv_usec = 0U; setsockopt( listen_sock , SOL_SOCKET, SO_RCVTIMEO , ( void * ) &xRcvValue, sizeof( xRcvValue )) lwip_bind(listen_sock) lwip_listen(listen_sock)
for(;;) { // will wait 10 sec for any connection request sock_connection = lwip_accept(listen_sock);
// will wait 4 sec for any client request to be handled read = lwip_read(sock_connection);
}// if (read) { // do somthing to serve the request ... } // lwip_shutdown(sock_connection, SHUT_RDWR); lwip_close(sock_connection);
MY PROBLEM:
I 've tested the ETHERNET cable unplug and (re)plug at the server side
- works fine when done while server is in lwip_accept() when continuing the shown for(;;) loop the next call of lwip_accept(listen_sock) will return 0
- fails when done while server is in lwip_read() when continuing the shown for(;;) loop the next call of lwip_accept(listen_sock) will return -1 when discontinuing the for loop just after read was executed and calling
lwip_shutdown(sock_connection, SHUT_RDWR);
lwip_close(sock_connection); lwip_shutdown(listen_sock, SHUT_RDWR);
lwip_closesocket(listen_sock);
the next call of listen_socklwip_socket() will return -1
What am I missing? ATTACHMENT:
MX_LWIP_Init():
tcpip_init( NULL, NULL );
/* IP addresses initialization without DHCP (IPv4) */ IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]); IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1] , NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]); IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]); /* add the network interface (IPv4/IPv6) with RTOS */ netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input); /* Registers the default network interface */ netif_set_default(&gnetif); if (netif_is_link_up(&gnetif)) { /* When the netif is fully configured this function must be called */ netif_set_up(&gnetif); } else { /* When the netif link is down this function must be called */ netif_set_down(&gnetif); } /* Set the link callback function, this function is called on change of link status*/ netif_set_link_callback(&gnetif, ethernet_link_status_updated);
Christian Hensel
|
[Prev in Thread] | Current Thread | [Next in Thread] |