Skip to content

Commit

Permalink
Configure multicast only with JDK
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Sep 20, 2017
1 parent c6e9eae commit 70d9ef8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
29 changes: 17 additions & 12 deletions src/main/java/io/vertx/core/datagram/impl/DatagramSocketImpl.java
Expand Up @@ -36,6 +36,7 @@
import io.vertx.core.net.impl.ConnectionBase;
import io.vertx.core.net.impl.PartialPooledByteBufAllocator;
import io.vertx.core.net.impl.SocketAddressImpl;
import io.vertx.core.spi.Transport;
import io.vertx.core.spi.metrics.DatagramSocketMetrics;
import io.vertx.core.spi.metrics.Metrics;
import io.vertx.core.spi.metrics.MetricsProvider;
Expand Down Expand Up @@ -67,8 +68,9 @@ public static DatagramSocketImpl create(VertxInternal vertx, DatagramSocketOptio
private Handler<Throwable> exceptionHandler;

private DatagramSocketImpl(VertxInternal vertx, DatagramSocketOptions options) {
DatagramChannel channel = vertx.transport().datagramChannel(options.isIpV6() ? InternetProtocolFamily.IPv6 : InternetProtocolFamily.IPv4);
configureChannel(channel, new DatagramSocketOptions(options));
Transport transport = vertx.transport();
DatagramChannel channel = transport.datagramChannel(options.isIpV6() ? InternetProtocolFamily.IPv6 : InternetProtocolFamily.IPv4);
configureChannel(transport == JdkTransport.INSTANCE, channel, new DatagramSocketOptions(options));

ContextImpl context = vertx.getOrCreateContext();
if (context.isMultiThreadedWorkerContext()) {
Expand Down Expand Up @@ -313,7 +315,8 @@ public Metrics getMetrics() {
return metrics;
}

private static void configureChannel(DatagramChannel channel,
private static void configureChannel(boolean configureMulticast,
DatagramChannel channel,
DatagramSocketOptions options) {
if (options.getSendBufferSize() != -1) {
channel.config().setSendBufferSize(options.getSendBufferSize());
Expand All @@ -327,15 +330,17 @@ private static void configureChannel(DatagramChannel channel,
channel.config().setTrafficClass(options.getTrafficClass());
}
channel.config().setBroadcast(options.isBroadcast());
channel.config().setLoopbackModeDisabled(options.isLoopbackModeDisabled());
if (options.getMulticastTimeToLive() != -1) {
channel.config().setTimeToLive(options.getMulticastTimeToLive());
}
if (options.getMulticastNetworkInterface() != null) {
try {
channel.config().setNetworkInterface(NetworkInterface.getByName(options.getMulticastNetworkInterface()));
} catch (SocketException e) {
throw new IllegalArgumentException("Could not find network interface with name " + options.getMulticastNetworkInterface());
if (configureMulticast) {
channel.config().setLoopbackModeDisabled(options.isLoopbackModeDisabled());
if (options.getMulticastTimeToLive() != -1) {
channel.config().setTimeToLive(options.getMulticastTimeToLive());
}
if (options.getMulticastNetworkInterface() != null) {
try {
channel.config().setNetworkInterface(NetworkInterface.getByName(options.getMulticastNetworkInterface()));
} catch (SocketException e) {
throw new IllegalArgumentException("Could not find network interface with name " + options.getMulticastNetworkInterface());
}
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/io/vertx/test/core/VertxTestBase.java
Expand Up @@ -30,7 +30,6 @@
import io.vertx.core.net.KeyCertOptions;
import io.vertx.core.net.PfxOptions;
import io.vertx.core.net.TCPSSLOptions;
import io.vertx.core.spi.Transport;
import io.vertx.core.spi.cluster.ClusterManager;
import io.vertx.test.fakecluster.FakeClusterManager;
import org.junit.Rule;
Expand All @@ -47,7 +46,7 @@
*/
public class VertxTestBase extends AsyncTestBase {

private static final boolean useNativeTransport = Boolean.getBoolean("vertx.useNativeTransport");
public static final boolean USE_NATIVE_TRANSPORT = Boolean.getBoolean("vertx.useNativeTransport");
private static final Logger log = LoggerFactory.getLogger(VertxTestBase.class);

@Rule
Expand Down Expand Up @@ -78,7 +77,7 @@ public void setUp() throws Exception {

protected VertxOptions getOptions() {
VertxOptions options = new VertxOptions();
options.setPreferNativeTransport(useNativeTransport);
options.setPreferNativeTransport(USE_NATIVE_TRANSPORT);
return options;
}

Expand Down

0 comments on commit 70d9ef8

Please sign in to comment.