]> git.mxchange.org Git - simgear.git/commitdiff
Patch to avoid the problem of the socket resource not yet being available
authorCurtis L. Olson <curtolson@gmail.com>
Fri, 12 Nov 2010 19:19:57 +0000 (13:19 -0600)
committerCurtis L. Olson <curtolson@gmail.com>
Fri, 12 Nov 2010 19:19:57 +0000 (13:19 -0600)
if the program is restarted quickly after being killed.

Reference: http://www.unixguide.net/network/socketfaq/4.5.shtml

simgear/io/raw_socket.cxx

index da04c93c8c94a16e2d26a7fd2c8916958fbe6a7a..75184bbd6abc63aa934a7fef68fd609f361a9903 100644 (file)
@@ -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);
 }