X-Git-Url: http://git.megacz.com/?p=org.ibex.jinetd.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjinetd%2FPort.java;h=b4d103905265c09aa362a952f3c8118bb15b4cc9;hp=a55f7afae6295adb0286f876691fab4d0063c281;hb=df13dadbee1a679518ccebbf417a11ec17c77aec;hpb=71778e79b8d806591e9701f1798f338bdaa5e8f9 diff --git a/src/org/ibex/jinetd/Port.java b/src/org/ibex/jinetd/Port.java index a55f7af..b4d1039 100644 --- a/src/org/ibex/jinetd/Port.java +++ b/src/org/ibex/jinetd/Port.java @@ -1,3 +1,7 @@ +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the Apache Public Source License 2.0 ("the License"). +// You may not use this file except in compliance with the License. + package org.ibex.jinetd; import org.ibex.util.*; import org.ibex.io.*; @@ -6,95 +10,43 @@ import java.util.*; import java.net.*; import java.util.zip.*; + +// Feature: port-level redirects public class Port extends Loader { + final ThreadPool tp; final InetAddress bindTo; final int port; private static Hash cache = new Hash(); - public static Port newPort(String path, InetAddress bindTo, int port) throws IOException { + public static Port newPort(String path, InetAddress bindTo, int port, ThreadPool tp) throws IOException { String canonical = new File(path).getCanonicalPath(); Port p = (Port)cache.get(canonical); - if (p == null) cache.put(canonical, p = new Port(path, bindTo, port)); + if (p == null) cache.put(canonical, p = new Port(path, bindTo, port, tp)); else Log.warn(Port.class, " sharing " + bindTo+":"+port+" -> "+ (p.bindTo+":"+p.port)); p.spawn(bindTo, port); return p; } void spawn(InetAddress bindTo, int port) { new PortThread(bindTo, port).start(); } - private Port(String path, InetAddress bindTo, int port) { - super(path); - this.bindTo = bindTo; - this.port = port; - } + private Port(String path, InetAddress bindTo, int port, ThreadPool tp) { + super(path); this.bindTo = bindTo; this.port = port; this.tp = tp; } public void changed(Watched w) { //Log.warn(this, "Port: noticed change in " + w); super.changed(w); } - - Class isListener(String name) throws ClassNotFoundException { - final ClassLoader cl = getClassLoader(); - final Class c = cl.loadClass(name); - if (c == null) return null; - if (Listener.class.isAssignableFrom(c) && c != Listener.class) return c; - return null; - } - - Class findListener() throws Exception { - getClassLoader(); - String[] list = list(); - for(int i=0; i " + c.getName()); Log.clearnotes(); - final ClassLoader cl = getClassLoader(); Thread.currentThread().setContextClassLoader(cl); Listener l = (Listener)c.newInstance(); l.accept(conn); @@ -102,13 +54,12 @@ public class Port extends Loader { Log.warn(this, "end of stream reached handling connection from " + conn.getRemoteHostname() + ":" + conn.getRemotePort()); } catch (Exception e) { - Log.error(this, "Listener threw exception"); Log.error(this, e); conn.close(); } finally { conn.close(); } - } }).start(); + } }); } private class PortThread extends Thread {