Skip to content

Commit 8aebab7

Browse files
evpopovEmil Popov
andauthored
Adds a warning if the stream-buffer or windows properties are changed on an already connected socket. Discussed in #1184 (#1188)
Also changes the error message to using FreeRTOS_printf instead of FreeRTOS_debug_printf to increase the chances of being seen. Co-authored-by: Emil Popov <[email protected]>
1 parent a45bfe2 commit 8aebab7

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

source/FreeRTOS_Sockets.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,17 +2356,25 @@ void * vSocketClose( FreeRTOS_Socket_t * pxSocket )
23562356
uint32_t ulNewValue;
23572357
BaseType_t xReturn;
23582358

2359+
if( ( FreeRTOS_issocketconnected( pxSocket ) == pdTRUE ) )
2360+
{
2361+
/* If this socket is the child of a listening socket, the remote client may or may not have already sent
2362+
* us data. If data was already sent, then pxSocket->u.xTCP.rxStream != NULL and this call will fail.
2363+
* Warn the user about this inconsistent behavior. */
2364+
FreeRTOS_printf( ( "Warning: Changing buffer/window properties on a connected socket may fail." ) );
2365+
}
2366+
23592367
if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP )
23602368
{
2361-
FreeRTOS_debug_printf( ( "Set SO_%sBUF: wrong socket type\n",
2362-
( lOptionName == FREERTOS_SO_SNDBUF ) ? "SND" : "RCV" ) );
2369+
FreeRTOS_printf( ( "Set SO_%sBUF: wrong socket type\n",
2370+
( lOptionName == FREERTOS_SO_SNDBUF ) ? "SND" : "RCV" ) );
23632371
xReturn = -pdFREERTOS_ERRNO_EINVAL;
23642372
}
23652373
else if( ( ( lOptionName == FREERTOS_SO_SNDBUF ) && ( pxSocket->u.xTCP.txStream != NULL ) ) ||
23662374
( ( lOptionName == FREERTOS_SO_RCVBUF ) && ( pxSocket->u.xTCP.rxStream != NULL ) ) )
23672375
{
2368-
FreeRTOS_debug_printf( ( "Set SO_%sBUF: buffer already created\n",
2369-
( lOptionName == FREERTOS_SO_SNDBUF ) ? "SND" : "RCV" ) );
2376+
FreeRTOS_printf( ( "Set SO_%sBUF: buffer already created\n",
2377+
( lOptionName == FREERTOS_SO_SNDBUF ) ? "SND" : "RCV" ) );
23702378
xReturn = -pdFREERTOS_ERRNO_EINVAL;
23712379
}
23722380
else

0 commit comments

Comments
 (0)