I have found a behaviour in FreeRTOS-Plus-TCP that may be a bug. Freertos+TCP version is 4.3.2.
My application has one task using a TCP socket for handling a server function, another task receives data from many UDP sockets and a third task provides a TFTP server also with a UDP socket. All of this works fine until I add a FreeRTOS_select() to handle more than one UDP sockets in the data receiving task.
When FreeRTOS_select() is added, the TCP socket stops working. UDP sockets continue working fine. TCP ACKs continue to work, but data is not received. FreeRTOS_select() is not related to the broken TCP socket, it is used in another task for other sockets.
For the TCP socket I use the following option.
FreeRTOS_setsockopt( modbusSocket, 0, FREERTOS_SO_WAKEUP_CALLBACK, tcp_socket_callback, sizeof(void));
I have also tried with sequential listen-accept-recv method with no difference. I have also tried separate conn and recv callback, no difference with those either.
The “Bug” manifests as not receiving the proper signals that are received when FreeRTOS_select() is not used. Below is a wireshark capture of the broken situation.
And below my simple log from device (tickcount, callback event), notice the time difference of 13s between opening the connection and receiving the receive event 1.
tick 256, eventbits 10
tick 260, eventbits 10
tick 35990, eventbits 0
tick 35990, eventbits 0
tick 35993, eventbits 4
tick 48015, eventbits 1
tick 48016, eventbits 20
tick 48017, eventbits 10
tick 48020, eventbits 10
Callback is:
void tcp_socket_callback( Socket_t pxSocket )
{
log_serial("tick %d, eventbits %x",xTaskGetTickCount(), pxSocket->xEventBits);
if (pxSocket->xEventBits & eSOCKET_RECEIVE) //we can have receive and send callbacks at the same time, therefore eventbits will be eSOCKET_RECEIVE | eSOCKET_SEND, but no need to process the send callback
{
xTaskNotify( configuratorTaskHandle, eSOCKET_RECEIVE, eSetValueWithOverwrite );
}
if (pxSocket->xEventBits == eSOCKET_ACCEPT)
{
connectedSocket = FreeRTOS_accept( modbusSocket, &modbusClientAddr, (socklen_t*)sizeof( struct freertos_sockaddr ));
FreeRTOS_setsockopt( connectedSocket, 0, FREERTOS_SO_WAKEUP_CALLBACK, tcp_socket_callback, sizeof(void));
}
if (pxSocket->xEventBits == eSOCKET_CLOSED)
{
if (FreeRTOS_closesocket( pxSocket ) == 1)
{
xTaskNotify( configuratorTaskHandle, eSOCKET_CLOSED, eSetValueWithOverwrite );
}
}
}
Receive event appears only when the host is already closing the connection.
When FreeRTOS_Select() is not used, then I get the event’s properly:
tick 256, eventbits 10
tick 260, eventbits 10
tick 4114, eventbits 0
tick 4114, eventbits 0
tick 4116, eventbits 4
tick 4118, eventbits 1
tick 4120, eventbits 2
tick 4124, eventbits 0
tick 4125, eventbits 20
tick 4126, eventbits 10
tick 4129, eventbits 10
And equivalent wireshark:
Anyone have any ideas how this could be fixed, or should I continue making an issue report in Github?


