Search in sources :

Example 61 with DatagramChannel

use of java.nio.channels.DatagramChannel 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 62 with DatagramChannel

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

the class DatagramChannelMulticastTest method test_block_mixedAddressTypes_IPv4.

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

Example 63 with DatagramChannel

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

the class DatagramChannelMulticastTest method test_joinSourceSpecific_nonUniicastSourceAddress_IPv6.

public void test_joinSourceSpecific_nonUniicastSourceAddress_IPv6() throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    try {
        dc.join(GOOD_MULTICAST_IPv6, ipv6NetworkInterface, BAD_MULTICAST_IPv6);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    dc.close();
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel)

Example 64 with DatagramChannel

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

the class DatagramChannelMulticastTest method test_unblock_null.

public void test_unblock_null() throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    MembershipKey membershipKey = dc.join(GOOD_MULTICAST_IPv4, ipv4NetworkInterface);
    membershipKey.block(UNICAST_IPv4_1);
    try {
        membershipKey.unblock(null);
        fail();
    } catch (IllegalStateException expected) {
    // Either of these exceptions are fine
    } catch (NullPointerException expected) {
    // Either of these exception are fine
    }
    dc.close();
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Example 65 with DatagramChannel

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

the class DatagramChannelMulticastTest method test_joinAnySource_nonMulticastGroupAddress_IPv4.

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

Aggregations

DatagramChannel (java.nio.channels.DatagramChannel)211 InetSocketAddress (java.net.InetSocketAddress)91 ByteBuffer (java.nio.ByteBuffer)71 IOException (java.io.IOException)57 DatagramSocket (java.net.DatagramSocket)21 SocketAddress (java.net.SocketAddress)21 MembershipKey (java.nio.channels.MembershipKey)21 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)20 SocketChannel (java.nio.channels.SocketChannel)17 SelectionKey (java.nio.channels.SelectionKey)16 InetAddress (java.net.InetAddress)13 Selector (java.nio.channels.Selector)13 Test (org.junit.Test)11 SocketException (java.net.SocketException)9 ClosedChannelException (java.nio.channels.ClosedChannelException)9 Histogram (org.HdrHistogram.Histogram)8 CancelledKeyException (java.nio.channels.CancelledKeyException)7 DatagramPacket (java.net.DatagramPacket)5 NetworkInterface (java.net.NetworkInterface)5 ArrayList (java.util.ArrayList)5