Following is my environment:
- Linux, Ubuntu
- C++/gdb
- Eclipse
I am implementing a TCP socket server application.
While developing/debugging, the application might terminate after a connection was accepted, and, before the open sockets were gracefully shutdown & closed.
On such a scenario, the next execution of the application will fail binding to the listening port, only after waiting a minute or so binding will succeed again.
My assumption is that the Linux kernel has some cleanup mechanism to ~collect~ all sockets that were not gracefully shutdown, explaining why I have to wait ~1 min before the port is bind-able again.
Having that said, is there any way of avoiding this 1 min wait? Is there any way of forcing the OS to collect all sockets that were not gracefully shutdown?
Any help will be appreciated.
Nadav at Sophin
Sure there is, just set the
SO_REUSEADDRSOL_SOCKETlevel option on the socket.