Skip to content

Commit

Permalink
Issue #6661 - Make ServerConnector socket options setting optional
Browse files Browse the repository at this point in the history
  • Loading branch information
joakime committed Aug 24, 2021
1 parent e3e630b commit ec84207
Showing 1 changed file with 15 additions and 2 deletions.
Expand Up @@ -19,6 +19,7 @@
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketOption;
import java.net.StandardSocketOptions;
import java.nio.channels.Channel;
import java.nio.channels.SelectableChannel;
Expand Down Expand Up @@ -332,10 +333,10 @@ protected ServerSocketChannel openAcceptChannel() throws IOException
{
InetSocketAddress bindAddress = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort());
serverChannel = ServerSocketChannel.open();
setSocketOption(serverChannel, StandardSocketOptions.SO_REUSEADDR, getReuseAddress());
setSocketOption(serverChannel, StandardSocketOptions.SO_REUSEPORT, isReusePort());
try
{
serverChannel.setOption(StandardSocketOptions.SO_REUSEADDR, getReuseAddress());
serverChannel.setOption(StandardSocketOptions.SO_REUSEPORT, isReusePort());
serverChannel.bind(bindAddress, getAcceptQueueSize());
}
catch (Throwable e)
Expand All @@ -348,6 +349,18 @@ protected ServerSocketChannel openAcceptChannel() throws IOException
return serverChannel;
}

private <T> void setSocketOption(ServerSocketChannel channel, SocketOption<T> name, T value)
{
try
{
channel.setOption(name, value);
}
catch (Throwable t)
{
LOG.warn("Unable to set socket option {} to {}", name, value, t);
}
}

@Override
public void close()
{
Expand Down

0 comments on commit ec84207

Please sign in to comment.