X-Git-Url: http://git.megacz.com/?p=org.ibex.jinetd.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjinetd%2FPort.java;h=8a92dd74bef8a8920ba20c606970c6016f929518;hp=470c0a0305baf05d893f6b283ec0dee348caad79;hb=5d36398ed04551d352ed4b185c036c5cd3433282;hpb=792b114e78d5d2a23498fb8b784b404f89c4106a diff --git a/src/org/ibex/jinetd/Port.java b/src/org/ibex/jinetd/Port.java index 470c0a0..8a92dd7 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,6 +10,8 @@ import java.util.*; import java.net.*; import java.util.zip.*; + +// Feature: port-level redirects public class Port extends Loader { final InetAddress bindTo; @@ -33,7 +39,16 @@ public class Port extends Loader { super.changed(w); } - boolean dispatch(final Connection conn) throws Exception { + + 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); - try { - Listener l = (Listener)c.newInstance(); - l.accept(conn); - } catch (Exception e) { - Log.error(c, "Listener threw exception"); - Log.error(c, e); - } finally { - conn.close(); - } - } }).start(); - return true; - } catch (Exception e) { Log.error(this, e); } - return false; + 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, e); + conn.close(); + } finally { + conn.close(); + } + } }).start(); } private class PortThread extends Thread { @@ -107,10 +126,7 @@ public class Port extends Loader { ", port " + port); ServerSocket ss = bindTo == null ? new ServerSocket(port) : new ServerSocket(port, 0, bindTo); for(Socket s = ss.accept(); ; s = ss.accept()) try { - if (!dispatch(new Connection(s, "megacz.com"))) { - Log.warn(this, "no handler for connection on port " + port); - s.close(); - } + dispatch(new Connection(s, "megacz.com")); } catch (Exception e) { Log.warn(Port.class, e); } } catch (Exception e) { Log.error(Port.class, e); } catch (Throwable t) {