SWRU455M February 2017 – October 2020 CC3120 , CC3120MOD , CC3130 , CC3135 , CC3135MOD , CC3220MOD , CC3220MODA , CC3220R , CC3220S , CC3220SF , CC3230S , CC3230SF , CC3235MODAS , CC3235MODASF , CC3235MODS , CC3235MODSF , CC3235S , CC3235SF
In nonblocking mode, operations return immediately even if the data does not exist, or a connection is not established yet. It is the responsibility of the application to poll the operation until completion. When a server socket is configured as nonblocking, the accepted private socket inherits the nonblocking attribute. If there are several nonblocking sockets, TI recommends using sl_Select with time-out 0, instead of polling each socket separately.
The commands sl_Recv/ and sl_RecvFrom are unique, and allow nonblocking operation although the socket is in blocking mode. Two options are available for this mode.
An example of setting the socket as non-blocking:
_i16 Status;
SlSockNonblocking_t BlockingOption;
BlockingOption.NonBlockingEnabled = 1;
// Enable or disable non-blocking mode
Status = sl_SetSockOpt(Sd,SL_SOL_SOCKET,SL_SO_NONBLOCKING,(_u8*)&BlockingOption,sizeof(BlockingOption));
if( Status )
{
// error
}
An example of a non-blocking TCP connect:
_i16 Status;
SlSockAddrIn_t Addr;
Addr.sin_family = SL_AF_INET;
Addr.sin_port = sl_Htons(5001);
Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(192,168,1,31));
Status = SL_ERROR_BSD_EALREADY;
while( 0 > Status )
{
Status = sl_Connect(Sd, ( SlSockAddr_t *)&Addr, sizeof(SlSockAddr_t));
if( 0 > Status )
{
if( SL_ERROR_BSD_EALREADY != Status )
{
// errorbreak;
}
}
}
An example of receiving data with no wait flag:
_i16 Status;
_i8 RecvBuf[1460];
Status = sl_Recv(Sd, RecvBuf, 1460, SL_MSG_DONTWAIT);
if( (0 > Status) && (SL_ERROR_BSD_EAGAIN != Status) )
{
// error
}
An example of setting the receive data timeout:
_i16 Status;
struct SlTimeval_t TimeVal;
TimeVal.tv_sec = 5; // Seconds
TimeVal.tv_usec = 0; // Microseconds. 10000 microseconds resolution
Status = sl_SetSockOpt(Sd,SL_SOL_SOCKET,SL_SO_RCVTIMEO, (_u8 *)&TimeVal, sizeof(TimeVal)); // Enable receive timeoutif( Status )
{
// error
}