SWRU368C May 2018 – January 2021 CC3100 , CC3100MOD , CC3200 , CC3200MOD
Depending on the implementation, choose to run the application with or without OS. Normally, when the application is run without OS, set the socket option to nonblocking with sl_SetSockOpt() with the third parameter as SL_SO_NONBLOCKING. An OS-based application, however, has the option to perform multithreading and can handle blocking functions.
Status = sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_NONBLOCKING,
&nonBlockingValue, sizeof(nonBlockingValue)) ;
If the blocking mechanism is used, these functions block until execution is finished.
If the nonblocking mechanism is used, these functions return with an error code. The value of the error codes depends the function used. For details, see the online documentation.
sl_Connect(), sl_Accept(), sl_Aend(), sl_Aendto(), sl_Recv(), and sl_Recvfrom() are affected by this flag. If not set, the default is blocking.
An example with sl_Connect() on a client application:
Status = sl_Connect(SockID, ( SlSockAddr_t *) &Addr, AddrSize);
while( Status < 0 )
{
Status = sl_Connect(SockID, ( SlSockAddr_t *)&Addr, AddrSize);
if( Status == SL_EALREADY )
{
/* Wait for 1 ms before the next retry */
Delay(1);
}
else if( Status < 0 )
{
return -1; //Error
}
/* Perform other tasks before we retry the connection */
}