Ip object delete error with two interfaces

Hello,

 

I got an error sometimes when I disable all my IP stack while trying to delete the IP object. The error code is NX_SOCKETS_BOUND.

I don't understand why I got this, i disable and delete all the ip services first though...

 

void net_stop_all()
{
net_wifi_close();
net_http_server_stop();
net_dhcp_server_stop();
net_dhcp_client_stop();
net_ip_stop();

}

 

void net_wifi_close()
{
if(wifi_on)
{
do
{
result = g_sf_wifi0.p_api->close(g_sf_wifi0.p_ctrl);
tx_thread_sleep (50);
}
while(result != SSP_SUCCESS && result != SSP_ERR_NOT_OPEN);
wifi_on = 0;
}
}

 

void net_http_server_stop()
{
if(http_server_initialized)
{
result = nx_http_server_stop(&g_http_server0);
tx_thread_sleep (50);
result = nx_http_server_delete(&g_http_server0);
tx_thread_sleep (50);
memset(&g_http_server0, 0, sizeof(g_http_server0));
http_server_initialized = 0;
}
}

void net_dhcp_server_stop()
{
if(dhcp_server_initialized)
{
result = nx_dhcp_server_stop(&g_dhcp_server0);
tx_thread_sleep (50);
result = nx_dhcp_server_delete(&g_dhcp_server0);
tx_thread_sleep (50);
memset(&g_dhcp_server0, 0, sizeof(g_dhcp_server0));
//result = g_wifi_stack.dhcpServerStop(g_wifi_stack_ctrl);
dhcp_server_initialized = 0;
}

}

void net_dhcp_client_stop()
{
if(wdhcp_client_on)
{
/* Start the DHCP Client on the secondary interface. */
result = nx_dhcp_interface_stop(&g_dhcp_client1, 0);
tx_thread_sleep (50);
result = nx_dhcp_interface_disable(&g_dhcp_client1, 0);
tx_thread_sleep (50);
wdhcp_client_on = 0;
}
if(edhcp_client_on)
{
result = nx_dhcp_interface_stop(&g_dhcp_client1, 1);
tx_thread_sleep (50);
result = nx_dhcp_interface_disable(&g_dhcp_client1, 1);
tx_thread_sleep (50);
edhcp_client_on = 0;
}
if(dhcp_client_initialized)
{
result = nx_dhcp_stop(&g_dhcp_client1);
tx_thread_sleep (50);
result = nx_dhcp_delete(&g_dhcp_client1);
tx_thread_sleep (50);
memset(&g_dhcp_client1, 0, sizeof(g_dhcp_client1));
dhcp_client_initialized = 0;
}
}

 

void net_ip_stop()
{
if(ip_initialized)
{
do{
result = nx_ip_delete(&g_ip1);
tx_thread_sleep (50);
memset(&g_ip1, 0, sizeof(g_ip1));
}
while(result != 0);
result = nx_packet_pool_delete(&g_packet_pool0);
tx_thread_sleep (50);
memset(&g_packet_pool0, 0, sizeof(g_packet_pool0));
ip_initialized = 0;
}
}

 

Sorry for the bad code format, i don't know how to make the code look better here :s

 

thanks in advance for any tips :)

 

Have a nice day,

 

Clément.

  • Clement,

    First, I assume you checked all the return status calls for successful result. Assuming no errors, all the NetX application "stop()" APIs unbind or release the port unless an error occurs and the service aborts.

    Note that if the DHCP Client is running on at least one other interface, nx_dhcp_interface_stop will not unbind the socket port. Looking at how you toggle dhcp_client_initialized , edhcp_client_initialized , and wdhcp_client_initialized that seems like the most likely culprit.

    Janet
  • Hello Janet,

    Indeed, I checked in debug mode the value of all the results. And no errors except when I delete the IP object. I highly suspect it have something to do with the dhcp client running on both interface that the problem occurs, your suggestion is likely the problem ! :) Can you help me again by explaining me how I can successfully unbind all the socket port before stoping both interfaces ?

    Thanks a lot for your answer and for your future answer !

    Have a nice day !

    Clément.
  • Clement

    I took another look at the nx_ip_delete code and I see now that it is not actually 'ports bound' that is the problem, it is the sockets not yet deleted. NetX requires that you delete the sockets before deleting the IP instance.

    If that is a problem, we could discuss whether you actually need to delete the IP instance at all. Anyway, try deleting all the sockets and see if the problem goes away.

    Janet
  • Hi Janet,

    Just how in the world do I delete these sockets ?
    I'm sorry, I just don't know what netx function to use here...

    Please help,

    Thank you !
  • Clement,

    You just need to call two API. nx_dhcp_delete() calls nx_udp_socket_delete, and nx_http_server_delete() calls nx_tcp_socket_delete(). My apologies for omitting that detail. Now it should work fine.

    Janet
  • Janet,

    Thanks a lot for your understanding and explanation ! :)
    So if I do something like that it should works ?

    result = nx_http_server_stop(&g_http_server0);
    tx_thread_sleep (10);
    result = nx_tcp_socket_delete(&g_http_server0.nx_http_server_socket);
    tx_thread_sleep (10);
    result = nx_http_server_delete(&g_http_server0);
    tx_thread_sleep (10);
    memset(&g_http_server0, 0, sizeof(g_http_server0));
    http_server_initialized = 0;

    result = nx_dhcp_stop(&g_dhcp_client1);
    tx_thread_sleep (10);
    result = nx_udp_socket_delete(&g_dhcp_client1.nx_dhcp_socket);
    tx_thread_sleep (10);
    result = nx_dhcp_delete(&g_dhcp_client1);
    tx_thread_sleep (10);
    memset(&g_dhcp_client1, 0, sizeof(g_dhcp_client1));
    dhcp_client_initialized = 0;

    Is it okay like that ?
    Is there some socket to close with the dhcp server too ?

    Thanks again,

    CLément.

     

    EDIT :

    Tried this code, with also a socket delete for udp dhcp server socket but same problem...

  • Clement,

    Omit the nx_udp_socket_delete and nx_tcp_socket_delete calls before calling the delete the DHCP and HTTP functions, respectively. The nx_dhcp_delete and nx_http_server_delete will call them for you.

    And yes, nx_dhcp_server_delete() will delete the UDP socket of the DHCP server.

    Regards,
    Janet
  • Janet,

    So you're telling me that it's not the problem in my code in that case... I call nx_dhcp_delete, nx_dhcp_server_delete, and nx_http_server_delete respectively since the begining of the problem...
    So my error at Ip_delete should come from somewhere else in that case isn't it ?

    Do you have any other ideas ?

    Thanks,

    CLément.
  • Clement,

    Has your application created any other sockets or NetX application instances?

    If not, the nx_udp_socket_delete() and nx_tcp_socket_delete() calls will fail if the socket is still bound.

    If you have access to NetX source code, add it to your project and step into the nx_udp_socket_delete() and nx_tcp_socket_delete() to make sure they succeed. Unfortunately the nx_dhcp_delete, nx_dhcp_server_delete() and nx_http_server_delete() do not check status return on deleting the socket.

    NX_SOCKETS_BOUND is only returned by nx_ip_delete() and only if there are still sockets not deleted.

    Janet
  • Hi Janet,

    I just forgot I had one custom http client I use...

    I'll try to check if the bug remain when I disable this http client.

    I'll keep in touch with you about that.

    Thanks a lot,

    Clément.