Lost in Sockets

My application sucessfully can send data via UDP sockets all day long Ocassionally when there is a back to back attempt at sending more than one UDP packet – The attempt to create a FreeRTOSsocket fails – /* Create the socket. */ xClientSocket = FreeRTOSsocket( FREERTOSAFINET, FREERTOSSOCKDGRAM, FREERTOSIPPROTOUDP ); configASSERT( xClientSocket != FREERTOSINVALIDSOCKET ); I am assuming that the sockets are dynamically create on the heap and more than one socket can be available at at time. As far as I can tell I have plenty of heap so I am at a loss what could cause the call to FreeRTOS_socket to fail. Is there a config parameter that specifies how many UDP sockets can be active at one time Lost in Sockets

Lost in Sockets

Looking at the FreeRTOSsocket() function (which you have the source code for, and can step through in the debugger), it seems like the only reasons FREERTOSINVALID_SOCKET would get returned are: 1) prvDetermineSocketSize() fails. You can look through this function to see the reasons this could fail – basically network is not ready or an input parameter is wrong. 2) The socket structure cannot be created (is pvPortMallocSocket() just mapped to pvPortMalloc(), which is the default? If so, which memory allocater are you using? Heap1, heap2, etc.) 3) xEventGroupCreate() fails, which again is just a memory allocation, so same as #2.

Lost in Sockets

Hi Pedro, I am not sure what to answer here. Remember that with configASSERT() defined, your application will halt if any of the calls to prvPortMalloc() fails, provided that you use one module out of portable/MemMang/heap_[1..5].c. The number of UDP sockets that you create is under your control. So you have to put a limit to it. I am not sure why you open more than one UDP socket? Do you advertise so many UDP ports? Normally, when you create a UDP-server, you’d open just one UDP socket and use that for every request. You can handle each request and send a reply to the sender. If you want, attach some code that illustrates what you are doing. There is special UDP protection tough, which becomes active if you define e.g. in your FreeRTOSIPConfig.h: ~~~

define ipconfigUDPMAXRX_PACKETS 4

~~~ With this example, each UDP socket will never store more that 4 received packets. For individual sockets, you can changes this limit with FreeRTOS_setsockopt() (FREERTOS_SO_UDP_MAX_RX_PACKETS); This option can protect your device against malicious attacks from outside.