----
Not considering the the cause of my program crash, that may be
hard to find as Charles knows, John Hascall and Peter Hudson provided me
some directions to avoid the problem caused to me when the program is
crashed, allowing me to restart the application again without receiving
the 'address already in use' error.
These are their replies:
>From John:
--------------------------
Add a call to set the SO_REUSEADDR flag on the socket -- something
like this:
int on = 1;
s = socket( ... );
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on));
:
bind(s, ... );
------------------------
>From Peter:
-------------------------
There is only one way to do this: you must close() the socket.
I am in the same situation, and I had to install a signal handler for
SIGTERM, SIGBUS, SIGSEGV, and so on... which closed the socket
gracefully.
Alternatively, in the code which opens/connects the socket, you could
have a retry loop checking errno == EADDRINUSE. A socket in CLOSE_WAIT
should timeout after about 2 minutes.
----------------------
Pedro Serrahima
IIC Madrid
Spain
Received on Thu Feb 06 1997 - 10:15:37 NZDT
This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:47 NZDT