The
FreeRTOS_recvfrom()
TCP/IP stack API function is used to receive from a
UDP socket.
Data can only be received after the
socket has been
created, configured, and
bound to a local
port number.
As detailed on the FreeRTOS_recvfrom() API reference page, FreeRTOS_recvfrom()
can be used with standard calling semantics, or zero copy calling semantics.
This page demonstrates the zero copy calling semantics.
The source code below shows a RTOS task that creates a socket before entering
a loop that receives data using the zero copy calling semantics. The
comments in the source code provide important information on how to use
network buffers when the zero copy option is used.
static void vUDPReceivingUsingZeroCopyInterface( void *pvParameters )
{
int32_t lBytes;
uint8_t *pucUDPPayloadBuffer;
struct freertos_sockaddr xClient, xBindAddress;
uint32_t xClientLength = sizeof( xClient ), ulIPAddress;
Socket_t xListeningSocket;
xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET,
FREERTOS_SOCK_DGRAM,
FREERTOS_IPPROTO_UDP );
configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET );
xBindAddress.sin_port = FreeRTOS_htons( 10000 );
FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );
for( ;; )
{
lBytes = FreeRTOS_recvfrom( xListeningSocket,
&pucUDPPayloadBuffer,
0,
FREERTOS_ZERO_COPY,
&xClient,
&xClientLength );
if( lBytes > 0 )
{
}
if( lBytes >= 0 )
{
FreeRTOS_ReleaseUDPPayloadBuffer( pucUDPPayloadBuffer );
}
}
}
Example using FreeRTOS_recvfrom() with the zero copy (as opposed to standard) calling semantics
<<
Back to the RTOS TCP networking tutorial index
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.