Search in sources :

Example 6 with MembershipKey

use of java.nio.channels.MembershipKey in project j2objc by google.

the class DatagramChannelMulticastTest method test_block_cannotBlockWithSourceSpecificMembership.

public void test_block_cannotBlockWithSourceSpecificMembership() throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    MembershipKey membershipKey = dc.join(GOOD_MULTICAST_IPv4, ipv4NetworkInterface, UNICAST_IPv4_1);
    try {
        membershipKey.block(UNICAST_IPv4_2);
        fail();
    } catch (IllegalStateException expected) {
    }
    dc.close();
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Example 7 with MembershipKey

use of java.nio.channels.MembershipKey in project j2objc by google.

the class DatagramChannelMulticastTest method check_dropAnySource_twice.

private void check_dropAnySource_twice(InetAddress group, NetworkInterface networkInterface) throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    MembershipKey membershipKey = dc.join(group, networkInterface);
    assertTrue(membershipKey.isValid());
    membershipKey.drop();
    assertFalse(membershipKey.isValid());
    // Try to leave a group we are no longer a member of - should do nothing.
    membershipKey.drop();
    dc.close();
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Example 8 with MembershipKey

use of java.nio.channels.MembershipKey in project j2objc by google.

the class DatagramChannelMulticastTest method test_joinAnySource_blockLimit.

public void test_joinAnySource_blockLimit() throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    MembershipKey key = dc.join(GOOD_MULTICAST_IPv4, ipv4NetworkInterface);
    for (byte i = 1; i <= 15; i++) {
        InetAddress sourceAddress = Inet4Address.getByName("10.0.0." + i);
        try {
            key.block(sourceAddress);
        } catch (SocketException e) {
            // There is a limit, that's ok according to the RI docs. For this test a lower bound of 10
            // is used, which appears to be the default linux limit.
            // See /proc/sys/net/ipv4/igmp_max_msf
            assertTrue(i > 10);
            break;
        }
    }
    dc.close();
}
Also used : SocketException(java.net.SocketException) DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey) InetAddress(java.net.InetAddress)

Example 9 with MembershipKey

use of java.nio.channels.MembershipKey in project j2objc by google.

the class DatagramChannelMulticastTest method test_block_wildcardAddress.

public void test_block_wildcardAddress() throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    MembershipKey membershipKey = dc.join(GOOD_MULTICAST_IPv4, ipv4NetworkInterface);
    try {
        membershipKey.block(WILDCARD_IPv4);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    dc.close();
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Example 10 with MembershipKey

use of java.nio.channels.MembershipKey in project j2objc by google.

the class DatagramChannelMulticastTest method checkMembershipKeyAccessors.

private void checkMembershipKeyAccessors(InetAddress group, NetworkInterface networkInterface) throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    MembershipKey key = dc.join(group, networkInterface);
    assertSame(dc, key.channel());
    assertSame(group, key.group());
    assertTrue(key.isValid());
    assertSame(networkInterface, key.networkInterface());
    assertNull(key.sourceAddress());
    dc.close();
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Aggregations

MembershipKey (java.nio.channels.MembershipKey)25 DatagramChannel (java.nio.channels.DatagramChannel)22 SuppressJava6Requirement (io.netty.util.internal.SuppressJava6Requirement)3 InetAddress (java.net.InetAddress)2 InetSocketAddress (java.net.InetSocketAddress)2 ByteBuffer (java.nio.ByteBuffer)2 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1