From 167cba9e93bcc15e8c5f41fd8daadc958936b71a Mon Sep 17 00:00:00 2001 From: "Curtis L. Olson" Date: Fri, 12 Nov 2010 13:19:57 -0600 Subject: [PATCH] Patch to avoid the problem of the socket resource not yet being available if the program is restarted quickly after being killed. Reference: http://www.unixguide.net/network/socketfaq/4.5.shtml --- simgear/io/raw_socket.cxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/simgear/io/raw_socket.cxx b/simgear/io/raw_socket.cxx index da04c93c..75184bbd 100644 --- a/simgear/io/raw_socket.cxx +++ b/simgear/io/raw_socket.cxx @@ -190,6 +190,19 @@ bool Socket::open ( bool stream ) { close () ; handle = ::socket ( AF_INET, (stream? SOCK_STREAM: SOCK_DGRAM), 0 ) ; + + // Jan 26, 2010: Patch to avoid the problem of the socket resource not + // yet being available if the program is restarted quickly after being + // killed. + // + // Reference: http://www.unixguide.net/network/socketfaq/4.5.shtml + // + if ( stream ) { + int opt_boolean = 1; + setsockopt( handle, SOL_SOCKET, SO_REUSEADDR, + &opt_boolean, sizeof(opt_boolean) ); + } + return (handle != -1); } -- 2.39.5