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
|
// create a listening socket
|
||||||
final ServerSocketChannel ssocket = ServerSocketChannel.open();
|
final ServerSocketChannel ssocket = ServerSocketChannel.open();
|
||||||
ssocket.configureBlocking(false);
|
configureSocket(ssocket);
|
||||||
InetSocketAddress isa = AddressUtil.getAddress(_bindHostname, port);
|
InetSocketAddress isa = AddressUtil.getAddress(_bindHostname, port);
|
||||||
ssocket.socket().bind(isa);
|
ssocket.socket().bind(isa);
|
||||||
|
|
||||||
@@ -125,6 +125,16 @@ public class ServerSocketChannelAcceptor
|
|||||||
log.info("Server listening on " + isa + ".");
|
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 int[] _ports;
|
||||||
protected final String _bindHostname;
|
protected final String _bindHostname;
|
||||||
protected final ConnectionManager _conMan;
|
protected final ConnectionManager _conMan;
|
||||||
|
|||||||
@@ -191,9 +191,7 @@ public class PresentsServer
|
|||||||
_clmgr.setInjector(injector);
|
_clmgr.setInjector(injector);
|
||||||
|
|
||||||
// Create our socket opening objects now that we know what ports we're using.
|
// Create our socket opening objects now that we know what ports we're using.
|
||||||
_socketAcceptor =
|
_lifecycle.addComponent(_socketAcceptor = createSocketAcceptor());
|
||||||
new ServerSocketChannelAcceptor(getBindHostname(), getListenPorts(), _conmgr);
|
|
||||||
_lifecycle.addComponent(_socketAcceptor);
|
|
||||||
_datagramReader =
|
_datagramReader =
|
||||||
new DatagramChannelReader(getDatagramHostname(), getDatagramPorts(), _conmgr);
|
new DatagramChannelReader(getDatagramHostname(), getDatagramPorts(), _conmgr);
|
||||||
_lifecycle.addComponent(_datagramReader);
|
_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.
|
* Starts up all of the server services and enters the main server event loop.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user