]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/raw_socket.cxx
Clear tile cache on (re-)init.
[simgear.git] / simgear / io / raw_socket.cxx
index 7af6c695b372d8326e9376fe347be85732b52ca0..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);
 }
 
@@ -331,7 +349,7 @@ bool Socket::isNonBlockingError ()
   if ( wsa_errno != 0 )
   {
     WSASetLastError(0);
-    ulSetError(UL_WARNING,"WSAGetLastError() => %d",wsa_errno);
+       SG_LOG(SG_IO, SG_WARN, "isNonBlockingError: WSAGetLastError():" << wsa_errno);
     switch (wsa_errno) {
     case WSAEWOULDBLOCK: // always == NET_EAGAIN?
     case WSAEALREADY:
@@ -474,8 +492,7 @@ int Socket::initSockets()
        WSADATA wsaData;
 
        if ( WSAStartup(version_wanted, &wsaData) != 0 ) {
-               ulSetError(UL_WARNING,"Couldn't initialize Winsock 1.1");
-               return(-1);
+               throw sg_exception("WinSock initialization failed");
        }
 #endif