mirror of
https://github.com/corda/corda.git
synced 2025-06-13 12:48:18 +00:00
Implemented a basic NIO socket channel interface. Non-blocking socket channels
and server socket channels are implemented. This version works but only when libnative is linked with g++ (because of C++ object creation code that fails without this linking)
This commit is contained in:
39
classpath/java/nio/channels/ServerSocketChannel.java
Normal file
39
classpath/java/nio/channels/ServerSocketChannel.java
Normal file
@ -0,0 +1,39 @@
|
||||
package java.nio.channels;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public class ServerSocketChannel extends SocketChannel {
|
||||
public static ServerSocketChannel open() {
|
||||
return new ServerSocketChannel();
|
||||
}
|
||||
|
||||
public SocketChannel accept() throws Exception {
|
||||
SocketChannel c = new SocketChannel();
|
||||
c.socket = doAccept();
|
||||
c.connected = true;
|
||||
return c;
|
||||
}
|
||||
|
||||
public Handle socket() {
|
||||
return new Handle();
|
||||
}
|
||||
|
||||
private int doAccept() throws Exception {
|
||||
return natDoAccept(socket);
|
||||
}
|
||||
|
||||
private int doListen(String host, int port) throws Exception {
|
||||
return natDoListen(host, port);
|
||||
}
|
||||
|
||||
public class Handle {
|
||||
public void bind(InetSocketAddress address)
|
||||
throws Exception
|
||||
{
|
||||
socket = doListen(address.getHostName(), address.getPort());
|
||||
}
|
||||
}
|
||||
|
||||
private static native int natDoAccept(int socket) throws Exception;
|
||||
private static native int natDoListen(String host, int port) throws Exception;
|
||||
}
|
Reference in New Issue
Block a user