Issue #1655 added openAcceptChannel

This commit is contained in:
Greg Wilkins 2017-07-03 14:51:45 +02:00 committed by Joakim Erdfelt
parent 349ee90b5d
commit 386ca510e6
1 changed files with 35 additions and 27 deletions

View File

@ -279,36 +279,44 @@ public class ServerConnector extends AbstractNetworkConnector
{
if (_acceptChannel == null)
{
ServerSocketChannel serverChannel = null;
if (isInheritChannel())
{
Channel channel = System.inheritedChannel();
if (channel instanceof ServerSocketChannel)
serverChannel = (ServerSocketChannel)channel;
else
LOG.warn("Unable to use System.inheritedChannel() [{}]. Trying a new ServerSocketChannel at {}:{}", channel, getHost(), getPort());
}
if (serverChannel == null)
{
serverChannel = ServerSocketChannel.open();
InetSocketAddress bindAddress = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort());
serverChannel.socket().setReuseAddress(getReuseAddress());
serverChannel.socket().bind(bindAddress, getAcceptQueueSize());
_localPort = serverChannel.socket().getLocalPort();
if (_localPort <= 0)
throw new IOException("Server channel not bound");
}
serverChannel.configureBlocking(true);
addBean(serverChannel);
_acceptChannel = serverChannel;
_acceptChannel = openAcceptChannel();
_acceptChannel.configureBlocking(true);
_localPort = _acceptChannel.socket().getLocalPort();
if (_localPort <= 0)
throw new IOException("Server channel not bound");
addBean(_acceptChannel);
}
}
/**
* Called by {@link #open()} to obtain the accepting channel.
* @return ServerSocketChannel used to accept connections.
* @throws IOException
*/
protected ServerSocketChannel openAcceptChannel() throws IOException
{
ServerSocketChannel serverChannel = null;
if (isInheritChannel())
{
Channel channel = System.inheritedChannel();
if (channel instanceof ServerSocketChannel)
serverChannel = (ServerSocketChannel)channel;
else
LOG.warn("Unable to use System.inheritedChannel() [{}]. Trying a new ServerSocketChannel at {}:{}", channel, getHost(), getPort());
}
if (serverChannel == null)
{
serverChannel = ServerSocketChannel.open();
InetSocketAddress bindAddress = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort());
serverChannel.socket().setReuseAddress(getReuseAddress());
serverChannel.socket().bind(bindAddress, getAcceptQueueSize());
}
return serverChannel;
}
@Override
public Future<Void> shutdown()
{