changeset 1004:3fa54d9d19cd

better handling of BindException
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 22 Oct 2016 23:00:57 -0600
parents 21910079096e
children 0e96ce3db20a
files src/luan/modules/http/LuanHandler.java src/luan/modules/http/Server.luan src/org/eclipse/jetty/server/Server.java src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java src/org/eclipse/jetty/util/component/AbstractLifeCycle.java
diffstat 5 files changed, 18 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/http/LuanHandler.java	Sat Oct 22 22:24:47 2016 -0600
+++ b/src/luan/modules/http/LuanHandler.java	Sat Oct 22 23:00:57 2016 -0600
@@ -2,12 +2,14 @@
 
 import java.io.IOException;
 import java.lang.reflect.Method;
+import java.net.BindException;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import javax.servlet.http.HttpServletResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.handler.AbstractHandler;
 import luan.Luan;
 import luan.LuanState;
@@ -159,4 +161,11 @@
 		}
 	}
 
+	public static void start(Server server) throws Exception {
+		try {
+			server.start();
+		} catch(BindException e) {
+			throw new LuanException(e.toString());
+		}
+	}
 }
--- a/src/luan/modules/http/Server.luan	Sat Oct 22 22:24:47 2016 -0600
+++ b/src/luan/modules/http/Server.luan	Sat Oct 22 23:00:57 2016 -0600
@@ -92,7 +92,7 @@
 end
 
 function M.start()
-	M.server.start()
+	LuanHandler.start(M.server)
 end
 
 function M.start_rpc()
--- a/src/org/eclipse/jetty/server/Server.java	Sat Oct 22 22:24:47 2016 -0600
+++ b/src/org/eclipse/jetty/server/Server.java	Sat Oct 22 23:00:57 2016 -0600
@@ -69,8 +69,8 @@
 	public Server(int port)
 	{
 		setServer(this);
-		new SelectChannelConnector(this,port);
-//		new BlockingChannelConnector(this,port);
+//		new SelectChannelConnector(this,port);
+		new BlockingChannelConnector(this,port);
 	}
 
 	@Override
--- a/src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java	Sat Oct 22 22:24:47 2016 -0600
+++ b/src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java	Sat Oct 22 23:00:57 2016 -0600
@@ -198,12 +198,16 @@
 			{
 				_timeout = getMaxIdleTime();
 				_endpoints.add(this);
-
+/*
 				while (isOpen())
 				{
 					_idleTimestamp = System.currentTimeMillis();
 					_connection.handle();
 				}
+*/
+				_idleTimestamp = System.currentTimeMillis();
+				_connection.handle();
+				if( isOpen() )  throw new RuntimeException();
 			}
 			catch (EofException e)
 			{
--- a/src/org/eclipse/jetty/util/component/AbstractLifeCycle.java	Sat Oct 22 22:24:47 2016 -0600
+++ b/src/org/eclipse/jetty/util/component/AbstractLifeCycle.java	Sat Oct 22 23:00:57 2016 -0600
@@ -181,7 +181,7 @@
 	private void setFailed(Throwable th)
 	{
 		_state = __FAILED;
-		LOG.warn(FAILED+" " + this+": "+th,th);
+		LOG.warn(FAILED+" " + this+": "+th);
 	}
 
 }