Skip to content

Commit

Permalink
default socket reuse address value should be non null
Browse files Browse the repository at this point in the history
The default for reuse address was null on Windows and casting to a boolean would
result in a NPE. This makes the default on Windows false and changes the return
type to a boolean and removes the need to check for nulls.
  • Loading branch information
jaymode committed May 20, 2015
1 parent 40bd56b commit a40ba3b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public static enum StackType {
localAddress = localAddressX;
}

public static Boolean defaultReuseAddress() {
return Constants.WINDOWS ? null : true;
public static boolean defaultReuseAddress() {
return Constants.WINDOWS ? false : true;
}

public static boolean isIPv4() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer

protected final String tcpNoDelay;
protected final String tcpKeepAlive;
protected final Boolean reuseAddress;
protected final boolean reuseAddress;

protected final ByteSizeValue tcpSendBufferSize;
protected final ByteSizeValue tcpReceiveBufferSize;
Expand Down Expand Up @@ -240,10 +240,8 @@ protected void doStart() {
}
serverBootstrap.setOption("receiveBufferSizePredictorFactory", receiveBufferSizePredictorFactory);
serverBootstrap.setOption("child.receiveBufferSizePredictorFactory", receiveBufferSizePredictorFactory);
if (reuseAddress != null) {
serverBootstrap.setOption("reuseAddress", reuseAddress);
serverBootstrap.setOption("child.reuseAddress", reuseAddress);
}
serverBootstrap.setOption("reuseAddress", reuseAddress);
serverBootstrap.setOption("child.reuseAddress", reuseAddress);

// Bind and start to accept incoming connections.
InetAddress hostAddressX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,8 @@ private ClientBootstrap createClientBootstrap() {

clientBootstrap.setOption("receiveBufferSizePredictorFactory", receiveBufferSizePredictorFactory);

Boolean reuseAddress = settings.getAsBoolean("transport.netty.reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress()));
if (reuseAddress != null) {
clientBootstrap.setOption("reuseAddress", reuseAddress);
}
boolean reuseAddress = settings.getAsBoolean("transport.netty.reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress()));
clientBootstrap.setOption("reuseAddress", reuseAddress);

return clientBootstrap;
}
Expand Down Expand Up @@ -376,10 +374,8 @@ private Settings createFallbackSettings() {
fallbackSettingsBuilder.put("tcp_keep_alive", fallbackTcpKeepAlive);
}

Boolean fallbackReuseAddress = settings.getAsBoolean("transport.netty.reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress()));
if (fallbackReuseAddress != null) {
fallbackSettingsBuilder.put("reuse_address", fallbackReuseAddress);
}
boolean fallbackReuseAddress = settings.getAsBoolean("transport.netty.reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress()));
fallbackSettingsBuilder.put("reuse_address", fallbackReuseAddress);

ByteSizeValue fallbackTcpSendBufferSize = settings.getAsBytesSize("transport.netty.tcp_send_buffer_size", settings.getAsBytesSize(TCP_SEND_BUFFER_SIZE, TCP_DEFAULT_SEND_BUFFER_SIZE));
if (fallbackTcpSendBufferSize != null) {
Expand Down Expand Up @@ -442,7 +438,7 @@ private void createServerBootstrap(String name, Settings settings) {
String publishHost = settings.get("publish_host");
String tcpNoDelay = settings.get("tcp_no_delay");
String tcpKeepAlive = settings.get("tcp_keep_alive");
Boolean reuseAddress = settings.getAsBoolean("reuse_address", NetworkUtils.defaultReuseAddress());
boolean reuseAddress = settings.getAsBoolean("reuse_address", NetworkUtils.defaultReuseAddress());
ByteSizeValue tcpSendBufferSize = settings.getAsBytesSize("tcp_send_buffer_size", TCP_DEFAULT_SEND_BUFFER_SIZE);
ByteSizeValue tcpReceiveBufferSize = settings.getAsBytesSize("tcp_receive_buffer_size", TCP_DEFAULT_RECEIVE_BUFFER_SIZE);

Expand Down Expand Up @@ -478,10 +474,8 @@ private void createServerBootstrap(String name, Settings settings) {
}
serverBootstrap.setOption("receiveBufferSizePredictorFactory", receiveBufferSizePredictorFactory);
serverBootstrap.setOption("child.receiveBufferSizePredictorFactory", receiveBufferSizePredictorFactory);
if (reuseAddress != null) {
serverBootstrap.setOption("reuseAddress", reuseAddress);
serverBootstrap.setOption("child.reuseAddress", reuseAddress);
}
serverBootstrap.setOption("reuseAddress", reuseAddress);
serverBootstrap.setOption("child.reuseAddress", reuseAddress);

serverBootstraps.put(name, serverBootstrap);
}
Expand Down

0 comments on commit a40ba3b

Please sign in to comment.