elgroves wrote on Wednesday, February 18, 2015:
I’ve ported FreeRTOS 8.1.2 to the TI TM4C1294NCPDT. I’ve configured FreeRTOS+TCP labs (141019) and written an interface driver for the TM4C part.
I’m writing an HTTP server that has a thread listening for inbound TCP connections. Once the connection is received, the new socket will be passed to a thread pool via a queue and handled there. My problem is that the FreeRTOS_accept call doesn’t wake up the thread. I can see in Wire Shark that the TCP stack takes the connection (SYN, ACK, HTTP request), but the handling thread is never woken up to handle it, so it just remains connected until some other event closes the socket.
If I configure the listening socket w/ a non-zero FREERTOS_SO_RCVTIMEO, the accept call returns. If no connection was found, I retry. If a connection is found, I pass it along and it is handled correctly, data flows, and all is well. But I’d prefer the accept call wake up my thread when a connection is received to reduce both latency and un-needed cycles. Is this not supported in the current version of FreeRTOS+TCP?
I am very ready to acknowledge that I may have mis-configured FreeRTOS or FreeRTOS+TCP.
My connection accepting thread:
void http_server(void * params)
{
static const TickType_t xReceiveTimeOut = 1000 / portTICK_RATE_MS; // portMAX_DELAY;
xSocket_t client_socket;
struct freertos_sockaddr bindAddress;
struct freertos_sockaddr clientAddress;
socklen_t size = sizeof(clientAddress);
(void) params;
server.listen_socket = FreeRTOS_socket(FREERTOS_AF_INET,
FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP);
configASSERT(server.listen_socket != FREERTOS_INVALID_SOCKET);
FreeRTOS_setsockopt(server.listen_socket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof(xReceiveTimeOut));
bindAddress.sin_port = (uint16_t) server.settings.listen_port;
bindAddress.sin_port = FreeRTOS_htons(bindAddress.sin_port);
FreeRTOS_bind(server.listen_socket, &bindAddress, sizeof(bindAddress));
FreeRTOS_listen(server.listen_socket, 20);
for (;;)
{
client_socket = FreeRTOS_accept(server.listen_socket, &clientAddress, &size);
if (client_socket == FREERTOS_INVALID_SOCKET
|| client_socket == NULL)
{
continue;
}
xQueueSendToBack(server.rx_sockets_queue, &client_socket, 1000 /portTICK_PERIOD_MS); //portMAX_DELAY);
}
}
Thanks for any help!