Update FreeRTOS_FD_SET() to check there is enough space in the queue before adding the socket to the socket set.

This commit is contained in:
Richard Barry 2013-10-07 20:13:02 +00:00
parent 10fa546e60
commit 0c849fa597
5 changed files with 59 additions and 26 deletions

View file

@ -105,17 +105,18 @@ xExampleDebugStatEntry_t xIPTraceValues[] =
{
/* Comment out array entries to remove individual trace items. */
{ iptraceID_NETWORK_INTERFACE_RECEIVE, ( const uint8_t * const ) "Packets received by the network interface", prvIncrementEventCount, 0 },
{ iptraceID_NETWORK_INTERFACE_TRANSMIT, ( const uint8_t * const ) "Count of transmitted packets", prvIncrementEventCount, 0 },
{ iptraceID_PACKET_DROPPED_TO_GENERATE_ARP, ( const uint8_t * const ) "Count of packets dropped to generate ARP", prvIncrementEventCount, 0 },
{ iptraceID_NETWORK_BUFFER_OBTAINED, ( const uint8_t * const ) "Lowest ever available network buffers", prvStoreLowest, 0xffffUL },
{ iptraceID_NETWORK_EVENT_RECEIVED, ( const uint8_t * const ) "Lowest ever free space in network event queue", prvStoreLowest, 0xffffUL },
{ iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER, ( const uint8_t * const ) "Count of failed attempts to obtain a network buffer",prvIncrementEventCount, 0 },
{ iptraceID_ARP_TABLE_ENTRY_EXPIRED, ( const uint8_t * const ) "Count of expired ARP entries", prvIncrementEventCount, 0 },
{ iptraceID_PACKET_DROPPED_TO_GENERATE_ARP, ( const uint8_t * const ) "Count of packets dropped to generate ARP", prvIncrementEventCount, 0 },
{ iptraceID_FAILED_TO_CREATE_SOCKET, ( const uint8_t * const ) "Count of failures to create a socket", prvIncrementEventCount, 0 },
{ iptraceID_RECVFROM_DISCARDING_BYTES, ( const uint8_t * const ) "Count of times recvfrom() has discarding bytes", prvIncrementEventCount, 0 },
{ iptraceID_ETHERNET_RX_EVENT_LOST, ( const uint8_t * const ) "Count of lost Ethenret Rx events (event queue full?)",prvIncrementEventCount, 0 },
{ iptraceID_STACK_TX_EVENT_LOST, ( const uint8_t * const ) "Count of lost IP stack events (event queue full?)", prvIncrementEventCount, 0 },
{ ipconfigID_BIND_FAILED, ( const uint8_t * const ) "Count of failed calls to bind()", prvIncrementEventCount, 0 },
{ iptraceID_NETWORK_INTERFACE_TRANSMIT, ( const uint8_t * const ) "Count of transmitted packets", prvIncrementEventCount, 0 },
{ iptraceID_RECVFROM_TIMEOUT, ( const uint8_t * const ) "Count of receive timeouts", prvIncrementEventCount, 0 },
{ iptraceID_SENDTO_DATA_TOO_LONG, ( const uint8_t * const ) "Count of failed sends due to oversized payload", prvIncrementEventCount, 0 },
{ iptraceID_SENDTO_SOCKET_NOT_BOUND, ( const uint8_t * const ) "Count of failed sends due to unbound socket", prvIncrementEventCount, 0 },

View file

@ -85,18 +85,21 @@ typedef struct ExampleDebugStatEntry
/* Unique identifiers used to locate the entry for each trace macro in the
xIPTraceValues[] table defined in DemoIPTrace.c. */
#define iptraceID_NETWORK_BUFFER_OBTAINED 1
#define iptraceID_NETWORK_BUFFER_OBTAINED_FROM_ISR 2
#define iptraceID_NETWORK_EVENT_RECEIVED 3
#define iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER 4
#define iptraceID_ARP_TABLE_ENTRY_EXPIRED 5
#define iptraceID_PACKET_DROPPED_TO_GENERATE_ARP 6
#define iptraceID_FAILED_TO_CREATE_SOCKET 7
#define iptraceID_RECVFROM_DISCARDING_BYTES 8
#define iptraceID_ETHERNET_RX_EVENT_LOST 9
#define iptraceID_STACK_TX_EVENT_LOST 10
#define ipconfigID_BIND_FAILED 11
#define iptraceID_NETWORK_INTERFACE_TRANSMIT 12
#define iptraceID_NETWORK_INTERFACE_RECEIVE 0
#define iptraceID_NETWORK_INTERFACE_TRANSMIT 1
#define iptraceID_PACKET_DROPPED_TO_GENERATE_ARP 2
/* Do not change IDs above this line as the ID is shared with a FreeRTOS+Nabto
demo. */
#define iptraceID_NETWORK_BUFFER_OBTAINED 3
#define iptraceID_NETWORK_BUFFER_OBTAINED_FROM_ISR 4
#define iptraceID_NETWORK_EVENT_RECEIVED 5
#define iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER 6
#define iptraceID_ARP_TABLE_ENTRY_EXPIRED 7
#define iptraceID_FAILED_TO_CREATE_SOCKET 8
#define iptraceID_RECVFROM_DISCARDING_BYTES 9
#define iptraceID_ETHERNET_RX_EVENT_LOST 10
#define iptraceID_STACK_TX_EVENT_LOST 11
#define ipconfigID_BIND_FAILED 12
#define iptraceID_RECVFROM_TIMEOUT 13
#define iptraceID_SENDTO_DATA_TOO_LONG 14
#define iptraceID_SENDTO_SOCKET_NOT_BOUND 15
@ -136,6 +139,7 @@ configINCLUDE_DEMO_DEBUG_STATS setting in FreeRTOSIPConfig.h. */
#define iptraceNO_BUFFER_FOR_SENDTO() vExampleDebugStatUpdate( iptraceID_NO_BUFFER_FOR_SENDTO, 0 )
#define iptraceWAITING_FOR_TX_DMA_DESCRIPTOR() vExampleDebugStatUpdate( iptraceID_WAIT_FOR_TX_DMA_DESCRIPTOR, 0 )
#define iptraceFAILED_TO_NOTIFY_SELECT_GROUP( xSocket ) vExampleDebugStatUpdate( iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP, 0 )
#define iptraceNETWORK_INTERFACE_RECEIVE() vExampleDebugStatUpdate( iptraceID_NETWORK_INTERFACE_RECEIVE, 0 )
/*
* The function that updates a line in the xIPTraceValues table.

View file

@ -0,0 +1,6 @@
FreeRTOS+Nabto projects are currently provided in a separate
download. Following are links to the download page and the
documentation for the demo that is included in the download.
http://www.freertos.org/FreeRTOS-Plus/Nabto/download_freertos_plus_nabto.shtml
http://www.freertos.org/FreeRTOS-Plus/Nabto/getting_started_with_FreeRTOS_Plus_Nabto.shtml

View file

@ -186,21 +186,39 @@ xFreeRTOS_Socket_t *pxSocket;
portBASE_TYPE FreeRTOS_FD_SET( xSocket_t xSocket, xSocketSet_t xSocketSet )
{
xFreeRTOS_Socket_t *pxSocket = ( xFreeRTOS_Socket_t * ) xSocket;
portBASE_TYPE xReturn;
portBASE_TYPE xReturn = pdFALSE;
unsigned portBASE_TYPE uxMessagesWaiting;
configASSERT( xSocket );
/* Is the socket already a member of a select group? */
if( pxSocket->xSelectQueue == NULL )
{
/* Store a pointer to the select group in the socket for future
reference. */
pxSocket->xSelectQueue = ( xQueueHandle ) xSocketSet;
xReturn = pdPASS;
}
else
{
/* The socket is already a member of a select group so cannot be added
to another. */
xReturn = pdFAIL;
taskENTER_CRITICAL();
{
/* Are there packets queued on the socket already? */
uxMessagesWaiting = uxQueueMessagesWaiting( pxSocket->xWaitingPacketSemaphore );
/* Are there enough notification spaces in the select queue for the
number of packets already queued on the socket? */
if( uxQueueSpacesAvailable( ( xQueueHandle ) xSocketSet ) >= uxMessagesWaiting )
{
/* Store a pointer to the select group in the socket for
future reference. */
pxSocket->xSelectQueue = ( xQueueHandle ) xSocketSet;
while( uxMessagesWaiting > 0 )
{
/* Add notifications of the number of packets that are
already queued on the socket to the select queue. */
xQueueSendFromISR( pxSocket->xSelectQueue, &pxSocket, NULL );
uxMessagesWaiting--;
}
xReturn = pdPASS;
}
}
taskEXIT_CRITICAL();
}
return xReturn;

View file

@ -147,4 +147,8 @@ from the FreeRTOSIPConfig.h configuration header file. */
#define ipconfigNABTO_TASK_PRIORITY ( ipconfigUDP_TASK_PRIORITY + 1 )
#endif
#ifndef ipconfigSUPPORT_SELECT_FUNCTION
#define ipconfigSUPPORT_SELECT_FUNCTION 0
#endif
#endif /* FREERTOS_DEFAULT_IP_CONFIG_H */