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.

Blocking TCP Server fault‏

Other Parts Discussed in Thread: CC3100

The components I'm working on them : CC3100 + Tiva C .

I am connectig to the AccessPoint and creating a blocking TCP Server socket.
I have a client software which connects to my server socket.

all works fine till I added a local variable (long nonBlocking= 1; -- preparing in order to do non-blocking socket)and since then I get a fault  every time the client connects.
here is my code :


void TcpServer() {
    SlSockAddrIn_t Addr;
    SlSockAddrIn_t LocalAddr;

    int AddrSize = sizeof(SlSockAddrIn_t);
    int SockID, newSockID;
    int Status;
    char Recvbuff[20];
    long
nonBlocking= 1;

    LocalAddr.sin_family = SL_AF_INET;
    LocalAddr.sin_port = sl_Htons((UINT16) 6000);
    LocalAddr.sin_addr.s_addr = 0;

    Addr.sin_family = SL_AF_INET;
    Addr.sin_port = sl_Htons((UINT16) 6000);
    Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,0,0,2));

    SockID = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, 0);
    Status = sl_Bind(SockID, (SlSockAddr_t *) &LocalAddr, AddrSize);
    Status = sl_Listen(SockID, 0);

 newSockID = sl_Accept(SockID, ( struct SlSockAddr_t *)&Addr,(SlSocklen_t*) &AddrSize);

while (1) {

        memset(Recvbuff, 0, sizeof(Recvbuff));
        Status = sl_Recv(newSockID, Recvbuff, 20, 0);

        if (Status > 0) {
            Recvbuff[Status] = '\0';

            if (strcmp(&Recvbuff[2], "end") == 0) {
                Status = sl_Send(newSockID, Recvbuff, Status, 0);
                sl_Close(newSockID);
                sl_Close(SockID);

                break;
            }
        }

        Status = sl_Send(newSockID, Recvbuff, Status, 0);
    }
}
 I looked at the registers map and I see :

NVIC_FAULT_STAT  = 0x00009200

 

I'm stuck and I'm waiting for a way to progress

thanks

  • Haya, so just defining a variable causes the code to stat showing failures?

    Well, I would assume adding a new variable increases the stack usage slightly and it is likely that the stack overflows. Are you able to increase the stack size and see if it makes a difference?

  • Hi Haya,

    Your code isn't written correctly to handle unblocking sockets.

    You should be polling on sl_Accept() waiting for incoming connections before continuing to handle the child socket.

    In non blocking the accept will return immediately and newSockID will be equal to SL_EAGAIN (negative value).

    In your code you are not handling that and you will try to call sl_recv() on a non existing socket ID.

     

    Please refer to our new programmers guide document in: http://www.ti.com/lit/pdf/swru368

     

    In general this is how you need to handle non blocking accept (taken from the document, in TCP connection chapter):

     

    long nonBlocking = 1;
    int  newSockID;
    Status = sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlocking, sizeof(nonBlocking));
     
    while( newSockID < 0 )
    {
        newSockID = sl_Accept(SockID, ( struct SlSockAddr_t *)&Addr,(SlSocklen_t*)&AddrSize);
        if( newSockID == SL_EAGAIN )
        {
            /* Wait for 1 ms */
            Delay(1);
        }
        else if( newSockID < 0 )
        {
            return -1;
        }
    }

    If the problem persists, please also try debugging it step by step to see which API call is causing the assertion.

    In addition, I would recommend to add code checking the API return values, handling error cases, it will make your application more robust.

    Thanks,
    Alon

  • The problem was actually the size of the stack ,it was too small.

    Project properties -> ARM linker -> by default stack size is 500. I increase to 2048.