From b66d8b9fbfca09192ebb782a2cbfdfc07f830511 Mon Sep 17 00:00:00 2001 From: JET Date: Tue, 2 Jul 2013 10:10:05 -0600 Subject: [PATCH] Expanded DatagramChannel and corrected blocking configuration in connect(). --- .../java/nio/channels/DatagramChannel.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/classpath/java/nio/channels/DatagramChannel.java b/classpath/java/nio/channels/DatagramChannel.java index ae30c75780..da9960fd27 100644 --- a/classpath/java/nio/channels/DatagramChannel.java +++ b/classpath/java/nio/channels/DatagramChannel.java @@ -20,6 +20,7 @@ import java.net.SocketException; import java.net.DatagramSocket; import java.net.StandardProtocolFamily; +// TODO: This class is both divergent from the Java standard and incomplete. public class DatagramChannel extends SelectableChannel implements ReadableByteChannel, WritableByteChannel { @@ -27,15 +28,20 @@ public class DatagramChannel extends SelectableChannel private int socket = InvalidSocket; private boolean blocking = true; + private boolean connected = false; public SelectableChannel configureBlocking(boolean v) throws IOException { blocking = v; - if (socket != InvalidSocket) { - configureBlocking(socket, v); - } + configureBlocking(); return this; } + private void configureBlocking() throws IOException { + if (socket != InvalidSocket) { + configureBlocking(socket, blocking); + } + } + int socketFD() { return socket; } @@ -75,6 +81,7 @@ public class DatagramChannel extends SelectableChannel } socket = bind(inetAddress.getHostName(), inetAddress.getPort()); + configureBlocking(); return this; } @@ -88,6 +95,9 @@ public class DatagramChannel extends SelectableChannel } socket = connect(inetAddress.getHostName(), inetAddress.getPort()); + configureBlocking(); + + if (socket != 0) connected = true; return this; } @@ -164,6 +174,15 @@ public class DatagramChannel extends SelectableChannel } } + public boolean isConnected() { return connected; } + + /** TODO: This is probably incomplete. */ + public DatagramChannel disconnect() throws IOException { + close(); + connected = false; + return this; + } + private static native void configureBlocking(int socket, boolean blocking) throws IOException; private static native int bind(String hostname, int port)