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.

Example code for non blocking TCP Socket

Other Parts Discussed in Thread: CC3100MODBOOST, CC3100

Hello all,

I am encountering some issues using non-blocking TCP socket with the CC3100MODBOOST in the client project.

When I switch to non blocking, sl_Send return -1 each call.

Can someone provide me an example which can show me how to use non blocking TCP socket in a client project ?

Thanks in advance

  • Hi Clement,

    Thanks for your question. Take a look at these projects: OTA, p2p, TCP, and webserver since these use non blocking.

    Best,

    Austin
  • Hi Austin,

    Thanks for your reply.
    I take a look at those projects, but I do not see anything related to "non blocking TCP socket".
    Can you show me what part of the code I have to focus on ?

    thank you in adavance

    Clement
  • Hi,

    Try this:

    int send(int socket, const void *buf, int len) {
      int timeout = 1000;
      int retVal;
      while (1) {
        retVal = sl_Send(socket, buf, len, 0);
        if (retVal != SL_EAGAIN) break;
        osi_Sleep(1);
        if ((timeout--) <= 0) return -1;
      }
      if (retVal < 0) return -2;
      return 0;
    }


    Jan

  • Hi Jan,

    Thank for you reply.

    I tried your code snippet. The return is always -2.

    I do not use any RTOS in my project, I had to replace osi_Sleep by :

    _SlNonOsMainLoopTask();
    for (i=0 ; i<4500 ; i++);
    _SlNonOsMainLoopTask();

  • Hi,

    Hmm... I expect that something else you have wrong. Is always retVal -1 as you wrote at your first post? How long is your delay for()? I expect very short. Maybe even this delay for() not working properly, due to compiler optimizations.


    Jan
  • You sl_Send always return -1 when I call it alone. From your funtion it is -2.

    My delay is approximately 1ms. You are right, compiler may interfere.

    I first try to disable optimization on compiler : same result.

    Then I replaced my "for" by (optimization still disabled) :

    uint16_t tab[10];
    int j = 0;
    for (i=0 ; i<4500 ; i++)
    {
    	tab[++j] = tab[j] + 1;
    	if (j == 9)
    	j = 0;
    }

    The result is again -2.

  • Hi,

    I think something else is wrong in your code. Unfortunately I am not able determine issue. Do you have latest SDK with latest service pack?


    Jan
  • Hi,

    Yes I have the lastest SDK and the CC3100 up to date.

  • I have found my issue.

    I keep the same code for socket connection from blocking mode to non blocking. So I try to send data whereas i am not connected to a server !

    Thanks for your help !