Operation Modes
91
SWRU455A – February 2017 – Revised March 2017
Copyright © 2017, Texas Instruments Incorporated
Socket
6.7
Operation Modes
By default network bound APIs are blocking (network-bound APIs are APIs that trigger networking
transactions and waits for their completion). For some implementations, especially on non-OS platforms,
nonblocking operations are essential to allow other activities during these periods. For use cases, the
SimpleLink device supports the standard nonblocking method of BSD sockets, and also a proprietary
mode (trigger mode). In non-blocking mode, it is the responsibility of the application to poll the relevant
API until the operation is completed. However, in trigger mode, instead of polling the API, the host
receives an event when the operation is completed, and only then should call the API again.
describes the different modes of the relevant APIs.
Table 6-4. Operational Modes
API
TCP,
UDP,
RAW
Blocking Mode
Non-Blocking Mode
Trigger Mode
sl_Connect
TCP
Blocked until connect
success, or connect time-out.
Supported.
SL_ERROR_BSD_EALREADY error code
means not connected yet; poll again.
Not supported
sl_Recv/sl_
RecvFrom
TCP
Blocked until data arrives.
Recv Time-out can be set by
sl_SetSockOpt.
Supported. SL_ERROR_BSD_EAGAIN
error code means data has not arrived;
poll again.
Not supported
UDP
RAW
sl_Send/sl_
SendTo
TCP
Blocked until the internal
buffer is available.
Supported. SL_ERROR_BSD_EAGAIN
error code means no internal buffer
available; try to send again.
Not supported
UDP
RAW
sl_Accept
TCP
Blocked until client connects.
Supported. SL_ERROR_BSD_EAGAIN
error code means no client connection; try
to accept again.
Not supported
sl_Select
TCP
Blocked until one or more
registered sockets become
ready.
Supported
Supported
UDP
RAW
6.7.1 Nonblocking Mode
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.
•
A single call to sl_Recv or sl_RecvFrom in nonblocking mode by using the SL_MSG_DONTWAIT flag.
The API returns immediately with data if it exists or with the error SL_ERROR_BSD_EAGAIN. This
action does not affect any socket settings or the following calls to sl_Recv/ and sl_RecvFrom.
•
Setting receives a time-out. This setting applies for all the following calls to sl_Recv/ and sl_RecvFrom.
When time-out expires, sl_Recv and sl_RecvFrom returns with SL_ERROR_BSD_EAGAIN, or earlier if
the data arrives.
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 )
if
( Status )