Author: toad
Date: 2007-03-31 19:21:21 +0000 (Sat, 31 Mar 2007)
New Revision: 12487
Modified:
trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
trunk/freenet/src/freenet/io/NetworkInterface.java
trunk/freenet/src/freenet/node/TextModeClientInterfaceServer.java
trunk/freenet/src/freenet/node/fcp/FCPServer.java
Log:
Prevent race condition initialising NetworkInterface
Modified: trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
2007-03-31 19:12:53 UTC (rev 12486)
+++ trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
2007-03-31 19:21:21 UTC (rev 12487)
@@ -294,7 +294,7 @@
toadlets = new LinkedList();
core.setToadletContainer(this); // even if not enabled, because
of config
- this.networkInterface = new NetworkInterface(port, this.bindTo,
fproxyConfig.getString("allowedHosts"));
+ this.networkInterface = NetworkInterface.create(port,
this.bindTo, fproxyConfig.getString("allowedHosts"));
if(!enabled) {
Logger.normal(core, "Not starting FProxy as it's
disabled");
System.out.println("Not starting FProxy as it's
disabled");
@@ -309,7 +309,7 @@
this.bindTo = newbindTo;
allowedFullAccess = new AllowedHosts(allowedHosts);
this.bf = bf;
- this.networkInterface = new NetworkInterface(port, this.bindTo,
allowedHosts);
+ this.networkInterface = NetworkInterface.create(port,
this.bindTo, allowedHosts);
toadlets = new LinkedList();
this.cssName = cssName;
pageMaker = new PageMaker(cssName);
Modified: trunk/freenet/src/freenet/io/NetworkInterface.java
===================================================================
--- trunk/freenet/src/freenet/io/NetworkInterface.java 2007-03-31 19:12:53 UTC
(rev 12486)
+++ trunk/freenet/src/freenet/io/NetworkInterface.java 2007-03-31 19:21:21 UTC
(rev 12487)
@@ -61,6 +61,22 @@
/** The number of running acceptors. */
private int runningAcceptors = 0;
+ public static NetworkInterface create(int port, String bindTo, String
allowedHosts) throws IOException {
+ NetworkInterface iface = new NetworkInterface(port,
allowedHosts);
+ try {
+ iface.setBindTo(bindTo);
+ } catch (IOException e) {
+ try {
+ iface.close();
+ } catch (IOException e1) {
+ Logger.error(NetworkInterface.class, "Caught
"+e1+" closing after catching "+e+" binding while constructing", e1);
+ // Ignore
+ }
+ throw e;
+ }
+ return iface;
+ }
+
/**
* Creates a new network interface that can bind to several addresses
and
* allows connection filtering on IP address level.
@@ -70,9 +86,8 @@
* @param allowedHosts
* A comma-separated list of allowed addresses
*/
- public NetworkInterface(int port, String bindTo, String allowedHosts)
throws IOException {
+ private NetworkInterface(int port, String allowedHosts) throws
IOException {
this.port = port;
- setBindTo(bindTo);
this.allowedHosts = new AllowedHosts(allowedHosts);
}
Modified: trunk/freenet/src/freenet/node/TextModeClientInterfaceServer.java
===================================================================
--- trunk/freenet/src/freenet/node/TextModeClientInterfaceServer.java
2007-03-31 19:12:53 UTC (rev 12486)
+++ trunk/freenet/src/freenet/node/TextModeClientInterfaceServer.java
2007-03-31 19:21:21 UTC (rev 12487)
@@ -220,7 +220,7 @@
int curPort = port;
String tempBindTo = this.bindTo;
try {
- networkInterface = new NetworkInterface(curPort,
tempBindTo, allowedHosts);
+ networkInterface = NetworkInterface.create(curPort,
tempBindTo, allowedHosts);
} catch (IOException e) {
Logger.error(this, "Could not bind to TMCI port:
"+tempBindTo+ ':' +port);
System.err.println("Could not bind to TMCI port:
"+tempBindTo+ ':' +port);
Modified: trunk/freenet/src/freenet/node/fcp/FCPServer.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/FCPServer.java 2007-03-31 19:12:53 UTC
(rev 12486)
+++ trunk/freenet/src/freenet/node/fcp/FCPServer.java 2007-03-31 19:21:21 UTC
(rev 12487)
@@ -124,7 +124,7 @@
System.out.println("Starting FCP server on "+bindTo+
':' +port+ '.');
NetworkInterface tempNetworkInterface = null;
try {
- tempNetworkInterface = new
NetworkInterface(port, bindTo, allowedHosts);
+ tempNetworkInterface =
NetworkInterface.create(port, bindTo, allowedHosts);
} catch (BindException be) {
Logger.error(this, "Couldn't bind to FCP Port
"+bindTo+ ':' +port+". FCP Server not started.");
System.out.println("Couldn't bind to FCP Port
"+bindTo+ ':' +port+". FCP Server not started.");