Skip to content

Commit c9e63fc

Browse files
evpopovEmil Popovtony-josi-aws
authored
Fixes the TCP zero-copy functionality... (#1018)
* Fixes the TCP zero-copy functionality... looks like this somehow just got overlooked. * Update unit tests --------- Co-authored-by: Emil Popov <[email protected]> Co-authored-by: tony-josi-aws <[email protected]>
1 parent 222a36d commit c9e63fc

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

source/FreeRTOS_Sockets.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -4594,16 +4594,10 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket )
45944594
size_t uxDataLength,
45954595
BaseType_t xFlags )
45964596
{
4597-
BaseType_t xByteCount = -pdFREERTOS_ERRNO_EINVAL;
4597+
BaseType_t xByteCount;
45984598
FreeRTOS_Socket_t * pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
45994599

4600-
if( pvBuffer != NULL )
4601-
{
4602-
/* Check if this is a valid TCP socket, affirm that it is not closed or closing,
4603-
* affirm that there was not malloc-problem, test if uxDataLength is non-zero,
4604-
* and if the connection is not in a confirmed FIN state. */
4605-
xByteCount = ( BaseType_t ) prvTCPSendCheck( pxSocket, uxDataLength );
4606-
}
4600+
xByteCount = ( BaseType_t ) prvTCPSendCheck( pxSocket, uxDataLength );
46074601

46084602
if( xByteCount > 0 )
46094603
{

test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c

+39-3
Original file line numberDiff line numberDiff line change
@@ -1233,10 +1233,40 @@ void test_FreeRTOS_send_DisconnectionOccursDuringWait( void )
12331233
}
12341234

12351235
/*
1236-
* @brief IP task is calling send function with a NULL buffer. Also there are 20 bytes worth of space
1237-
* less in the stream buffer as the data length.
1236+
* @brief IP task is calling send function with a NULL buffer (TCP zero copy).
12381237
*/
12391238
void test_FreeRTOS_send_IPTaskWithNULLBuffer( void )
1239+
{
1240+
BaseType_t xReturn;
1241+
FreeRTOS_Socket_t xSocket;
1242+
size_t uxNettLength = 100;
1243+
BaseType_t xFlags = 0;
1244+
StreamBuffer_t xLocalStreamBuffer;
1245+
1246+
memset( &xSocket, 0, sizeof( xSocket ) );
1247+
memset( &xLocalStreamBuffer, 0, sizeof( xLocalStreamBuffer ) );
1248+
1249+
xSocket.ucProtocol = FREERTOS_IPPROTO_TCP;
1250+
xSocket.u.xTCP.eTCPState = eESTABLISHED;
1251+
xSocket.u.xTCP.bits.bFinSent = pdFALSE_UNSIGNED;
1252+
xSocket.u.xTCP.txStream = &xLocalStreamBuffer;
1253+
xSocket.xSendBlockTime = 100;
1254+
1255+
listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( &xBoundTCPSocketsList );
1256+
uxStreamBufferGetSpace_ExpectAndReturn( xSocket.u.xTCP.txStream, uxNettLength );
1257+
uxStreamBufferAdd_ExpectAndReturn( xSocket.u.xTCP.txStream, 0U, NULL, uxNettLength, uxNettLength );
1258+
xIsCallingFromIPTask_ExpectAndReturn( pdTRUE );
1259+
1260+
xReturn = FreeRTOS_send( &xSocket, NULL, uxNettLength, xFlags );
1261+
1262+
TEST_ASSERT_EQUAL( uxNettLength, xReturn );
1263+
}
1264+
1265+
/*
1266+
* @brief IP task is calling send function with a NULL buffer (TCP zero copy). Also there are 20 bytes worth of space
1267+
* less in the stream buffer as the data length.
1268+
*/
1269+
void test_FreeRTOS_send_IPTaskWithNULLBuffer_LessSpaceInStreamBuffer( void )
12401270
{
12411271
BaseType_t xReturn;
12421272
FreeRTOS_Socket_t xSocket;
@@ -1256,9 +1286,15 @@ void test_FreeRTOS_send_IPTaskWithNULLBuffer( void )
12561286

12571287
uxDataLength = 100;
12581288

1289+
listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( &xBoundTCPSocketsList );
1290+
uxStreamBufferGetSpace_ExpectAndReturn( xSocket.u.xTCP.txStream, uxDataLength - 20 );
1291+
uxStreamBufferAdd_ExpectAndReturn( xSocket.u.xTCP.txStream, 0U, NULL, uxDataLength - 20, uxDataLength - 20 );
1292+
xIsCallingFromIPTask_ExpectAndReturn( pdTRUE );
1293+
xIsCallingFromIPTask_ExpectAndReturn( pdTRUE );
1294+
12591295
xReturn = FreeRTOS_send( &xSocket, NULL, uxDataLength, xFlags );
12601296

1261-
TEST_ASSERT_EQUAL( -pdFREERTOS_ERRNO_EINVAL, xReturn );
1297+
TEST_ASSERT_EQUAL( uxDataLength - 20, xReturn );
12621298
}
12631299

12641300
/**

0 commit comments

Comments
 (0)