Hein,
The config parameters are defined with the same values.
I am working on a project that will provide a Web server for
configuration. The Web server must be enabled through a physical
user interface and will time out and shut down if no connection is
made within a few minutes. The same will happen if the user connects
but fails to enter a one time password that the physical UI presents.
The server can also be shut down on demand through the physical UI.
The server code is based on the FreeRTOS HTTP demo. I also added
a websocket implementation. Everything is working and we can configure
our product as desired. The only remaining problem is that if I shut down the
server on demand I experience the issue I outlined.
As I said the HTTP server is based on the demo. The listener is created and bound as in the
demo. The following options are employed as in the demo.
BaseType_t xNoTimeout = 0;
FreeRTOS_setsockopt(xSocket, 0, FREERTOS_SO_RCVTIMEO, (void*) &xNoTimeout,
sizeof(BaseType_t));
FreeRTOS_setsockopt(xSocket, 0, FREERTOS_SO_SNDTIMEO, (void*) &xNoTimeout,
sizeof(BaseType_t));
WinProperties_t xWinProps;
memset( &xWinProps, '\0', sizeof(xWinProps));
/* The parent socket itself won't get connected. The properties below
will be inherited by each new child socket. */
xWinProps.lTxBufSize = ipconfigHTTP_TX_BUFSIZE;
xWinProps.lTxWinSize = ipconfigHTTP_TX_WINSIZE;
xWinProps.lRxBufSize = ipconfigHTTP_RX_BUFSIZE;
xWinProps.lRxWinSize = ipconfigHTTP_RX_WINSIZE;
/* Set the window and buffer sizes. */
FreeRTOS_setsockopt(xSocket, 0, FREERTOS_SO_WIN_PROPERTIES, (void*) &xWinProps,
sizeof(xWinProps));
I am not re-using the listener, the same one accepts a new client connection. 2 - 4 client connections (sockets) may be opened when a browser connects depending on if the one time password is entered correctly. There is a 1s wait on select at which time a variable is checked for shutdown.
The server is shut down within the task that manages the web server (listener, clients, etc.)
The server task shuts down as follows:
Listener
FreeRTOS_FD_CLR( listenerSocket, xSocketSet, eSELECT_ALL );
FreeRTOS_shutdown(listenerSocket, FREERTOS_SHUT_RDWR);
FreeRTOS_closesocket(listenerSocket);
Followed by each client in sequence:
for each client connection…
{
FreeRTOS_FD_CLR(xSocket, xSocketSet, eSELECT_ALL);
FreeRTOS_shutdown(xSocket, FREERTOS_SHUT_RDWR);
while(1)
{
unsigned buf;
int rc;
rc = FreeRTOS_recv(pxTCPClient->xSocket, &buf, 1, 0);
if((rc < 0) && (rc != -pdFREERTOS_ERRNO_EWOULDBLOCK))
{
break;
}
vTaskDelay(125);
}
FreeRTOS_closesocket(xSocket);
}
I uploaded a pcap. At the end of the capture a websocket closes almost immediately
because the one time password is incorrect. A few seconds later I accessed the physical
UI to shut down the server that had 2 connections remaining from HTTP. One takes 7
seconds to shutdown. The other takes 40 seconds to shutdown. By shutdown I mean for
FreeRTOS_recv to return in error.
These sockets usually take exactly 40s to shutdown. They were less in this capture for some reason.
Any help greatly appreciated.
long_socket_shutdown.7z (259.0 KB)