|
@@ -13,6 +13,10 @@ import de.tudarmstadt.informatik.hostage.system.PrivilegedPort;
|
|
|
|
|
|
public class MyServerSocketFactory extends ServerSocketFactory {
|
|
|
|
|
|
+ /**
|
|
|
+ * This method creates and returns a ServerSocket. A custom SocketImpl is
|
|
|
+ * injected into the ServerSocket.
|
|
|
+ */
|
|
|
@Override
|
|
|
public ServerSocket createServerSocket(int port) throws IOException {
|
|
|
FileDescriptor fd = new PrivilegedPort(port).bindAndGetFD();
|
|
@@ -30,12 +34,18 @@ public class MyServerSocketFactory extends ServerSocketFactory {
|
|
|
return socket;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Extracts the SocketImpl out of a ServerSocket.
|
|
|
+ */
|
|
|
private SocketImpl getImpl(ServerSocket socket) throws Exception {
|
|
|
Field implField = socket.getClass().getDeclaredField("impl");
|
|
|
implField.setAccessible(true);
|
|
|
return (SocketImpl) implField.get(socket);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Injects a FileDescriptor into a SocketImpl.
|
|
|
+ */
|
|
|
private void injectFD(FileDescriptor fd, SocketImpl impl) throws Exception {
|
|
|
Class<?> plainServerSocketImplClazz = impl.getClass();
|
|
|
Class<?> plainSocketImplClazz = plainServerSocketImplClazz
|
|
@@ -46,6 +56,9 @@ public class MyServerSocketFactory extends ServerSocketFactory {
|
|
|
fdField.set(impl, fd);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Injects a SocketImpl into a ServerSocket.
|
|
|
+ */
|
|
|
private void injectImpl(SocketImpl impl, ServerSocket socket)
|
|
|
throws Exception {
|
|
|
Field implField = socket.getClass().getDeclaredField("impl");
|
|
@@ -53,18 +66,27 @@ public class MyServerSocketFactory extends ServerSocketFactory {
|
|
|
implField.set(socket, impl);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Sets the isBound Field of a ServerSocket to true.
|
|
|
+ */
|
|
|
private void setBound(ServerSocket socket) throws Exception {
|
|
|
Field boundField = socket.getClass().getDeclaredField("isBound");
|
|
|
boundField.setAccessible(true);
|
|
|
boundField.set(socket, true);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Must override.
|
|
|
+ */
|
|
|
@Override
|
|
|
public ServerSocket createServerSocket(int port, int backlog)
|
|
|
throws IOException {
|
|
|
return createServerSocket(port);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Must override.
|
|
|
+ */
|
|
|
@Override
|
|
|
public ServerSocket createServerSocket(int port, int backlog,
|
|
|
InetAddress iAddress) throws IOException {
|