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] [MinGW]: Reset/Ignore Thread Interruption for Plain[Datagram]SocketImpl


Hi People,

Operations on Plain[Datagram]Socket aren't
interruptible under Sun's JRE; this patch simply
resets and ignores the thread's interrupted
flag after such operations. With this patch,
I get an almost-perfect diff with the attached test
between Sun's JRE 1.4.2 and gcj on Win32.

-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/

ChangeLog
2003-12-11  Mohan Embar  <gnustuff@thisiscool.com>

	* gnu/java/net/natPlainDatagramSocketImplWin32.cc:
	Removed unused InterruptedIOException.h include.
	* gnu/java/net/natPlainSocketImplWin32.cc
	(connect): Reset and ignore our thread's interrupted
	flag instead of testing and throwing an InterruptedIOException
	if set.
	(accept): Likewise + changed case of SocketTimeoutException
	text.
	(write): Likewise (for both overloads).
	(doRead): Likewise.

Index: gnu/java/net/natPlainDatagramSocketImplWin32.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/net/natPlainDatagramSocketImplWin32.cc,v
retrieving revision 1.6
diff -u -2 -r1.6 natPlainDatagramSocketImplWin32.cc
--- gnu/java/net/natPlainDatagramSocketImplWin32.cc	4 Dec 2003 10:59:56 -0000	1.6
+++ gnu/java/net/natPlainDatagramSocketImplWin32.cc	12 Dec 2003 04:14:20 -0000
@@ -18,5 +18,4 @@
 #include <gnu/java/net/PlainDatagramSocketImpl.h>
 #include <java/io/IOException.h>
-#include <java/io/InterruptedIOException.h>
 #include <java/net/BindException.h>
 #include <java/net/SocketException.h>
Index: gnu/java/net/natPlainSocketImplWin32.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/net/natPlainSocketImplWin32.cc,v
retrieving revision 1.8
diff -u -2 -r1.8 natPlainSocketImplWin32.cc
--- gnu/java/net/natPlainSocketImplWin32.cc	1 Dec 2003 14:32:26 -0000	1.8
+++ gnu/java/net/natPlainSocketImplWin32.cc	12 Dec 2003 04:14:21 -0000
@@ -18,5 +18,4 @@
 #include <gnu/java/net/PlainSocketImpl$SocketOutputStream.h>
 #include <java/io/IOException.h>
-#include <java/io/InterruptedIOException.h>
 #include <java/net/BindException.h>
 #include <java/net/ConnectException.h>
@@ -177,7 +176,11 @@
             // MS constants got undefined
 
+        // Reset and ignore our thread's interrupted flag.
+        // It's not possible to interrupt these sort of
+        // operations on Win32 anyway.
+        ::java::lang::Thread::interrupted();
+
         if (dwRet == WSA_WAIT_FAILED)
           throwConnectException ();
-        
         else if (dwRet == WSA_WAIT_TIMEOUT)
           throw new ::java::net::SocketTimeoutException
@@ -276,9 +279,12 @@
             // MS constants got undefined
 
+        // Reset and ignore our thread's interrupted flag.
+        ::java::lang::Thread::interrupted();
+
         if (dwRet == WSA_WAIT_FAILED)
           goto error;
         else if (dwRet == WSA_WAIT_TIMEOUT)
           throw new ::java::net::SocketTimeoutException
-            (JvNewStringUTF ("accept timed out"));
+            (JvNewStringUTF ("Accept timed out"));
       }
     }
@@ -362,12 +368,10 @@
         {
           DWORD dwErr = WSAGetLastError();
-          if (::java::lang::Thread::interrupted())
-            {
-              ::java::io::InterruptedIOException *iioe
-                = new ::java::io::InterruptedIOException
-                (_Jv_WinStrError (dwErr));
-              iioe->bytesTransferred = 0;
-              throw iioe;
-            }
+          
+          // Reset and ignore our thread's interrupted flag.
+          // It's not possible to interrupt these sort of
+          // operations on Win32 anyway.
+          ::java::lang::Thread::interrupted();
+
           // Some errors should not cause exceptions.
           if (dwErr != WSAENOTCONN && dwErr != WSAECONNRESET
@@ -398,12 +402,8 @@
         {
           DWORD dwErr = WSAGetLastError();
-          if (::java::lang::Thread::interrupted())
-            {
-              ::java::io::InterruptedIOException *iioe
-                = new ::java::io::InterruptedIOException
-                (_Jv_WinStrError (dwErr));
-              iioe->bytesTransferred = written;
-              throw iioe;
-            }
+
+          // Reset and ignore our thread's interrupted flag.
+          ::java::lang::Thread::interrupted();
+
           // Some errors should not cause exceptions.
           if (dwErr != WSAENOTCONN && dwErr != WSAECONNRESET
@@ -457,13 +457,8 @@
     // save WSAGetLastError() before calling Thread.interrupted()
   
-  if (::java::lang::Thread::interrupted())
-    {
-      ::java::io::InterruptedIOException *iioe =
-        new ::java::io::InterruptedIOException
-        (JvNewStringUTF("read interrupted"));
-      iioe->bytesTransferred = r == -1 ? 0 : r;
-      throw iioe;
-    }
-  else if (r == -1)
+  // Reset and ignore our thread's interrupted flag.
+  ::java::lang::Thread::interrupted();
+  
+  if (r == -1)
     {
 error:
@@ -475,5 +470,5 @@
       if (dwErrorCode == WSAETIMEDOUT)
         throw new ::java::net::SocketTimeoutException
-          (JvNewStringUTF ("read timed out") );
+          (JvNewStringUTF ("Read timed out") );
       else
         _Jv_ThrowIOException (dwErrorCode);

Attachment: NetTest.tar.bz2
Description: application/bzip2


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