From b4ec6fdff8407892dccc5aa7318894e7a01309a2 Mon Sep 17 00:00:00 2001 From: Olivier Ligot Date: Wed, 29 May 2013 11:14:58 +0200 Subject: [PATCH] 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 --- library/tcp_stream_socket.e | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/tcp_stream_socket.e b/library/tcp_stream_socket.e index f51873cd..5c3ccf07 100644 --- a/library/tcp_stream_socket.e +++ b/library/tcp_stream_socket.e @@ -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