]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/raw_socket.cxx
fix SGPagedLOD change for 2.8.3
[simgear.git] / simgear / io / raw_socket.cxx
index da04c93c8c94a16e2d26a7fd2c8916958fbe6a7a..e2adb7eebe4a35a49b9e3d4c44699810aa7d67a1 100644 (file)
@@ -190,6 +190,24 @@ 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;
+#if defined(_WIN32) || defined(__CYGWIN__)
+    setsockopt( handle, SOL_SOCKET, SO_REUSEADDR, (char *)&opt_boolean,
+               sizeof(opt_boolean) );
+#else
+    setsockopt( handle, SOL_SOCKET, SO_REUSEADDR, &opt_boolean,
+               sizeof(opt_boolean) );
+#endif
+  }
+
   return (handle != -1);
 }