aboutsummaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authorMohan Embar <gnustuff@thisiscool.com>2003-12-11 15:35:13 +0000
committerMohan Embar <membar@gcc.gnu.org>2003-12-11 15:35:13 +0000
commitc1fb3625aebaa9ccacc16eb185f04a93e4ed459f (patch)
treea17332ea63799b3f5567f998f28e81a0b0f834c9 /libjava
parent834b1209074da1983d7688ba5eebb54e9c9920ef (diff)
downloadgcc-c1fb3625aebaa9ccacc16eb185f04a93e4ed459f.zip
gcc-c1fb3625aebaa9ccacc16eb185f04a93e4ed459f.tar.gz
gcc-c1fb3625aebaa9ccacc16eb185f04a93e4ed459f.tar.bz2
* gnu/java/nio/SocketChannelImpl.java
(write): Removed diagnostic trace. * gnu/java/nio/natSelectorImplPosix.cc: Added includes for java.lang.Thread and java.io.InterruptedIOException. (helper_put_filedescriptors): Don't put invalid file descriptors in select set. (helper_get_filedescriptors): Clear invalid file descriptors from select set. (helper_reset): New method for clearing our file descriptor array. (implSelect): Correctly calculate timeout if specified and legal. Intercept and deal with any java.io.InterruptedIOException thrown by _Jv_select(). From-SVN: r74537
Diffstat (limited to 'libjava')
-rw-r--r--libjava/ChangeLog17
-rw-r--r--libjava/gnu/java/nio/SocketChannelImpl.java2
-rw-r--r--libjava/gnu/java/nio/natSelectorImplPosix.cc58
3 files changed, 63 insertions, 14 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 09b1e98..5a7f73b 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,20 @@
+2003-12-11 Mohan Embar <gnustuff@thisiscool.com>
+
+ * gnu/java/nio/SocketChannelImpl.java
+ (write): Removed diagnostic trace.
+ * gnu/java/nio/natSelectorImplPosix.cc: Added
+ includes for java.lang.Thread and java.io.InterruptedIOException.
+ (helper_put_filedescriptors): Don't put invalid file descriptors
+ in select set.
+ (helper_get_filedescriptors): Clear invalid file descriptors
+ from select set.
+ (helper_reset): New method for clearing our file descriptor
+ array.
+ (implSelect): Correctly calculate timeout if specified and
+ legal.
+ Intercept and deal with any java.io.InterruptedIOException
+ thrown by _Jv_select().
+
2003-12-08 Fernando Nasser <fnasser@redhat.com>
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c (awt_event_handler):
diff --git a/libjava/gnu/java/nio/SocketChannelImpl.java b/libjava/gnu/java/nio/SocketChannelImpl.java
index 46c0d8c..ced8ef2 100644
--- a/libjava/gnu/java/nio/SocketChannelImpl.java
+++ b/libjava/gnu/java/nio/SocketChannelImpl.java
@@ -301,8 +301,6 @@ public final class SocketChannelImpl extends SocketChannel
data = src.array();
}
- System.out.println ("INTERNAL: writing to socket outputstream");
-
OutputStream output = socket.getOutputStream();
output.write (data, offset, len);
diff --git a/libjava/gnu/java/nio/natSelectorImplPosix.cc b/libjava/gnu/java/nio/natSelectorImplPosix.cc
index 81de3ed..ac16dac 100644
--- a/libjava/gnu/java/nio/natSelectorImplPosix.cc
+++ b/libjava/gnu/java/nio/natSelectorImplPosix.cc
@@ -15,7 +15,9 @@ details. */
#include <string.h>
#include <gnu/java/nio/SelectorImpl.h>
+#include <java/io/InterruptedIOException.h>
#include <java/io/IOException.h>
+#include <java/lang/Thread.h>
static void
helper_put_filedescriptors (jintArray fdArray, fd_set& fds, int& max_fd)
@@ -24,10 +26,14 @@ helper_put_filedescriptors (jintArray fdArray, fd_set& fds, int& max_fd)
for (int index = 0; index < JvGetArrayLength (fdArray); index++)
{
- FD_SET (tmpFDArray [index], &fds);
-
- if (tmpFDArray [index] > max_fd)
- max_fd = tmpFDArray [index];
+ int fd = tmpFDArray [index];
+ if (fd > 0)
+ {
+ FD_SET (tmpFDArray [index], &fds);
+
+ if (tmpFDArray [index] > max_fd)
+ max_fd = tmpFDArray [index];
+ }
}
}
@@ -37,8 +43,20 @@ helper_get_filedescriptors (jintArray& fdArray, fd_set fds)
jint* tmpFDArray = elements (fdArray);
for (int index = 0; index < JvGetArrayLength (fdArray); index++)
- if (!FD_ISSET (tmpFDArray [index], &fds))
- tmpFDArray [index] = 0;
+ {
+ int fd = tmpFDArray [index];
+ if (fd < 0 || !FD_ISSET (fd, &fds))
+ tmpFDArray [index] = 0;
+ }
+}
+
+static void
+helper_reset (jintArray& fdArray)
+{
+ jint* tmpFDArray = elements (fdArray);
+
+ for (int index = 0; index < JvGetArrayLength (fdArray); index++)
+ tmpFDArray [index] = 0;
}
jint
@@ -53,15 +71,15 @@ gnu::java::nio::SelectorImpl::implSelect (jintArray read, jintArray write,
struct timeval real_time_data;
struct timeval *time_data = NULL;
- real_time_data.tv_sec = 0;
- real_time_data.tv_usec = timeout;
-
- // If not legal timeout value is given, use NULL.
+ // If a legal timeout value isn't given, use NULL.
// This means an infinite timeout. The specification
// also says that a zero timeout should be treated
- // as infinite.
+ // as infinite. Otherwise (if the timeout value is legal),
+ // fill our timeval struct and use it for the select.
if (timeout > 0)
{
+ real_time_data.tv_sec = timeout / 1000;
+ real_time_data.tv_usec = (timeout % 1000) * 1000;
time_data = &real_time_data;
}
@@ -76,7 +94,23 @@ gnu::java::nio::SelectorImpl::implSelect (jintArray read, jintArray write,
helper_put_filedescriptors (except, except_fds, max_fd);
// Actually do the select
- result = _Jv_select (max_fd + 1, &read_fds, &write_fds, &except_fds, time_data);
+ try
+ {
+ result = _Jv_select (max_fd + 1, &read_fds, &write_fds,
+ &except_fds, time_data);
+ }
+ catch (::java::io::InterruptedIOException *e)
+ {
+ // The behavior of JRE 1.4.1 is that no exception is thrown
+ // when the thread is interrupted, but the thread's interrupt
+ // status is set. Clear all of our select sets and return 0,
+ // indicating that nothing was selected.
+ ::java::lang::Thread::currentThread ()->interrupt ();
+ helper_reset (read);
+ helper_reset (write);
+ helper_reset (except);
+ return 0;
+ }
if (result < 0)
{