Operation Modes
94
SWRU455A – February 2017 – Revised March 2017
Copyright © 2017, Texas Instruments Incorporated
Socket
LocalAddr.sin_family = SL_AF_INET;
LocalAddr.sin_port = sl_Htons(5001);
LocalAddr.sin_addr.s_addr = 0;
timeVal.tv_sec = 0;
timeVal.tv_usec = 0;
//Open TCP server socket
Sd = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
if
( Status )
{
// error
}
//Bind the server socket
Status = sl_Bind(Sd, (SlSockAddr_t *)&LocalAddr,
sizeof
(SlSockAddrIn_t));
if
( Status )
{
// error
}
//Listen
Status = sl_Listen(Sd, 0);
if
( Status )
{
// error
}
nfds = Sd + 1;
SL_SOCKET_FD_ZERO( &rxSet );
SL_SOCKET_FD_SET( Sd, &rxSet );
Status = sl_Select( nfds, &rxSet, NULL, NULL, &timeVal );
if
( Status )
{
// error
}
2. The host now can enter deep sleep until triggered by the select event.
3. After the SL_SOCKET_TRIGGER_EVENT_SELECT event is received, the host wakes up and calls
sl_Select to identify which socket has network activity.
//Call select again since the trigger event has arrived (see handler example above)
SL_SOCKET_FD_ZERO( &rxSet );
SL_SOCKET_FD_SET( Sd,& rxSet );
Status = sl_Select( nfds, &rxSet, NULL, NULL, &timeVal );
if
(SL_SOCKET_FD_ISSET(Sd, &rxSet))
{
//socket is marked, call accept
LocalSd = sl_Accept(Sd, (SlSockAddr_t*)&Addr, (SlSocklen_t*) (
sizeof
(SlSockAddrIn_t)));
}
6.7.2.2
Trigger Mode for Data Reception
1. Open the TCP client socket and call sl_Select on the following socket.
_i16 Status, Sd;
_u16 nfds;
SlSockAddrIn_t Addr;
SlTimeval_t timeVal;
SlFdSet_t
rxSet;
_i8
RecvBuf[1460];
timeVal.tv_sec = 0;
timeVal.tv_usec = 0;
//Open TCP client socket
Sd = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
if
( Status )