win32.h (_Jv_platform_close_on_exec): Changed signature and declared extern.
authorMohan Embar <gnustuff@thisiscool.com>
Fri, 7 Nov 2003 03:13:56 +0000 (03:13 +0000)
committerMohan Embar <membar@gcc.gnu.org>
Fri, 7 Nov 2003 03:13:56 +0000 (03:13 +0000)
* include/win32.h (_Jv_platform_close_on_exec): Changed
signature and declared extern.
* win32.cc (_Jv_platform_close_on_exec): Implemented.
* gnu/java/net/natPlainDatagramSocketImplWin32.cc
(create): Use new signature of _Jv_platform_close_on_exec.
* gnu/java/net/natPlainSocketImplWin32.cc
(create): Eliminated a few typecasts
Use new signature of _Jv_platform_close_on_exec.
(accept): Eliminated a few typecasts
Use new signature of _Jv_platform_close_on_exec.
* java/io/natFileDescriptorWin32.cc (open): Use
_Jv_platform_close_on_exec.

From-SVN: r73325

libjava/ChangeLog
libjava/gnu/java/net/natPlainDatagramSocketImplWin32.cc
libjava/gnu/java/net/natPlainSocketImplWin32.cc
libjava/include/win32.h
libjava/java/io/natFileDescriptorWin32.cc
libjava/win32.cc

index 6cbae87531dbf484b384a8b2f4ff81a3fa4a0c0a..9b1af441622f45c94412113510ee92f9b2c7229b 100644 (file)
@@ -1,3 +1,18 @@
+2003-11-06  Mohan Embar  <gnustuff@thisiscool.com>
+
+       * include/win32.h (_Jv_platform_close_on_exec): Changed
+       signature and declared extern.
+       * win32.cc (_Jv_platform_close_on_exec): Implemented.
+       * gnu/java/net/natPlainDatagramSocketImplWin32.cc
+       (create): Use new signature of _Jv_platform_close_on_exec.
+       * gnu/java/net/natPlainSocketImplWin32.cc 
+       (create): Eliminated a few typecasts
+       Use new signature of _Jv_platform_close_on_exec.
+       (accept): Eliminated a few typecasts
+       Use new signature of _Jv_platform_close_on_exec.
+       * java/io/natFileDescriptorWin32.cc (open): Use
+       _Jv_platform_close_on_exec.
+
 2003-11-04  Bryce McKinlay  <bryce@mckinlay.net.nz>
 
        * java/lang/natClass.cc (newInstance): Throw InstantiationException
index 1098e6158a8f6637a999b5968a4339c0b200b4c0..4a4ec986c612e2dae61b95969c30aade9d08d3e5 100644 (file)
@@ -69,11 +69,14 @@ gnu::java::net::PlainDatagramSocketImpl::create ()
       _Jv_ThrowSocketException ();
     }
 
-  _Jv_platform_close_on_exec (sock);
+  // Cast this to a HANDLE so we can make
+  // it non-inheritable via _Jv_platform_close_on_exec.
+  HANDLE hSocket = (HANDLE) sock;
+  _Jv_platform_close_on_exec (hSocket);
 
   // We use native_fd in place of fd here.  From leaving fd null we avoid
   // the double close problem in FileDescriptor.finalize.
-  native_fd = (int) sock;
+  native_fd = (jint) hSocket;
 }
 
 void
index 96373811936a3ecfbb264856a0f82f499918ecde..c1c813ec7adc280eab6c45d2c9d9d28b69f3384e 100644 (file)
@@ -45,18 +45,21 @@ union SockAddr
 void
 gnu::java::net::PlainSocketImpl::create (jboolean stream)
 {
-  int sock = ::socket (AF_INET, stream ? SOCK_STREAM : SOCK_DGRAM, 0);
+  SOCKET sock = ::socket (AF_INET, stream ? SOCK_STREAM : SOCK_DGRAM, 0);
 
-  if (sock == int(INVALID_SOCKET))
+  if (sock == INVALID_SOCKET)
     {
       _Jv_ThrowIOException ();
     }
 
-  _Jv_platform_close_on_exec (sock);
+  // Cast this to a HANDLE so we can make
+  // it non-inheritable via _Jv_platform_close_on_exec.
+  HANDLE hSocket = (HANDLE) sock;
+  _Jv_platform_close_on_exec (hSocket);
 
   // We use native_fd in place of fd here.  From leaving fd null we avoid
   // the double close problem in FileDescriptor.finalize.
-  native_fd = sock;
+  native_fd = (jint) hSocket;
 }
 
 void
@@ -230,7 +233,8 @@ gnu::java::net::PlainSocketImpl::accept (gnu::java::net::PlainSocketImpl *s)
 {
   union SockAddr u;
   socklen_t addrlen = sizeof(u);
-  int new_socket = 0;
+  HANDLE hSocket = 0;
+  SOCKET new_socket = 0;
 
   if (timeout > 0)
     {
@@ -245,7 +249,7 @@ gnu::java::net::PlainSocketImpl::accept (gnu::java::net::PlainSocketImpl *s)
       {
         new_socket = ::accept (native_fd, (sockaddr*) &u, &addrlen);
 
-        if (new_socket != int(INVALID_SOCKET))
+        if (new_socket != INVALID_SOCKET)
         {
           // This new child socket is nonblocking because the parent
           // socket became nonblocking via the WSAEventSelect() call,
@@ -284,10 +288,13 @@ gnu::java::net::PlainSocketImpl::accept (gnu::java::net::PlainSocketImpl *s)
       new_socket = ::accept (native_fd, (sockaddr*) &u, &addrlen);
     }
 
-  if (new_socket == int(INVALID_SOCKET))
+  if (new_socket == INVALID_SOCKET)
     goto error;
 
-  _Jv_platform_close_on_exec (new_socket);
+  // Cast this to a HANDLE so we can make
+  // it non-inheritable via _Jv_platform_close_on_exec.
+  hSocket = (HANDLE) new_socket;
+  _Jv_platform_close_on_exec (hSocket);
 
   jbyteArray raddr;
   jint rport;
@@ -308,7 +315,7 @@ gnu::java::net::PlainSocketImpl::accept (gnu::java::net::PlainSocketImpl *s)
   else
     throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
 
-  s->native_fd = new_socket;
+  s->native_fd = (jint) hSocket;
   s->localport = localport;
   s->address = new ::java::net::InetAddress (raddr, NULL);
   s->port = rport;
index e169adf9b284a0e145392363bbc525f36b696676..479ed53f00ec96b9a42a3f319c3b6c0cd64ba895 100644 (file)
@@ -97,11 +97,8 @@ extern jlong _Jv_platform_gettimeofday ();
 extern int _Jv_select (int n, fd_set *, fd_set *, fd_set *, struct timeval *);
 extern int _Jv_pipe (int filedes[2]);
 
-inline void
-_Jv_platform_close_on_exec (jint)
-{
-  // Ignore.
-}
+extern void
+_Jv_platform_close_on_exec (HANDLE h);
 
 #ifdef JV_HASH_SYNCHRONIZATION
 /* Suspends the execution of the current thread for the specified
index 1891bf78e4222acf1496fd7c37e7b5169aa8f738..465d7557992edecedf61060207cd4ac6b65a30e0 100644 (file)
@@ -133,7 +133,13 @@ java::io::FileDescriptor::open (jstring path, jint jflags) {
         throw new FileNotFoundException (_Jv_WinStrError (cpath, dwErrorCode));
       }
     }
-  return (jint)handle;
+    
+  // Make this handle non-inheritable so that child
+  // processes don't inadvertently prevent us from
+  // closing this file.
+  _Jv_platform_close_on_exec (handle);
+
+  return (jint) handle;
 }
 
 void
index 3bf1391016e9dba8a88326b5798f3010520590aa..dfed8c436603c0317a2e60b3e309bb74047eb5fc 100644 (file)
@@ -363,3 +363,11 @@ _Jv_pipe (int filedes[2])
 {
   return _pipe (filedes, 4096, _O_BINARY);
 }
+
+void
+_Jv_platform_close_on_exec (HANDLE h)
+{
+  // Mark the handle as non-inheritable. This has
+  // no effect under Win9X.
+  SetHandleInformation (h, HANDLE_FLAG_INHERIT, 0);
+}