mirror of
https://github.com/corda/corda.git
synced 2025-01-06 05:04:20 +00:00
Expanded DatagramChannel and corrected blocking configuration in connect().
This commit is contained in:
parent
e07a1e2f57
commit
b66d8b9fbf
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user