TCP – Cane a Socket be used for multiple connects and shutdowns
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
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
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
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
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
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
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
I’m modifing my process flow to keep the connection open to see how THAT works.