Skip to content

Commit faf65d6

Browse files
Use vSocketCloseNextTime instead of FreeRTOS_closesocket
This avoids problems with calling FreeRTOS_closesocket from the IP task.
1 parent ad8a429 commit faf65d6

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

.github/lexicon.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,7 @@ vreleasenetworkbufferanddescriptor
13021302
vrxfaultinjection
13031303
vsocketbind
13041304
vsocketclose
1305+
vsocketclosenexttime
13051306
vsocketselect
13061307
vsocketwakeupuser
13071308
vtasklist

FreeRTOS_IP.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,8 @@ static void prvCheckNetworkTimers( void )
834834
xProcessedTCPMessage = 0;
835835
}
836836
}
837+
838+
vSocketCloseNextTime( NULL );
837839
#endif /* ipconfigUSE_TCP == 1 */
838840
}
839841
/*-----------------------------------------------------------*/

FreeRTOS_TCP_IP.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,23 @@
421421

422422
return xResult;
423423
}
424+
/*-----------------------------------------------------------*/
425+
426+
/** @brief Close the socket another time.
427+
*
428+
* @param[in] pxSocket: The socket to be checked.
429+
*/
430+
void vSocketCloseNextTime( FreeRTOS_Socket_t * pxSocket )
431+
{
432+
static FreeRTOS_Socket_t * prev_socket = NULL;
433+
434+
if( ( prev_socket != NULL ) && ( prev_socket != pxSocket ) )
435+
{
436+
vSocketClose( prev_socket );
437+
}
438+
439+
prev_socket = pxSocket;
440+
}
424441
/*-----------------------------------------------------------*/
425442

426443
#if ( ipconfigTCP_HANG_PROTECTION == 1 )
@@ -499,7 +516,7 @@
499516
* gets connected. */
500517
if( pxSocket->u.xTCP.bits.bPassQueued != pdFALSE_UNSIGNED )
501518
{
502-
/* vTCPStateChange() has called FreeRTOS_closesocket()
519+
/* vTCPStateChange() has called vSocketCloseNextTime()
503520
* in case the socket is not yet owned by the application.
504521
* Return a negative value to inform the caller that
505522
* the socket will be closed in the next cycle. */
@@ -1844,7 +1861,7 @@
18441861

18451862
if( pxSocket->u.xTCP.bits.bReuseSocket == pdFALSE_UNSIGNED )
18461863
{
1847-
( void ) FreeRTOS_closesocket( pxSocket );
1864+
vSocketCloseNextTime( pxSocket );
18481865
}
18491866
}
18501867
}
@@ -3896,7 +3913,7 @@
38963913
if( vSocketBind( pxNewSocket, &xAddress, sizeof( xAddress ), pdTRUE ) != 0 )
38973914
{
38983915
FreeRTOS_debug_printf( ( "TCP: Listen: new socket bind error\n" ) );
3899-
( void ) FreeRTOS_closesocket( pxNewSocket );
3916+
vSocketClose( pxNewSocket );
39003917
xResult = pdFALSE;
39013918
}
39023919
else

include/FreeRTOS_IP_Private.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,11 @@
760760

761761
#if ( ipconfigUSE_TCP == 1 )
762762

763+
/*
764+
* Close the socket another time.
765+
*/
766+
void vSocketCloseNextTime( FreeRTOS_Socket_t * pxSocket );
767+
763768
/*
764769
* Lookup a TCP socket, using a multiple matching: both port numbers and
765770
* return IP address.

0 commit comments

Comments
 (0)