I have an application developed in C++ running on Linux. This application opens certain TCP sockets on start-up. But if this application is killed when a connection was in established state, the server side socket still remains in closing state (TIME_WAIT) for few moments.
Since my application is restarted immideatly it is unable to bind port which takes almost 60secs to close from previous crash.
Is there any system call which can forcefully close all open/dangling sockets ?? so before I go for binding I can ensure that all open/dangling sockets are closed and my binding does not failt.
Thanks.
You can set
SO_REUSEADDRusingsetsockopt. Then you’ll be able to bind straight away.