This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: Indicate EOF on Win32 when ReadFile( ) returns with ERROR_BROKEN_PIPE


Hi,
   
   This patch proposes to change the read( ) methods in 
java/io/natFileDescriptorWin32.cc so that they return a
-1 (EOF) when ReadFile( ) returns with a Win32 error
code of ERROR_BROKEN_PIPE when reading from a pipe.

This makes its behaviour similar to POSIX read( ) and
ensures that a parent process reading from a child's
output and error streams doesn't encounter an IOException
when the child exits. This is how Sun's JDK behaves, at
least on Win32.

Ranjit.

PS: How does one write ChangeLog entries for overloaded
methods like read( ) in the following example?


Index: ChangeLog
from  Ranjit Mathew  <rmathew@hotmail.com>

	* java/io/natFileDescriptorWin32.cc 
	(java::io::FileDescriptor::read): Return -1 (EOF) if ReadFile( )
	returns with Win32 error code ERROR_BROKEN_PIPE.

Index: java/io/natFileDescriptorWin32.cc
===================================================================
--- java/io/natFileDescriptorWin32.cc	2003-02-11 21:52:43.000000000 +0530
+++ java/io/natFileDescriptorWin32.cc	2003-02-11 21:56:38.000000000 +0530
@@ -1,5 +1,6 @@
 // natFileDescriptorWin32.cc - Native part of FileDescriptor class.
 
-/* Copyright (C) 1998, 1999, 2000, 2001, 2002  Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003  Free Software 
+   Foundation, Inc.
 
    This file is part of libgcj.
@@ -289,5 +290,11 @@
 
   if (! ReadFile ((HANDLE)fd, &buf, 1, &read, NULL))
-    throw new IOException (JvNewStringLatin1 (winerr ()));
+    {
+      if (GetLastError () == ERROR_BROKEN_PIPE)
+        return -1;
+      else
+        throw new IOException (JvNewStringLatin1 (winerr ()));
+    }
+
   if (! read)
     return -1;
@@ -314,7 +321,13 @@
   DWORD read;
   if (! ReadFile((HANDLE)fd, bytes, count, &read, NULL))
-    throw new IOException (JvNewStringLatin1 (winerr ()));
+    {
+      if (GetLastError () == ERROR_BROKEN_PIPE)
+        return -1;
+      else
+        throw new IOException (JvNewStringLatin1 (winerr ()));
+    }
 
   if (read == 0) return -1;
+
   return (jint)read;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]