Added an option to bind the datagram socket to a specific

hostname, in hopes of fixing the issue with receiving datagrams 
from the staging server.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5793 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2009-05-21 18:04:09 +00:00
parent 6dd16483be
commit d45b0bdb00
2 changed files with 25 additions and 3 deletions
@@ -154,11 +154,11 @@ public class PresentsServer
_clmgr.setInjector(injector);
// configure our connection manager
_conmgr.init(getListenPorts(), getDatagramPorts());
_conmgr.init(getListenPorts(), getDatagramPorts(), getDatagramHostname());
// initialize the time base services
TimeBaseProvider.init(_invmgr, _omgr);
// Make the client manager shut down before the invoker and dobj threads. This will help
// application code to avoid long chains of shutdown constraints (e.g. msoy bureau manager).
_shutmgr.addConstraint(
@@ -207,6 +207,15 @@ public class PresentsServer
return Client.DEFAULT_DATAGRAM_PORTS;
}
/**
* Returns the hostname for which the connection manager will listen for datagrams, or
* <code>null</code> to bind to the wildcard address.
*/
protected String getDatagramHostname ()
{
return null;
}
/**
* Called once the invoker and distributed object manager have both completed processing all
* remaining events and are fully shutdown. <em>Note:</em> this is called as the last act of
@@ -109,9 +109,20 @@ public class ConnectionManager extends LoopingThread
*/
public void init (int[] ports, int[] datagramPorts)
throws IOException
{
init(ports, datagramPorts, null);
}
/**
* Constructs and initialized a connection manager (binding socket on which it will listen for
* client connections to each of the specified ports).
*/
public void init (int[] ports, int[] datagramPorts, String datagramHostname)
throws IOException
{
_ports = ports;
_datagramPorts = datagramPorts;
_datagramHostname = datagramHostname;
_selector = SelectorProvider.provider().openSelector();
// create our stats record
@@ -390,7 +401,8 @@ public class ConnectionManager extends LoopingThread
_datagramChannel = DatagramChannel.open();
_datagramChannel.configureBlocking(false);
InetSocketAddress isa = new InetSocketAddress(port);
InetSocketAddress isa = (_datagramHostname == null) ?
new InetSocketAddress(port) : new InetSocketAddress(_datagramHostname, port);
_datagramChannel.socket().bind(isa);
registerChannel(_datagramChannel);
log.info("Server accepting datagrams on " + isa + ".");
@@ -1169,6 +1181,7 @@ public class ConnectionManager extends LoopingThread
@Inject(optional=true) protected Authenticator _author = new DummyAuthenticator();
protected int[] _ports, _datagramPorts;
protected String _datagramHostname;
protected Selector _selector;
protected ServerSocketChannel _ssocket;
protected DatagramChannel _datagramChannel;