Socket: reuse address to resolve the error "address already in use"

On Unix, when we stop the server, and then re-start it right away, we get an
error that the address is already in use:
http://www.softlab.ntua.gr/facilities/documentation/unix/unix-socket-faq/unix-socket-faq-4.html#ss4.1
This means that the sockets that were used by the first incarnation of the
server are still active.

One way to resolve this is to set the socket option SO_REUSEADDR:
http://www.softlab.ntua.gr/facilities/documentation/unix/unix-socket-faq/unix-socket-faq-4.html#ss4.5

Tested on Ubuntu 12.04 LTS
This commit is contained in:
Olivier Ligot
2013-05-29 11:14:58 +02:00
parent ef9494e7e8
commit b4ec6fdff8

View File

@@ -8,6 +8,9 @@ class
inherit
NETWORK_STREAM_SOCKET
redefine
make
end
create
make_server_by_address_and_port,
@@ -18,6 +21,13 @@ create {NETWORK_STREAM_SOCKET}
feature {NONE} -- Initialization
make
-- Create a network stream socket.
do
Precursor
set_reuse_address
end
make_server_by_address_and_port (an_address: INET_ADDRESS; a_port: INTEGER)
-- Create server socket on `an_address' and `a_port'.
require