This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

accept() CC3000 freeze

Hello,

I'm running an accept() in a while loop after configuring a server.  After a successful connection, I receive data and close the connection.  It works well, but after ~10-13 connections, the CC3000 seems to stop responding.  It appears as though the accept() functions is non-blocking from when I run the program with the debugger.  When the CC3000 stops responding, the Tiva gets stuck in the hci_event_handler function by the if statement "if (tSLInformation.usEventOrDataReceived != 0)"

This makes me think that something is wrong with the CC3000 because the usEventOrDataReceived  is set when the SPI event handler receives communication from the CC3000.  

Here is the code that I run on startup.  I'm guessing that I am not closing my connections appropriately and causing the CC3000 to go out of whack.  I've been building off of the basic_wifi_application in TivaWare. 

Thanks,
Jackson

void serverconfig (void)
{
//
//socket locals
//
int32_t i32Check = 0;

//
//bind locals
//
uint32_t ui32Port = 0;
int8_t i8Check = 0;

//
//Listen/accept locals
//
uint8_t closeSuccess = 0;
socklen_t socketlength=sizeof(sockaddr);
char pui8Data[]="helloworld";
uint32_t ui32DataLength=strlen(pui8Data);
int32_t CommandCheck;

//
// Reset global socket type holder.
//
g_ui32SocketType = 0;

//
// Wait for DHCP process to finish. If you are using a static IP address
// please delete the wait for DHCP event - ulCC3000DHCP
//
while((g_ui32CC3000DHCP == 0) || (g_ui32CC3000Connected == 0))
{
hci_unsolicited_event_handler();

ROM_SysCtlDelay(1000);
}

//
// Open socket.
//
i32Check = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

//
// Set global variable that holds type of socket.
//
g_ui32SocketType = IPPROTO_TCP;

//
// Inform user of the socket being opened.
//
UARTprintf(" Socket is of type TCP\n");

//
// Error checking.
//
if(i32Check >= 0)
{
UARTprintf(" Socket Handle is '%d'\n",i32Check);
g_ui32Socket = i32Check;
}
else
{
UARTprintf(" Socket Function returned an error."
" Socket not opened. Error code %d.\n",i32Check);
g_ui32SocketType = 0;
return;
}

//
// Family is Always AF_INET on CC3000
//
g_tSocketAddr.sa_family = AF_INET;

//
// Set the port to bind the socket to.
//
ui32Port = DEFAULT_SERVER_PORT;
g_tSocketAddr.sa_data[0] = (ui32Port & 0xFF00) >> 8;
g_tSocketAddr.sa_data[1] = (ui32Port & 0x00FF) >> 0;

//
// Set IP to 0.0.0.0
//
memset (&g_tSocketAddr.sa_data[2], 0, 4);

//
// Low Level API call
//
i8Check = bind(g_ui32Socket, &g_tSocketAddr, sizeof(sockaddr));

if(i8Check == 0)
{
UARTprintf(" Bind Successful to port %d, 0x%x\n",
(g_tSocketAddr.sa_data[0] << 8) + g_tSocketAddr.sa_data[1],
(g_tSocketAddr.sa_data[0] << 8) + g_tSocketAddr.sa_data[1]);

//
// Set global flag variable to indicate the socket has been bound.
//
g_ui32BindFlag = 0;
}
else
{
UARTprintf(" Bind Failed. bind() returned code '%d'\n",i8Check);

//
// Set global flag variable to indicate the socket is not bound.
//
g_ui32BindFlag = SENTINEL_EMPTY;
}

//
//Listen for connection on TCP stream socket.
//
if(listen(g_ui32Socket,1))
{
UARTprintf(" Listen Failed.");
}
else
{
UARTprintf(" Listening.");
}

//
//Assign new socket for receiving info from client. Original socket
//is still listening.
//


//
//Loop over accept() function to address new clients.
//
while(1)
{
hci_unsolicited_event_handler();
i32Check=accept(g_ui32Socket, &g_tSocketAddr, &socketlength);

//
//If connection with client is successful, read data in and close
//socket immediately to wait for new connection.
//
if(i32Check>0)
{
UARTprintf(" Socket Handle is '%d'\n",i32Check);
g_ui32Socket_client1=i32Check;
receiveData();
CommandCheck=CmdLineProcess(g_pui8CC3000_Rx_Buffer);
if(CommandCheck == CMDLINE_BAD_CMD)
{
noCommand();
}
closeSuccess = closesocket(g_ui32Socket_client1);

//
// Error checking.
//
if(COMMAND_SUCCESS == closeSuccess)
{
UARTprintf(" Socket '%d' closed successfully.\n",g_ui32Socket_client1);
g_ui32Socket_client1 = SENTINEL_EMPTY;
}
else
{
UARTprintf(" Socket close Failed.\n");
g_ui32Socket_client1 = SENTINEL_EMPTY;
}
}
}


return(0);
}

  • Hi Jackson,

    This issue could sometimes occur due to the socket close (CLOSE_WAIT) events. Can you please try it by masking the event HCI_EVNT_BSD_TCP_CLOSE_WAIT?
    If the issue still persists, can you please give me the command/event traces at the host driver level?

    Also, can you please tell me the version of the Service Pack and the Host driver that you are using?
    Because, I see that you are periodically calling the 'hci_unsolicited_event_handler()'. You need not do this with the newer releases.

    Even though this may not the root cause for this issue. It is recommended that you move to the latest Host Driver/Service pack.

    Thanks & Regards,
    Raghavendra

  • How can I mask that event?  Do I add it to the init function wlan_set_event_mask()?

  • I added the event to wlan_set_event_mask command in the init function, but did not see any improvement.  Going with the same train of thought, I added a 1 second delay after attempting to close the socket.  This seems to have fixed the problem.  Still, I'm not sure why this is working the way that it is.  I've noticed two things:

    1. There is no noticeable delay between receiving information and my next connection.  

    2.  There is a noticeable delay between my connection occasionally.  Maybe 1 in 10 connections takes a delayed amount of time to finish connecting to the server.

    Any thoughts on this fix?  I'd like to have something a little more concrete for my final design.  Here's the accept loop:

    //
    //Loop over accept() function to address new clients.
    //
    while(1)
    {

    i32Check=accept(g_ui32Socket, &clientaddr, &socketlength);

    //
    //If connection with client is successful, read data in and close
    //socket immediately to wait for new connection.
    //
    if(i32Check>0)
    {
    UARTprintf(" Socket Handle is '%d'\n",i32Check);
    g_ui32Socket_client1=i32Check;
    receiveData();
    CommandCheck=CmdLineProcess(g_pui8CC3000_Rx_Buffer);
    if(CommandCheck == CMDLINE_BAD_CMD)
    {
    noCommand();
    }
    closeSuccess = closesocket(g_ui32Socket_client1);

    //
    // Error checking.
    //
    if(COMMAND_SUCCESS == closeSuccess)
    {
    UARTprintf(" Socket '%d' closed successfully.\n",g_ui32Socket_client1);
    g_ui32Socket_client1 = SENTINEL_EMPTY;
    }
    else
    {
    UARTprintf(" Socket close Failed.\n");
    g_ui32Socket_client1 = SENTINEL_EMPTY;
    }
    SysCtlDelay((SysCtlClockGet()/3)*1);
    }
    g_ui32Socket_client1 = SENTINEL_EMPTY;
    }

  • Turns out I have SP 1.24 = 1.11.1.  I'm posting separately about the update.  I'll ring this up to date when I have everything set up.