Patch: FYI: EINTR handling
Tom Tromey
tromey@redhat.com
Sat Jul 26 00:39:00 GMT 2003
I'm checking this in on the trunk.
I ran into a situation where a child process exiting caused a SIGCHLD
to interrupt a read() call in FileDescriptor. This in turn caused an
IOException.
I don't think this is correct. Instead, I think we want to try again
if we see EINTR. To that end, I'm checking in the appended patch.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* java/io/natFileDescriptorPosix.cc (write): Try again on EINTR.
(write): Likewise.
(read): Likewise.
(read): Likewise.
Index: java/io/natFileDescriptorPosix.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/natFileDescriptorPosix.cc,v
retrieving revision 1.28
diff -u -r1.28 natFileDescriptorPosix.cc
--- java/io/natFileDescriptorPosix.cc 5 Jun 2003 22:37:02 -0000 1.28
+++ java/io/natFileDescriptorPosix.cc 26 Jul 2003 00:36:18 -0000
@@ -150,7 +150,8 @@
iioe->bytesTransferred = r == -1 ? 0 : r;
throw iioe;
}
- throw new IOException (JvNewStringLatin1 (strerror (errno)));
+ if (errno != EINTR)
+ throw new IOException (JvNewStringLatin1 (strerror (errno)));
}
}
position++;
@@ -178,7 +179,8 @@
iioe->bytesTransferred = written;
throw iioe;
}
- throw new IOException (JvNewStringLatin1 (strerror (errno)));
+ if (errno != EINTR)
+ throw new IOException (JvNewStringLatin1 (strerror (errno)));
}
written += r;
@@ -282,20 +284,26 @@
java::io::FileDescriptor::read (void)
{
jbyte b;
- int r = ::read (fd, &b, 1);
- if (r == 0)
- return -1;
- if (r == -1)
+ int r;
+ do
{
- if (java::lang::Thread::interrupted())
+ r = ::read (fd, &b, 1);
+ if (r == 0)
+ return -1;
+ if (r == -1)
{
- InterruptedIOException *iioe
- = new InterruptedIOException (JvNewStringLatin1 (strerror (errno)));
- iioe->bytesTransferred = r == -1 ? 0 : r;
- throw iioe;
+ if (java::lang::Thread::interrupted())
+ {
+ InterruptedIOException *iioe
+ = new InterruptedIOException (JvNewStringLatin1 (strerror (errno)));
+ iioe->bytesTransferred = r == -1 ? 0 : r;
+ throw iioe;
+ }
+ if (errno != EINTR)
+ throw new IOException (JvNewStringLatin1 (strerror (errno)));
}
- throw new IOException (JvNewStringLatin1 (strerror (errno)));
}
+ while (r != 1);
position++;
return b & 0xFF;
}
@@ -314,20 +322,26 @@
return 0;
jbyte *bytes = elements (buffer) + offset;
- int r = ::read (fd, bytes, count);
- if (r == 0)
- return -1;
- if (r == -1)
- {
- if (java::lang::Thread::interrupted())
+ int r;
+ do
+ {
+ r = ::read (fd, bytes, count);
+ if (r == 0)
+ return -1;
+ if (r == -1)
{
- InterruptedIOException *iioe
- = new InterruptedIOException (JvNewStringLatin1 (strerror (errno)));
- iioe->bytesTransferred = r == -1 ? 0 : r;
- throw iioe;
+ if (java::lang::Thread::interrupted())
+ {
+ InterruptedIOException *iioe
+ = new InterruptedIOException (JvNewStringLatin1 (strerror (errno)));
+ iioe->bytesTransferred = r == -1 ? 0 : r;
+ throw iioe;
+ }
+ if (errno != EINTR)
+ throw new IOException (JvNewStringLatin1 (strerror (errno)));
}
- throw new IOException (JvNewStringLatin1 (strerror (errno)));
}
+ while (r <= 0);
position += r;
return r;
}
More information about the Java-patches
mailing list