X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjinetd%2FPort.java;h=200ce2c34e9fccbc7e775795588b9b088489386d;hb=HEAD;hp=8ac02a5f75e598a0bb7e38fc2b55fce16b44c130;hpb=383219a33fe21df43472e0a3cb5341c7f7d44a00;p=org.ibex.jinetd.git diff --git a/src/org/ibex/jinetd/Port.java b/src/org/ibex/jinetd/Port.java index 8ac02a5..200ce2c 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,104 +10,52 @@ import java.util.*; import java.net.*; import java.util.zip.*; -public class Port extends Loader { +// Feature: port-level redirects +public class Port extends TreeClassLoader { + 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; - } - - 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() + ":"+conn.getLocalPort()); Log.clearnotes(); - final ClassLoader cl = getClassLoader(); - Thread.currentThread().setContextClassLoader(cl); + Thread.currentThread().setContextClassLoader(Port.this); Listener l = (Listener)c.newInstance(); l.accept(conn); + } catch (org.ibex.io.Stream.EOF eof) { + 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 { @@ -112,17 +64,16 @@ public class Port extends Loader { public PortThread(InetAddress bindTo, int port) { this.bindTo = bindTo; this.port = port; } public void run() { try { - Log.warn(this, "Now listening on address " + (bindTo == null ? "all interfaces" : bindTo.toString()) + - ", port " + port); + Log.warn(this, "Now listening on address " + (bindTo==null?"all interfaces":bindTo.toString()) + ", port " + port); ServerSocket ss = bindTo == null ? new ServerSocket(port) : new ServerSocket(port, 0, bindTo); for(Socket s = ss.accept(); ; s = ss.accept()) try { - dispatch(new Connection(s, "megacz.com")); + dispatch(new Connection(s, Main.defaultDomain)); } catch (Exception e) { Log.warn(Port.class, e); } } catch (Exception e) { Log.error(Port.class, e); } catch (Throwable t) { Log.error(this, "serious error, aborting VM"); Log.error(this, t); - Root.reboot(); + Main.reboot(); } } }