Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #6661 - Make ServerConnector socket options setting optional #6663

Merged
merged 2 commits into from Aug 25, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
joakime marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Override
public void close()
{
Expand Down