Skip to content

Commit

Permalink
Merge pull request #6663 from eclipse/jetty-10.0.x-6661-windows-socke…
Browse files Browse the repository at this point in the history
…t-setoptions

Issue #6661 - Make ServerConnector socket options setting optional
  • Loading branch information
joakime committed Aug 25, 2021
2 parents e8beb58 + 54edcef commit 325739b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Expand Up @@ -486,7 +486,7 @@ private <T> void setSocketOption(SocketChannel channel, SocketOption<T> option,
catch (Throwable x)
{
if (LOG.isDebugEnabled())
LOG.debug("Could not configure {} to {} on {}", option, value, channel);
LOG.debug("Could not configure {} to {} on {}", option, value, channel, x);
}
}

Expand Down
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,19 @@ protected ServerSocketChannel openAcceptChannel() throws IOException
return serverChannel;
}

private <T> void setSocketOption(ServerSocketChannel channel, SocketOption<T> option, T value)
{
try
{
channel.setOption(option, value);
}
catch (Throwable x)
{
if (LOG.isDebugEnabled())
LOG.debug("Could not configure {} to {} on {}", option, value, channel, x);
}
}

@Override
public void close()
{
Expand Down

0 comments on commit 325739b

Please sign in to comment.