Quality RTOS & Embedded Software

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




Loading

TCP - Cane a Socket be used for multiple connects and shutdowns

Posted by joehinkle on September 28, 2016

I'm thinking about heap fragmentation.

I'm using heap4.

I have to acquire from 1 to 5 files from a Server.

Currently, I'm shutting down each connection after a file is acquired (think HTTP 1.0). and closing the socket.

Since a TCP socket acquires multiple buffers from the heap, each time a file is processed, buffers are acquired and freed from the heap because the socket is being acquired and freed.

Can a task acquire a socket and then perform multiple connects and shutdowns on the socket without closing the socket?

Thanks.

Joe


TCP - Cane a Socket be used for multiple connects and shutdowns

Posted by rtel on September 28, 2016

Hi Joe,

I think this should be legal, according to the TCP state machine, but it will mean you will create a new connection using the same IP address and port number, and I believe that has the potential to cause problems with anything in between your client and server (firewalls, routers, etc.) that could could maintain state of the previous connection. I will have to defer to Hein for anything further.

Regards.


TCP - Cane a Socket be used for multiple connects and shutdowns

Posted by joehinkle on September 28, 2016

I am/was concerned about internal socket data not getting re-initialized with each connection. You inferred that, I think, by stating that the port number might not be changed with a new connection.

Local Port number being associated wth socket and not the current connection. Is this a socket specification or an implementataion action?

Thanks.

Joe


TCP - Cane a Socket be used for multiple connects and shutdowns

Posted by heinbali01 on September 28, 2016

Can a task acquire a socket and then perform multiple connects and shutdowns on the socket without closing the socket?

Unfortunately that is not possible.

The only socket that can connect multiple times is a server socket that uses the resocket option FREERTOS_SO_REUSE_LISTEN_SOCKET. That is no use for you now.

Have you really seen that a lot of fragmentation occurs? Because normally, when you allocated N blocks, and then de-allocate them (in any order), there should be no fragmentation left. heap4 will split-up memory blocks, but free will join the blocks again.


TCP - Cane a Socket be used for multiple connects and shutdowns

Posted by rtel on September 28, 2016

The port number is assigned when the socket is 'bound'. Re-using the socket does not re-bind the socket. It may be possible to explicitly re-bind the socket by calling FreeRTOS_bind(), but I would have to check the source code to see if that would work - it is possible the bind() function will only proceed if the socket is not already bound to a port.


TCP - Cane a Socket be used for multiple connects and shutdowns

Posted by joehinkle on September 28, 2016

Fragmentation was just a concern -- I have not investigated actual results, just potential concern because of my process.


TCP - Cane a Socket be used for multiple connects and shutdowns

Posted by heinbali01 on September 28, 2016

Currently, I'm shutting down each connection after a file is acquired (think HTTP 1.0). and closing the socket.

Is it really important to stay HTTP 1.0 compatible? In all my HTTP client applications, a socket will do multiple GET's without closing the connection in-between and I can not remember that it ever cause a problem.


TCP - Cane a Socket be used for multiple connects and shutdowns

Posted by joehinkle on September 28, 2016

I'm modifing my process flow to keep the connection open to see how THAT works.


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




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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