SOLVED --- Need process steps to re-start NetX

I am using SSP 1.3.3 and I have de-selected the auto initialization process for NetX.  I need to build a bullet proof system that can recover from errors such as cables unplugged, noise, etc.

I can start NetX OK, I discover the cable connection OK.  I serve web pages OK.  My application works fine.

The problem comes when I detect the cable disconnected.  At that point I would prefer to unwind the start up process and totally re-initialize NetX (fresh start)

Received help from Synergy team and here is the process to manually start / restart NetX and associated services:

  • Basically the steps are to initialize each process you will use
  • Then let your application use the processes in its work
  • When you detect errors or need to restart:
    • You must unwind the processes in their order by stop, then delete them
    • Clear memory allocated to the pool and IP instance as needed
  • Once you have completely unwound the processes then you can initialize and start again

Here is how I manually initialize and start my processes (part actual code, part comments):

nx_common_init0(); // void function initializes the internal threads and structures
packet_pool_init0(); // void function that inits the packet pool as configured in SSC
ip_init0(); // void function that inits the TCIP as configured in SSC

// make sure the network has started OK ...
mNetErr = nx_ip_interface_status_check(&g_ip0, NET_INDEX_0, NX_IP_INITIALIZE_DONE, (ULONG *)&mCurrentNetStatus, NX_NO_WAIT);
if((mNetErr == NX_SUCCESS) && (mCurrentNetStatus == NX_IP_INITIALIZE_DONE)) // init is done go to next step ...
{
      mWaitForCableLoopCount = 0; // try for a while, then restart if no cable
      SdNetState = SD_NET_WAITING_FOR_CABLE;
}
else
      SdNetState = SD_NET_RESTART_ALL; // DHCP did not give us an IP address so start over again

next I wait for the cable to be attached ...

if(isCableAttached() == true) // link is UP !!!
{
    mIsContinue = true; // must remain true to complete the proceeses below
    // create an instance of the DHCP service
    if(mIsContinue == true) {mDhcpStatus = nx_dhcp_create(&g_dhcp_client0,&g_ip0, "SdDhcp"); NET_SUCCESS_ERR_IS_CONTINUE_TRAP(mDhcpStatus)}
    // Register a DHCP state change callback function.
    if(mIsContinue == true) {mDhcpStatus = nx_dhcp_state_change_notify(&g_dhcp_client0, DhcpNotifyCallBack);    NET_SUCCESS_ERR_IS_CONTINUE_TRAP(mDhcpStatus)}
    // Now we're ready to start the DHCP Client.
    if(mIsContinue == true) {mDhcpStatus = nx_dhcp_start(&g_dhcp_client0); NET_SUCCESS_ERR_IS_CONTINUE_TRAP(mDhcpStatus)}
    if(mIsContinue == true)
    {
        mWaitForIpAddrLoopCount = 0;
        mIsBoundToIpAddr = NX_FALSE;
        SdNetState = SD_NET_WAITING_FOR_IP_ADDRESS;
    }
    else // failed to get DHCP going properly ...
        SdNetState = SD_NET_RESTART_ALL; // DHCP did not give us an IP address so start over again
}

Next I wait for an IP address from DHCP- code not shown

After I get an IP address I start the http server service:

mNetErr = nx_http_server_create(&g_http_server0,
        "g_http_server0 HTTP Server",
        &g_ip0,
        &g_fx_media0,
        &g_http_server0_stack_memory[0],
        4096,
        &g_packet_pool0,
        NULL,
        request_notify);
if( mNetErr == NX_SUCCESS )
{
    mNetErr = nx_http_server_start(&g_http_server0); // start the server
    if( mNetErr == NX_SUCCESS )
    {
        gNetworkState = NET_ROCK_AND_ROLL; // tell the world our current state
        SdNetState = SD_NET_ROCK_AND_ROLL; // service requests and send periodic logs as needed
    }
    else // failed to start
        SdNetState = SD_NET_RESTART_ALL; // DHCP did not give us an IP address so start over again
    }
}

Now my application does its thing serving web pages, responding to CGI forms etc.

If I see the cable unplugged or any other error I need to unwind and restart.

Here is the unwind:

// unwind all processes, init net variables, and start again
mNetErr = nx_http_server_stop(&g_http_server0); NET_SUCCESS_ERR_TRAP(mNetErr)
mNetErr = nx_http_server_delete(&g_http_server0); NET_SUCCESS_ERR_TRAP(mNetErr)
mNetErr = nx_dhcp_stop(&g_dhcp_client0); NET_SUCCESS_ERR_TRAP(mNetErr)
mNetErr = nx_dhcp_delete(&g_dhcp_client0); NET_SUCCESS_ERR_TRAP(mNetErr)
memset(&g_dhcp_client0, 0, sizeof(g_dhcp_client0));
mNetErr = nx_ip_delete(&g_ip0); NET_SUCCESS_ERR_TRAP(mNetErr)
memset(&g_ip0, 0, sizeof(g_ip0));
mNetErr = nx_packet_pool_delete(&g_packet_pool0); NET_SUCCESS_ERR_TRAP(mNetErr)
memset(&g_packet_pool0, 0, sizeof(g_packet_pool0));
SdNetState = SD_NET_POWER_ON;
break;

Then I go back to the initialize and startup code listed above ...

I have tried to break the system and so far this seems to be very robust and reliable.

Hope this helps others who might need to do this

Thanks Warren and Janet for your prompt help !!!  You guys are great !!!

Long live Synergy ....