Allow customizing the ServerSocketChannelAcceptor to configure the socket
differently (specifically, we want to enable SO_REUSEADDR in Spiral Knights). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6625 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -99,7 +99,7 @@ public class ServerSocketChannelAcceptor
|
||||
{
|
||||
// create a listening socket
|
||||
final ServerSocketChannel ssocket = ServerSocketChannel.open();
|
||||
ssocket.configureBlocking(false);
|
||||
configureSocket(ssocket);
|
||||
InetSocketAddress isa = AddressUtil.getAddress(_bindHostname, port);
|
||||
ssocket.socket().bind(isa);
|
||||
|
||||
@@ -125,6 +125,16 @@ public class ServerSocketChannelAcceptor
|
||||
log.info("Server listening on " + isa + ".");
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to perform any desired additional socket configuration before binding. Be sure to
|
||||
* call the superclass implementation.
|
||||
*/
|
||||
protected void configureSocket (ServerSocketChannel ssocket)
|
||||
throws IOException
|
||||
{
|
||||
ssocket.configureBlocking(false);
|
||||
}
|
||||
|
||||
protected final int[] _ports;
|
||||
protected final String _bindHostname;
|
||||
protected final ConnectionManager _conMan;
|
||||
|
||||
@@ -191,9 +191,7 @@ public class PresentsServer
|
||||
_clmgr.setInjector(injector);
|
||||
|
||||
// Create our socket opening objects now that we know what ports we're using.
|
||||
_socketAcceptor =
|
||||
new ServerSocketChannelAcceptor(getBindHostname(), getListenPorts(), _conmgr);
|
||||
_lifecycle.addComponent(_socketAcceptor);
|
||||
_lifecycle.addComponent(_socketAcceptor = createSocketAcceptor());
|
||||
_datagramReader =
|
||||
new DatagramChannelReader(getDatagramHostname(), getDatagramPorts(), _conmgr);
|
||||
_lifecycle.addComponent(_datagramReader);
|
||||
@@ -220,6 +218,11 @@ public class PresentsServer
|
||||
}
|
||||
}
|
||||
|
||||
protected ServerSocketChannelAcceptor createSocketAcceptor ()
|
||||
{
|
||||
return new ServerSocketChannelAcceptor(getBindHostname(), getListenPorts(), _conmgr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts up all of the server services and enters the main server event loop.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user