mirror of
https://github.com/corda/corda.git
synced 2025-01-08 14:03:06 +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.DatagramSocket;
|
||||||
import java.net.StandardProtocolFamily;
|
import java.net.StandardProtocolFamily;
|
||||||
|
|
||||||
|
// TODO: This class is both divergent from the Java standard and incomplete.
|
||||||
public class DatagramChannel extends SelectableChannel
|
public class DatagramChannel extends SelectableChannel
|
||||||
implements ReadableByteChannel, WritableByteChannel
|
implements ReadableByteChannel, WritableByteChannel
|
||||||
{
|
{
|
||||||
@ -27,15 +28,20 @@ public class DatagramChannel extends SelectableChannel
|
|||||||
|
|
||||||
private int socket = InvalidSocket;
|
private int socket = InvalidSocket;
|
||||||
private boolean blocking = true;
|
private boolean blocking = true;
|
||||||
|
private boolean connected = false;
|
||||||
|
|
||||||
public SelectableChannel configureBlocking(boolean v) throws IOException {
|
public SelectableChannel configureBlocking(boolean v) throws IOException {
|
||||||
blocking = v;
|
blocking = v;
|
||||||
if (socket != InvalidSocket) {
|
configureBlocking();
|
||||||
configureBlocking(socket, v);
|
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void configureBlocking() throws IOException {
|
||||||
|
if (socket != InvalidSocket) {
|
||||||
|
configureBlocking(socket, blocking);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int socketFD() {
|
int socketFD() {
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
@ -75,6 +81,7 @@ public class DatagramChannel extends SelectableChannel
|
|||||||
}
|
}
|
||||||
|
|
||||||
socket = bind(inetAddress.getHostName(), inetAddress.getPort());
|
socket = bind(inetAddress.getHostName(), inetAddress.getPort());
|
||||||
|
configureBlocking();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -88,6 +95,9 @@ public class DatagramChannel extends SelectableChannel
|
|||||||
}
|
}
|
||||||
|
|
||||||
socket = connect(inetAddress.getHostName(), inetAddress.getPort());
|
socket = connect(inetAddress.getHostName(), inetAddress.getPort());
|
||||||
|
configureBlocking();
|
||||||
|
|
||||||
|
if (socket != 0) connected = true;
|
||||||
|
|
||||||
return this;
|
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)
|
private static native void configureBlocking(int socket, boolean blocking)
|
||||||
throws IOException;
|
throws IOException;
|
||||||
private static native int bind(String hostname, int port)
|
private static native int bind(String hostname, int port)
|
||||||
|
Loading…
Reference in New Issue
Block a user