Paul Jenner helpfully pointed out some problems when running Azureus with the epoll selector, and the modified DatagramSocket implementation.
2006-09-21 Casey Marshall <[EMAIL PROTECTED]> * gnu/java/net/PlainDatagramSocketImpl.java (send): ignore `InterruptedIOException;' try again if it gets thrown. (receive): likewise, but re-throw `SocketTimeoutException.' * gnu/java/nio/EpollSelectorImpl.java (doSelect): just return 0 if we have nothing to select. Committed.
### Eclipse Workspace Patch 1.0 #P classpath Index: gnu/java/nio/EpollSelectorImpl.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/nio/EpollSelectorImpl.java,v retrieving revision 1.1 diff -u -r1.1 EpollSelectorImpl.java --- gnu/java/nio/EpollSelectorImpl.java 20 Sep 2006 21:39:41 -0000 1.1 +++ gnu/java/nio/EpollSelectorImpl.java 21 Sep 2006 23:16:22 -0000 @@ -140,6 +140,10 @@ key.valid = false; keys.remove(new Integer(key.fd)); } + + // Don't bother if we have nothing to select. + if (keys.isEmpty()) + return 0; ByteBuffer selected = ByteBuffer.allocateDirect(keys.size() * sizeof_struct_epoll_event); Index: gnu/java/net/PlainDatagramSocketImpl.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/net/PlainDatagramSocketImpl.java,v retrieving revision 1.11 diff -u -r1.11 PlainDatagramSocketImpl.java --- gnu/java/net/PlainDatagramSocketImpl.java 17 Sep 2006 07:31:41 -0000 1.11 +++ gnu/java/net/PlainDatagramSocketImpl.java 21 Sep 2006 23:16:22 -0000 @@ -41,6 +41,7 @@ import gnu.java.nio.VMChannel; import java.io.IOException; +import java.io.InterruptedIOException; import java.lang.reflect.Field; import java.net.DatagramPacket; import java.net.DatagramSocketImpl; @@ -49,6 +50,7 @@ import java.net.NetworkInterface; import java.net.SocketAddress; import java.net.SocketException; +import java.net.SocketTimeoutException; import java.nio.ByteBuffer; /** @@ -259,7 +261,17 @@ throw new NullPointerException(); if (port <= 0) throw new SocketException("invalid port " + port); - channel.send(buf, new InetSocketAddress(remote, port)); + while (true) + { + try + { + channel.send(buf, new InetSocketAddress(remote, port)); + } + catch (InterruptedIOException ioe) + { + // Ignore; interrupted system call. + } + } } } @@ -278,7 +290,23 @@ ByteBuffer buf = ByteBuffer.wrap(packet.getData(), packet.getOffset(), packet.getLength()); - SocketAddress addr = channel.receive(buf); + SocketAddress addr = null; + while (true) + { + try + { + addr = channel.receive(buf); + break; + } + catch (SocketTimeoutException ste) + { + throw ste; + } + catch (InterruptedIOException iioe) + { + // Ignore. Loop. + } + } if (addr != null) packet.setSocketAddress(addr); packet.setLength(buf.position() - packet.getOffset());