From a9722aed4a101edc04c326a2a71809f80aede537 Mon Sep 17 00:00:00 2001 From: Emil Popov Date: Thu, 12 Sep 2024 08:33:56 -0400 Subject: [PATCH] Adds a warning if the stream-buffer or windows properties are changed on an already connected socket. Discussed in #1184 Also changes the error message to using FreeRTOS_printf instead of FreeRTOS_debug_printf to increase the chances of being seen. --- source/FreeRTOS_Sockets.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index a4ffaf389..b473c06f5 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -2356,17 +2356,25 @@ void * vSocketClose( FreeRTOS_Socket_t * pxSocket ) uint32_t ulNewValue; BaseType_t xReturn; + if( ( FreeRTOS_issocketconnected( pxSocket ) == pdTRUE ) ) + { + /* If this socket is the child of a listening socket, the remote client may or may not have already sent + * us data. If data was already sent, then pxSocket->u.xTCP.rxStream != NULL and this call will fail. + * Warn the user about this inconsistent behavior. */ + FreeRTOS_printf( ( "Warning: Changing buffer/window properties on a connected socket may fail." ) ); + } + if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) { - FreeRTOS_debug_printf( ( "Set SO_%sBUF: wrong socket type\n", - ( lOptionName == FREERTOS_SO_SNDBUF ) ? "SND" : "RCV" ) ); + FreeRTOS_printf( ( "Set SO_%sBUF: wrong socket type\n", + ( lOptionName == FREERTOS_SO_SNDBUF ) ? "SND" : "RCV" ) ); xReturn = -pdFREERTOS_ERRNO_EINVAL; } else if( ( ( lOptionName == FREERTOS_SO_SNDBUF ) && ( pxSocket->u.xTCP.txStream != NULL ) ) || ( ( lOptionName == FREERTOS_SO_RCVBUF ) && ( pxSocket->u.xTCP.rxStream != NULL ) ) ) { - FreeRTOS_debug_printf( ( "Set SO_%sBUF: buffer already created\n", - ( lOptionName == FREERTOS_SO_SNDBUF ) ? "SND" : "RCV" ) ); + FreeRTOS_printf( ( "Set SO_%sBUF: buffer already created\n", + ( lOptionName == FREERTOS_SO_SNDBUF ) ? "SND" : "RCV" ) ); xReturn = -pdFREERTOS_ERRNO_EINVAL; } else