2008-02-19 18:06:52 +00:00
|
|
|
/* Copyright (c) 2008, Avian Contributors
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
2007-10-05 21:32:56 +00:00
|
|
|
package java.nio.channels;
|
|
|
|
|
2008-03-25 17:18:17 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2007-10-05 21:32:56 +00:00
|
|
|
import java.net.InetSocketAddress;
|
2008-03-25 17:18:17 +00:00
|
|
|
import java.net.SocketAddress;
|
|
|
|
import java.net.ServerSocket;
|
2007-10-05 21:32:56 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-03-25 17:18:17 +00:00
|
|
|
public ServerSocket socket() {
|
2007-10-05 21:32:56 +00:00
|
|
|
return new Handle();
|
|
|
|
}
|
|
|
|
|
2008-03-25 17:18:17 +00:00
|
|
|
private int doAccept() throws IOException {
|
2007-10-05 21:32:56 +00:00
|
|
|
return natDoAccept(socket);
|
|
|
|
}
|
|
|
|
|
2008-03-25 17:18:17 +00:00
|
|
|
private int doListen(String host, int port) throws IOException {
|
2007-10-05 21:32:56 +00:00
|
|
|
return natDoListen(host, port);
|
|
|
|
}
|
|
|
|
|
2008-03-25 17:18:17 +00:00
|
|
|
public class Handle extends ServerSocket {
|
|
|
|
public void bind(SocketAddress address)
|
|
|
|
throws IOException
|
2007-10-05 21:32:56 +00:00
|
|
|
{
|
2008-03-25 17:18:17 +00:00
|
|
|
InetSocketAddress a;
|
|
|
|
try {
|
|
|
|
a = (InetSocketAddress) address;
|
|
|
|
} catch (ClassCastException e) {
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
|
|
|
socket = doListen(a.getHostName(), a.getPort());
|
2007-10-05 21:32:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-25 17:18:17 +00:00
|
|
|
private static native int natDoAccept(int socket) throws IOException;
|
|
|
|
private static native int natDoListen(String host, int port) throws IOException;
|
2007-10-05 21:32:56 +00:00
|
|
|
}
|