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:
@@ -8,6 +8,9 @@ class
|
|||||||
|
|
||||||
inherit
|
inherit
|
||||||
NETWORK_STREAM_SOCKET
|
NETWORK_STREAM_SOCKET
|
||||||
|
redefine
|
||||||
|
make
|
||||||
|
end
|
||||||
|
|
||||||
create
|
create
|
||||||
make_server_by_address_and_port,
|
make_server_by_address_and_port,
|
||||||
@@ -18,6 +21,13 @@ create {NETWORK_STREAM_SOCKET}
|
|||||||
|
|
||||||
feature {NONE} -- Initialization
|
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)
|
make_server_by_address_and_port (an_address: INET_ADDRESS; a_port: INTEGER)
|
||||||
-- Create server socket on `an_address' and `a_port'.
|
-- Create server socket on `an_address' and `a_port'.
|
||||||
require
|
require
|
||||||
|
|||||||
Reference in New Issue
Block a user