Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


FreeRTOS+TCP. Creating new socket after FreeRTOS_closesocket()

Posted by yanvasilij on June 29, 2017


Does I understed correct after FreeRTOSclosesocket() (for example when connection is lost) I must to create new socket with FreeRTOSsocket() to reopen connection, and I must not to use old socket value. Does this kind of socket creation uses dinamic memory allocation even I need only one open socket? Does it could couse memory fragmentation if I use heap_1?

Regards, Vasilij

FreeRTOS+TCP. Creating new socket after FreeRTOS_closesocket()

Posted by rtel on June 29, 2017

Once a socket is closed it cannot be used again. If you want another socket then you need to create it again.

The socket is allocated using a call to pvPortMallocSocket(). By default that will call pvPortMalloc(), but you can re-define the behaviour by #defining pvPortMallocSocket() in FreeRTOSIPConfig.h to do whatever you want it to do. Fro example:

define pvPortMallocSocket( x ) MyStaticAllocator( x )

(where MyStaticAllocator() would be something you provided).

heap1 cannot free memory, so don't use that. Heap4 will guard against memory fragmentation as much as it can.

FreeRTOS+TCP. Creating new socket after FreeRTOS_closesocket()

Posted by yanvasilij on June 30, 2017

Thank you a lot for explanation! It helped.

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner