Other Parts Discussed in Thread: CC3235MODSF,
Hello all,
I am developing an application as a TCP client using the following components:
Custom hardware with CC3235MODSF
SIMPLELINK-CC32XX-SDK Version: 5.10.00.02
Service Pack Version: 4.1.0.28
The aim is to be able to receive data from the socket as fast as possible. The size of the data that will come from the TCP server is not constant. The communication on the socket is full duplex. So, the data from the TCP server might be received at anytime and also the TCP client can send data at anytime.
Due to these requirements, I am assuming I have to use a thread to either poll the socket very frequently or block the socket until 1 byte is received. If I poll the socket as frequent as I require, the MCU is late for processing other operations within other threads with lower priority. If I block the socket, only after that one byte is received I set the socket non-blocking and receive rest of the data bytes. However, that is also not fast enough as I can see from my debug timings.
Here are the functions that I call for these two different ways:
/* Create a client socket. */
sl_Socket(SL_AF_INET, SL_SOCK_STREAM, 0);
/* Try to connect to server. */
sl_Connect(sd, (SlSockAddr_t *)&addr, sizeof(SlSockAddr_t));
/* Set socket as non-blocking. */
nonBlocking = TRUE;
rs = sl_SetSockOpt(sd, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlocking, sizeof(nonBlocking));
/* Begin receiving loop. */
while(1)
{
/* Try receiving first byte several times. */
for(i = 0 ; i < 100 ; i++)
{
/* Check socket to receive first byte. */
rs = sl_Recv(sd, gp_buff, 1, SL_MSG_DONTWAIT);
/* Check if there is no data. */
if(SL_ERROR_BSD_EAGAIN == rs)
{
/* Sleep to try again later. */
usleep(1000);
}
else
{
/* Break the for loop. */
break;
}
}
/* Check if first byte received. */
if(1 == rs)
{
/* Receive rest of data. */
rs = sl_Recv(sd, &gp_buff[1], 4095, SL_MSG_DONTWAIT);
/* Process data.... */
}
/* Check if there is no data. */
else if(SL_ERROR_BSD_EAGAIN == rs)
{
/* Sleep task to try again later. */
usleep(100000);
}
/* Check if there is an error. */
else
{
/* Break the loop. */
break;
}
}
/* Create a client socket. */
sl_Socket(SL_AF_INET, SL_SOCK_STREAM, 0);
/* Try to connect to server. */
sl_Connect(sd, (SlSockAddr_t *)&addr, sizeof(SlSockAddr_t));
/* Set socket as non-blocking. */
nonBlocking = TRUE;
rs = sl_SetSockOpt(sd, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlocking, sizeof(nonBlocking));
/* Begin receiving loop. */
while(1)
{
/* Block socket to receive first byte. */
rs = sl_Recv(sd, gp_buff, 1, SL_MSG_DONTWAIT);
/* Check if first byte received. */
if(1 == rs)
{
/* Receive rest of data. */
rs = sl_Recv(sd, &gp_buff[1], 4095, SL_MSG_DONTWAIT);
/* Process data.... */
}
/* Check if there is an error. */
else
{
/* Break the loop. */
break;
}
}
On the other hand, if I try a dummy scenario which I know exactly how many bytes that the TCP server is going to send, I can see that the communication happens very fast.
I have tried using sl_Select with trigger mode as well but as I am using TI-RTOS, I read in the forum that this was not recommended.
Please let me know if there is a better way to handle this TCP communication.
Best,
Ogulcan