changeset 909:c60c1adfac3e

simplify connectors
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 08 Oct 2016 21:15:28 -0600
parents e003b20780c4
children 9b65e8064f90
files src/org/eclipse/jetty/io/ByteArrayEndPoint.java src/org/eclipse/jetty/server/Connector.java src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java src/org/eclipse/jetty/server/nio/SelectChannelConnector.java
diffstat 4 files changed, 378 insertions(+), 480 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/eclipse/jetty/io/ByteArrayEndPoint.java	Fri Oct 07 15:17:01 2016 -0600
+++ b/src/org/eclipse/jetty/io/ByteArrayEndPoint.java	Sat Oct 08 21:15:28 2016 -0600
@@ -29,380 +29,380 @@
  */
 public class ByteArrayEndPoint implements ConnectedEndPoint
 {
-    protected byte[] _inBytes;
-    protected ByteArrayBuffer _in;
-    protected ByteArrayBuffer _out;
-    protected boolean _closed;
-    protected boolean _nonBlocking;
-    protected boolean _growOutput;
-    protected Connection _connection;
-    protected int _maxIdleTime;
+	protected byte[] _inBytes;
+	protected ByteArrayBuffer _in;
+	protected ByteArrayBuffer _out;
+	protected boolean _closed;
+	protected boolean _nonBlocking;
+	protected boolean _growOutput;
+	protected Connection _connection;
+	protected int _maxIdleTime;
 
 
-    /* ------------------------------------------------------------ */
-    /**
-     *
-     */
-    public ByteArrayEndPoint()
-    {
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 *
+	 */
+	public ByteArrayEndPoint()
+	{
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * @see org.eclipse.jetty.io.ConnectedEndPoint#getConnection()
-     */
-    public Connection getConnection()
-    {
-        return _connection;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * @see org.eclipse.jetty.io.ConnectedEndPoint#getConnection()
+	 */
+	public Connection getConnection()
+	{
+		return _connection;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * @see org.eclipse.jetty.io.ConnectedEndPoint#setConnection(org.eclipse.jetty.io.Connection)
-     */
-    public void setConnection(Connection connection)
-    {
-        _connection=connection;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * @see org.eclipse.jetty.io.ConnectedEndPoint#setConnection(org.eclipse.jetty.io.Connection)
+	 */
+	public void setConnection(Connection connection)
+	{
+		_connection=connection;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * @return the nonBlocking
-     */
-    public boolean isNonBlocking()
-    {
-        return _nonBlocking;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * @return the nonBlocking
+	 */
+	public boolean isNonBlocking()
+	{
+		return _nonBlocking;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * @param nonBlocking the nonBlocking to set
-     */
-    public void setNonBlocking(boolean nonBlocking)
-    {
-        _nonBlocking=nonBlocking;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * @param nonBlocking the nonBlocking to set
+	 */
+	public void setNonBlocking(boolean nonBlocking)
+	{
+		_nonBlocking=nonBlocking;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     *
-     */
-    public ByteArrayEndPoint(byte[] input, int outputSize)
-    {
-        _inBytes=input;
-        _in=new ByteArrayBuffer(input);
-        _out=new ByteArrayBuffer(outputSize);
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 *
+	 */
+	public ByteArrayEndPoint(byte[] input, int outputSize)
+	{
+		_inBytes=input;
+		_in=new ByteArrayBuffer(input);
+		_out=new ByteArrayBuffer(outputSize);
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * @return Returns the in.
-     */
-    public ByteArrayBuffer getIn()
-    {
-        return _in;
-    }
-    /* ------------------------------------------------------------ */
-    /**
-     * @param in The in to set.
-     */
-    public void setIn(ByteArrayBuffer in)
-    {
-        _in = in;
-    }
-    /* ------------------------------------------------------------ */
-    /**
-     * @return Returns the out.
-     */
-    public ByteArrayBuffer getOut()
-    {
-        return _out;
-    }
-    /* ------------------------------------------------------------ */
-    /**
-     * @param out The out to set.
-     */
-    public void setOut(ByteArrayBuffer out)
-    {
-        _out = out;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * @return Returns the in.
+	 */
+	public ByteArrayBuffer getIn()
+	{
+		return _in;
+	}
+	/* ------------------------------------------------------------ */
+	/**
+	 * @param in The in to set.
+	 */
+	public void setIn(ByteArrayBuffer in)
+	{
+		_in = in;
+	}
+	/* ------------------------------------------------------------ */
+	/**
+	 * @return Returns the out.
+	 */
+	public ByteArrayBuffer getOut()
+	{
+		return _out;
+	}
+	/* ------------------------------------------------------------ */
+	/**
+	 * @param out The out to set.
+	 */
+	public void setOut(ByteArrayBuffer out)
+	{
+		_out = out;
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see org.eclipse.io.EndPoint#isOpen()
-     */
-    public boolean isOpen()
-    {
-        return !_closed;
-    }
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see org.eclipse.io.EndPoint#isOpen()
+	 */
+	public boolean isOpen()
+	{
+		return !_closed;
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     *  @see org.eclipse.jetty.io.EndPoint#isInputShutdown()
-     */
-    public boolean isInputShutdown()
-    {
-        return _closed;
-    }
+	/* ------------------------------------------------------------ */
+	/*
+	 *  @see org.eclipse.jetty.io.EndPoint#isInputShutdown()
+	 */
+	public boolean isInputShutdown()
+	{
+		return _closed;
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     *  @see org.eclipse.jetty.io.EndPoint#isOutputShutdown()
-     */
-    public boolean isOutputShutdown()
-    {
-        return _closed;
-    }
+	/* ------------------------------------------------------------ */
+	/*
+	 *  @see org.eclipse.jetty.io.EndPoint#isOutputShutdown()
+	 */
+	public boolean isOutputShutdown()
+	{
+		return _closed;
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see org.eclipse.io.EndPoint#isBlocking()
-     */
-    public boolean isBlocking()
-    {
-        return !_nonBlocking;
-    }
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see org.eclipse.io.EndPoint#isBlocking()
+	 */
+	public boolean isBlocking()
+	{
+		return !_nonBlocking;
+	}
 
-    /* ------------------------------------------------------------ */
-    public boolean blockReadable(long millisecs)
-    {
-        return true;
-    }
+	/* ------------------------------------------------------------ */
+	public boolean blockReadable(long millisecs)
+	{
+		return true;
+	}
 
-    /* ------------------------------------------------------------ */
-    public boolean blockWritable(long millisecs)
-    {
-        return true;
-    }
+	/* ------------------------------------------------------------ */
+	public boolean blockWritable(long millisecs)
+	{
+		return true;
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see org.eclipse.io.EndPoint#shutdownOutput()
-     */
-    public void shutdownOutput() throws IOException
-    {
-        close();
-    }
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see org.eclipse.io.EndPoint#shutdownOutput()
+	 */
+	public void shutdownOutput() throws IOException
+	{
+		close();
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see org.eclipse.io.EndPoint#shutdownInput()
-     */
-    public void shutdownInput() throws IOException
-    {
-        close();
-    }
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see org.eclipse.io.EndPoint#shutdownInput()
+	 */
+	public void shutdownInput() throws IOException
+	{
+		close();
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see org.eclipse.io.EndPoint#close()
-     */
-    public void close() throws IOException
-    {
-        _closed=true;
-    }
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see org.eclipse.io.EndPoint#close()
+	 */
+	public void close() throws IOException
+	{
+		_closed=true;
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see org.eclipse.io.EndPoint#fill(org.eclipse.io.Buffer)
-     */
-    public int fill(Buffer buffer) throws IOException
-    {
-        if (_closed)
-            throw new IOException("CLOSED");
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see org.eclipse.io.EndPoint#fill(org.eclipse.io.Buffer)
+	 */
+	public int fill(Buffer buffer) throws IOException
+	{
+		if (_closed)
+			throw new IOException("CLOSED");
 
-        if (_in!=null && _in.length()>0)
-        {
-            int len = buffer.put(_in);
-            _in.skip(len);
-            return len;
-        }
+		if (_in!=null && _in.length()>0)
+		{
+			int len = buffer.put(_in);
+			_in.skip(len);
+			return len;
+		}
 
-        if (_in!=null && _in.length()==0 && _nonBlocking)
-            return 0;
+		if (_in!=null && _in.length()==0 && _nonBlocking)
+			return 0;
 
-        close();
-        return -1;
-    }
+		close();
+		return -1;
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see org.eclipse.io.EndPoint#flush(org.eclipse.io.Buffer)
-     */
-    public int flush(Buffer buffer) throws IOException
-    {
-        if (_closed)
-            throw new IOException("CLOSED");
-        if (_growOutput && buffer.length()>_out.space())
-        {
-            _out.compact();
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see org.eclipse.io.EndPoint#flush(org.eclipse.io.Buffer)
+	 */
+	public int flush(Buffer buffer) throws IOException
+	{
+		if (_closed)
+			throw new IOException("CLOSED");
+		if (_growOutput && buffer.length()>_out.space())
+		{
+			_out.compact();
 
-            if (buffer.length()>_out.space())
-            {
-                ByteArrayBuffer n = new ByteArrayBuffer(_out.putIndex()+buffer.length());
+			if (buffer.length()>_out.space())
+			{
+				ByteArrayBuffer n = new ByteArrayBuffer(_out.putIndex()+buffer.length());
 
-                n.put(_out.peek(0,_out.putIndex()));
-                if (_out.getIndex()>0)
-                {
-                    n.mark();
-                    n.setGetIndex(_out.getIndex());
-                }
-                _out=n;
-            }
-        }
-        int len = _out.put(buffer);
-        if (!buffer.isImmutable())
-            buffer.skip(len);
-        return len;
-    }
+				n.put(_out.peek(0,_out.putIndex()));
+				if (_out.getIndex()>0)
+				{
+					n.mark();
+					n.setGetIndex(_out.getIndex());
+				}
+				_out=n;
+			}
+		}
+		int len = _out.put(buffer);
+		if (!buffer.isImmutable())
+			buffer.skip(len);
+		return len;
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see org.eclipse.io.EndPoint#flush(org.eclipse.io.Buffer, org.eclipse.io.Buffer, org.eclipse.io.Buffer)
-     */
-    public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
-    {
-        if (_closed)
-            throw new IOException("CLOSED");
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see org.eclipse.io.EndPoint#flush(org.eclipse.io.Buffer, org.eclipse.io.Buffer, org.eclipse.io.Buffer)
+	 */
+	public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
+	{
+		if (_closed)
+			throw new IOException("CLOSED");
 
-        int flushed=0;
+		int flushed=0;
 
-        if (header!=null && header.length()>0)
-            flushed=flush(header);
+		if (header!=null && header.length()>0)
+			flushed=flush(header);
 
-        if (header==null || header.length()==0)
-        {
-            if (buffer!=null && buffer.length()>0)
-                flushed+=flush(buffer);
+		if (header==null || header.length()==0)
+		{
+			if (buffer!=null && buffer.length()>0)
+				flushed+=flush(buffer);
 
-            if (buffer==null || buffer.length()==0)
-            {
-                if (trailer!=null && trailer.length()>0)
-                {
-                    flushed+=flush(trailer);
-                }
-            }
-        }
+			if (buffer==null || buffer.length()==0)
+			{
+				if (trailer!=null && trailer.length()>0)
+				{
+					flushed+=flush(trailer);
+				}
+			}
+		}
 
-        return flushed;
-    }
+		return flushed;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     *
-     */
-    public void reset()
-    {
-        _closed=false;
-        _in.clear();
-        _out.clear();
-        if (_inBytes!=null)
-            _in.setPutIndex(_inBytes.length);
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 *
+	 */
+	public void reset()
+	{
+		_closed=false;
+		_in.clear();
+		_out.clear();
+		if (_inBytes!=null)
+			_in.setPutIndex(_inBytes.length);
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see org.eclipse.io.EndPoint#getLocalAddr()
-     */
-    public String getLocalAddr()
-    {
-        return null;
-    }
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see org.eclipse.io.EndPoint#getLocalAddr()
+	 */
+	public String getLocalAddr()
+	{
+		return null;
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see org.eclipse.io.EndPoint#getLocalHost()
-     */
-    public String getLocalHost()
-    {
-        return null;
-    }
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see org.eclipse.io.EndPoint#getLocalHost()
+	 */
+	public String getLocalHost()
+	{
+		return null;
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see org.eclipse.io.EndPoint#getLocalPort()
-     */
-    public int getLocalPort()
-    {
-        return 0;
-    }
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see org.eclipse.io.EndPoint#getLocalPort()
+	 */
+	public int getLocalPort()
+	{
+		return 0;
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see org.eclipse.io.EndPoint#getRemoteAddr()
-     */
-    public String getRemoteAddr()
-    {
-        return null;
-    }
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see org.eclipse.io.EndPoint#getRemoteAddr()
+	 */
+	public String getRemoteAddr()
+	{
+		return null;
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see org.eclipse.io.EndPoint#getRemoteHost()
-     */
-    public String getRemoteHost()
-    {
-        return null;
-    }
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see org.eclipse.io.EndPoint#getRemoteHost()
+	 */
+	public String getRemoteHost()
+	{
+		return null;
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see org.eclipse.io.EndPoint#getRemotePort()
-     */
-    public int getRemotePort()
-    {
-        return 0;
-    }
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see org.eclipse.io.EndPoint#getRemotePort()
+	 */
+	public int getRemotePort()
+	{
+		return 0;
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see org.eclipse.io.EndPoint#getConnection()
-     */
-    public Object getTransport()
-    {
-        return _inBytes;
-    }
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see org.eclipse.io.EndPoint#getConnection()
+	 */
+	public Object getTransport()
+	{
+		return _inBytes;
+	}
 
-    /* ------------------------------------------------------------ */
-    public void flush() throws IOException
-    {
-    }
-    
-    /* ------------------------------------------------------------ */
-    /**
-     * @return the growOutput
-     */
-    public boolean isGrowOutput()
-    {
-        return _growOutput;
-    }
+	/* ------------------------------------------------------------ */
+	public void flush() throws IOException
+	{
+	}
+	
+	/* ------------------------------------------------------------ */
+	/**
+	 * @return the growOutput
+	 */
+	public boolean isGrowOutput()
+	{
+		return _growOutput;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * @param growOutput the growOutput to set
-     */
-    public void setGrowOutput(boolean growOutput)
-    {
-        _growOutput=growOutput;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * @param growOutput the growOutput to set
+	 */
+	public void setGrowOutput(boolean growOutput)
+	{
+		_growOutput=growOutput;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * @see org.eclipse.jetty.io.EndPoint#getMaxIdleTime()
-     */
-    public int getMaxIdleTime()
-    {
-        return _maxIdleTime;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * @see org.eclipse.jetty.io.EndPoint#getMaxIdleTime()
+	 */
+	public int getMaxIdleTime()
+	{
+		return _maxIdleTime;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * @see org.eclipse.jetty.io.EndPoint#setMaxIdleTime(int)
-     */
-    public void setMaxIdleTime(int timeMs) throws IOException
-    {
-        _maxIdleTime=timeMs;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * @see org.eclipse.jetty.io.EndPoint#setMaxIdleTime(int)
+	 */
+	public void setMaxIdleTime(int timeMs) throws IOException
+	{
+		_maxIdleTime=timeMs;
+	}
 
 
 }
--- a/src/org/eclipse/jetty/server/Connector.java	Fri Oct 07 15:17:01 2016 -0600
+++ b/src/org/eclipse/jetty/server/Connector.java	Sat Oct 08 21:15:28 2016 -0600
@@ -22,6 +22,7 @@
 import java.net.InetAddress;
 import java.net.Socket;
 import java.net.UnknownHostException;
+import java.nio.channels.ServerSocketChannel;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -70,6 +71,9 @@
 
 	protected final HttpBuffersImpl _buffers = new HttpBuffersImpl();
 
+	// from child classes
+	protected transient ServerSocketChannel _acceptChannel;
+
 	public Connector(Server server,int port) {
 		this.server = server;
 		this.port = port;
@@ -81,26 +85,16 @@
 		_buffers.setResponseHeaderType(Type.INDIRECT);
 	}
 
-	/* ------------------------------------------------------------ */
-	/**
-	 */
 	public void setHost(String host)
 	{
 		_host = host;
 	}
 
-	/* ------------------------------------------------------------ */
-	/*
-	 */
 	public String getHost()
 	{
 		return _host;
 	}
 
-	/* ------------------------------------------------------------ */
-	/**
-	 * @return Returns the maxIdleTime.
-	 */
 	public int getMaxIdleTime()
 	{
 		return _maxIdleTime;
@@ -213,13 +207,9 @@
 		_soLingerTime = soLingerTime;
 	}
 
-	/* ------------------------------------------------------------ */
 	@Override
 	protected void doStart() throws Exception
 	{
-		// open listener port
-		open();
-
 		super.doStart();
 
 		// Start selector thread
@@ -274,19 +264,13 @@
 	{
 	}
 
-	/* ------------------------------------------------------------ */
-	/*
-	 * @see org.eclipse.jetty.server.Connector#isConfidential(org.eclipse.jetty.server.Request)
-	 */
 	public boolean isConfidential(Request request)
 	{
 		return false;
 	}
 
-	/* ------------------------------------------------------------ */
 	protected abstract void accept() throws IOException, InterruptedException;
 
-	/* ------------------------------------------------------------ */
 	public void stopAccept(int acceptorID) throws Exception
 	{
 	}
@@ -376,19 +360,16 @@
 		return _buffers.getMaxBuffers();
 	}
 
-	/* ------------------------------------------------------------ */
 	@Override
 	public String toString()
 	{
 		return String.format("%s@%s:%d",
 				getClass().getSimpleName(),
 				getHost()==null?"0.0.0.0":getHost(),
-				getLocalPort()<=0 ? port : getLocalPort());
+				port);
 	}
 
-	/* ------------------------------------------------------------ */
-	/* ------------------------------------------------------------ */
-	/* ------------------------------------------------------------ */
+
 	private class Acceptor implements Runnable
 	{
 
@@ -400,7 +381,7 @@
 
 			try
 			{
-				while (isRunning() && getConnection() != null)
+				while (isRunning() && _acceptChannel != null)
 				{
 					try
 					{
@@ -435,21 +416,17 @@
 	public String getName()
 	{
 		if (_name == null)
-			_name = (getHost() == null?"0.0.0.0":getHost()) + ":" + (getLocalPort() <= 0?port:getLocalPort());
+			_name = (getHost() == null?"0.0.0.0":getHost()) + ":" + port;
 		return _name;
 	}
 
-	/* ------------------------------------------------------------ */
 	public final boolean isLowResources()
 	{
 		return server.isLowOnThreads();
 	}
 
 	// from old interface
-	public abstract void open() throws IOException;
 	public abstract void close() throws IOException;
-	public abstract int getLocalPort();
-	public abstract Object getConnection();
 
 
 	// from AbstractNIOConnector
@@ -470,4 +447,8 @@
 		_buffers.setRequestBufferType(direct?Type.DIRECT:Type.INDIRECT);
 		_buffers.setResponseBufferType(direct?Type.DIRECT:Type.INDIRECT);
 	}
+
+
+	// from child classes
+
 }
--- a/src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java	Fri Oct 07 15:17:01 2016 -0600
+++ b/src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java	Sat Oct 08 21:15:28 2016 -0600
@@ -60,7 +60,6 @@
 {
 	private static final Logger LOG = LoggerFactory.getLogger(BlockingChannelConnector.class);
 
-	private transient ServerSocketChannel _acceptChannel;
 	private final Set<BlockingChannelEndPoint> _endpoints = new ConcurrentHashMap<BlockingChannelEndPoint,Boolean>().newKeySet();
 
 
@@ -73,19 +72,18 @@
 		super(server,port);
 	}
 
-	/* ------------------------------------------------------------ */
-	public Object getConnection()
-	{
-		return _acceptChannel;
-	}
 
-	/* ------------------------------------------------------------ */
-	/**
-	 * @see org.eclipse.jetty.server.AbstractConnector#doStart()
-	 */
 	@Override
 	protected void doStart() throws Exception
 	{
+		// Create a new server socket and set to non blocking mode
+		_acceptChannel= ServerSocketChannel.open();
+		_acceptChannel.configureBlocking(true);
+
+		// Bind the server socket to the local host and port
+		InetSocketAddress addr = getHost()==null?new InetSocketAddress(port):new InetSocketAddress(getHost(),port);
+		_acceptChannel.bind(addr);
+
 		super.doStart();
 		server.threadPool.execute(new Runnable()
 		{
@@ -118,20 +116,6 @@
 
 	}
 
-
-	/* ------------------------------------------------------------ */
-	public void open() throws IOException
-	{
-		// Create a new server socket and set to non blocking mode
-		_acceptChannel= ServerSocketChannel.open();
-		_acceptChannel.configureBlocking(true);
-
-		// Bind the server socket to the local host and port
-		InetSocketAddress addr = getHost()==null?new InetSocketAddress(port):new InetSocketAddress(getHost(),port);
-		_acceptChannel.socket().bind(addr);
-	}
-
-	/* ------------------------------------------------------------ */
 	public void close() throws IOException
 	{
 		if (_acceptChannel != null)
@@ -139,21 +123,19 @@
 		_acceptChannel=null;
 	}
 
-	/* ------------------------------------------------------------ */
 	@Override
 	public void accept()
 		throws IOException, InterruptedException
 	{
 		SocketChannel channel = _acceptChannel.accept();
 		channel.configureBlocking(true);
-		Socket socket=channel.socket();
+		Socket socket = channel.socket();
 		configure(socket);
 
 		BlockingChannelEndPoint connection=new BlockingChannelEndPoint(channel);
 		connection.dispatch();
 	}
 
-	/* ------------------------------------------------------------------------------- */
 	@Override
 	public void customize(EndPoint endpoint, Request request)
 		throws IOException
@@ -164,17 +146,6 @@
 	}
 
 
-	/* ------------------------------------------------------------------------------- */
-	public int getLocalPort()
-	{
-		if (_acceptChannel==null || !_acceptChannel.isOpen())
-			return -1;
-		return _acceptChannel.socket().getLocalPort();
-	}
-
-	/* ------------------------------------------------------------------------------- */
-	/* ------------------------------------------------------------------------------- */
-	/* ------------------------------------------------------------------------------- */
 	private class BlockingChannelEndPoint extends ChannelEndPoint implements Runnable, ConnectedEndPoint
 	{
 		private Connection _connection;
--- a/src/org/eclipse/jetty/server/nio/SelectChannelConnector.java	Fri Oct 07 15:17:01 2016 -0600
+++ b/src/org/eclipse/jetty/server/nio/SelectChannelConnector.java	Sat Oct 08 21:15:28 2016 -0600
@@ -67,18 +67,11 @@
  */
 public class SelectChannelConnector extends Connector
 {
-	private transient ServerSocketChannel _acceptChannel;
 	private int _lowResourcesConnections;
 	private int _lowResourcesMaxIdleTime;
-	private int _localPort=-1;
 
 	private final SelectorManager _manager = new ConnectorSelectorManager();
 
-	/* ------------------------------------------------------------------------------- */
-	/**
-	 * Constructor.
-	 *
-	 */
 	public SelectChannelConnector(Server server,int port)
 	{
 		super(server,port);
@@ -87,7 +80,6 @@
 		setAcceptors(Math.max(1,(Runtime.getRuntime().availableProcessors()+3)/4));
 	}
 	
-	/* ------------------------------------------------------------ */
 	@Override
 	public final void accept() throws IOException
 	{
@@ -103,23 +95,17 @@
 		}
 	}
 
-	/* ------------------------------------------------------------ */
-	public void close() throws IOException
+	public synchronized void close() throws IOException
 	{
-		synchronized(this)
+		if (_acceptChannel != null)
 		{
-			if (_acceptChannel != null)
-			{
-				removeBean(_acceptChannel);
-				if (_acceptChannel.isOpen())
-					_acceptChannel.close();
-			}
-			_acceptChannel = null;
-			_localPort=-2;
+			removeBean(_acceptChannel);
+			if (_acceptChannel.isOpen())
+				_acceptChannel.close();
 		}
+		_acceptChannel = null;
 	}
 
-	/* ------------------------------------------------------------------------------- */
 	@Override
 	public void customize(EndPoint endpoint, Request request) throws IOException
 	{
@@ -128,7 +114,6 @@
 		super.customize(endpoint, request);
 	}
 
-	/* ------------------------------------------------------------------------------- */
 	@Override
 	public void persist(EndPoint endpoint) throws IOException
 	{
@@ -137,54 +122,11 @@
 		super.persist(endpoint);
 	}
 
-	/* ------------------------------------------------------------ */
 	public SelectorManager getSelectorManager()
 	{
 		return _manager;
 	}
 
-	/* ------------------------------------------------------------ */
-	public synchronized Object getConnection()
-	{
-		return _acceptChannel;
-	}
-
-	/* ------------------------------------------------------------------------------- */
-	public int getLocalPort()
-	{
-		synchronized(this)
-		{
-			return _localPort;
-		}
-	}
-
-	/* ------------------------------------------------------------ */
-	public void open() throws IOException
-	{
-		synchronized(this)
-		{
-			if (_acceptChannel == null)
-			{
-				// Create a new server socket
-				_acceptChannel = ServerSocketChannel.open();
-				// Set to blocking mode
-				_acceptChannel.configureBlocking(true);
-
-				// Bind the server socket to the local host and port
-				_acceptChannel.socket().setReuseAddress(true);
-				InetSocketAddress addr = getHost()==null?new InetSocketAddress(port):new InetSocketAddress(getHost(),port);
-				_acceptChannel.socket().bind(addr);
-
-				_localPort=_acceptChannel.socket().getLocalPort();
-				if (_localPort<=0)
-					throw new IOException("Server channel not bound");
-
-				addBean(_acceptChannel);
-			}
-		}
-	}
-
-	/* ------------------------------------------------------------ */
 	@Override
 	public void setMaxIdleTime(int maxIdleTime)
 	{
@@ -192,10 +134,6 @@
 		super.setMaxIdleTime(maxIdleTime);
 	}
 
-	/* ------------------------------------------------------------ */
-	/**
-	 * @return the lowResourcesConnections
-	 */
 	public int getLowResourcesConnections()
 	{
 		return _lowResourcesConnections;
@@ -239,22 +177,35 @@
 	}
 
 
-	/* ------------------------------------------------------------ */
-	/*
-	 * @see org.eclipse.jetty.server.server.AbstractConnector#doStart()
-	 */
 	@Override
-	protected void doStart() throws Exception
+	protected synchronized void doStart() throws Exception
 	{
 		_manager.setSelectSets(getAcceptors());
 		_manager.setMaxIdleTime(getMaxIdleTime());
 		_manager.setLowResourcesConnections(getLowResourcesConnections());
 		_manager.setLowResourcesMaxIdleTime(getLowResourcesMaxIdleTime());
 
+		if (_acceptChannel == null)
+		{
+			// Create a new server socket
+			_acceptChannel = ServerSocketChannel.open();
+			// Set to blocking mode
+			_acceptChannel.configureBlocking(true);
+
+			// Bind the server socket to the local host and port
+			_acceptChannel.socket().setReuseAddress(true);
+			InetSocketAddress addr = getHost()==null?new InetSocketAddress(port):new InetSocketAddress(getHost(),port);
+			_acceptChannel.bind(addr);
+
+			if( _acceptChannel.socket().getLocalPort() != port)
+				throw new IOException("Server channel not bound");
+
+			addBean(_acceptChannel);
+		}
+
 		super.doStart();
 	}
 
-	/* ------------------------------------------------------------ */
 	protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key) throws IOException
 	{
 		SelectChannelEndPoint endp= new SelectChannelEndPoint(channel,selectSet,key, SelectChannelConnector.this._maxIdleTime);
@@ -262,22 +213,17 @@
 		return endp;
 	}
 
-	/* ------------------------------------------------------------------------------- */
 	protected void endPointClosed(SelectChannelEndPoint endpoint)
 	{
 		endpoint.getConnection().onClose();
 	}
 
-	/* ------------------------------------------------------------------------------- */
 	protected AsyncConnection newConnection(SocketChannel channel,final AsyncEndPoint endpoint)
 	{
 		return new AsyncHttpConnection(SelectChannelConnector.this,endpoint,server);
 	}
 
 
-	/* ------------------------------------------------------------ */
-	/* ------------------------------------------------------------ */
-	/* ------------------------------------------------------------ */
 	private final class ConnectorSelectorManager extends SelectorManager
 	{
 		@Override