dibosco wrote on Tuesday, August 30, 2016:
Folks,
I have a situation where, ocassionally, FreeRTOS_send() returns 0.
I followed the premise on this page:
However, very ocassionally, I find that in this part:
if( FreeRTOS_connect( xSocket, &xRemoteAddress, sizeof( xRemoteAddress ) ) == 0 )
{
/* Keep sending until the entire buffer has been sent. /
while( xAlreadyTransmitted < xTotalLengthToSend )
{
/ How many bytes are left to send? /
xLenToSend = xTotalLengthToSend - xAlreadyTransmitted;
xBytesSent = FreeRTOS_send( / The socket being sent to. /
xSocket,
/ The data being sent. /
&( pcBufferToTransmit[ xAlreadyTransmitted ] ),
/ The remaining length of data to send. /
xLenToSend,
/ ulFlags. */
0 );
if( xBytesSent >= 0 )
{
/* Data was sent successfully. */
xAlreadyTransmitted += xBytesSent;
}
else
{
/* Error - break out of the loop for graceful socket close. */
break;
}
}
}
The xBytesSent is always zero and therefore the thread gets stuck infinitely in that bit of the code and the whole web server just stops responding,
I changed the line from:
if( xBytesSent >= 0 )
to
if( xBytesSent > 0 )
And that seems to stop the thread from locking up, but I very ocassionally get my auto-refresh page not responding and have to manually refresh the page, then all is well again.
I’m using a version of the TCP/IP stack that is around a year old. Is it worth updating it? Or do these symptoms point to something more sinister?
If it’s of any help I did step into the code and found that the zero return value was here:
else if( pxSocket->u.xTcp.bits.bFinSent )
{
/* This TCP connection is closing already, the FIN flag has been sent.
Maybe it is still delivering or receiving data.
Return OK in order not to get closed/deleted too quickly */
xResult = 0;
}
Which is in prvTCPSendCheck() which is called by FreeRTOS_send().
Many thanks!
Rob