DatagramCahnnel scatter/gather problem on diablo 1.6.0_07-b02

Joe Lin jlin at maxiscale.com
Mon Feb 1 00:01:41 UTC 2010


Hi I wrote a sample program trying to use DatagramChannel.write(ByteBuffer[] bufs). The exact same code works on Windows and Linux. But it fails on the Diablo VM under FreeBSD 7.0 64 bit. The exception:

Exception in thread "main" java.io.IOException: Invalid argument
        at sun.nio.ch.DatagramDispatcher.writev0(Native Method)
        at sun.nio.ch.DatagramDispatcher.writev(DatagramDispatcher.java:37)
        at sun.nio.ch.IOUtil.write(IOUtil.java:164)
        at sun.nio.ch.DatagramChannelImpl.write0(DatagramChannelImpl.java:414)
        at sun.nio.ch.DatagramChannelImpl.write(DatagramChannelImpl.java:431)
        at java.nio.channels.DatagramChannel.write(DatagramChannel.java:418)
        at coco.McastSender.main(McastSender.java:68).

Following is the test program. Thanks for any help:

public class McastSender
{

    public static void main(String[] args) throws IOException
    {
        DatagramChannel channel = DatagramChannel.open();
        DatagramSocket socket = channel.socket();
        System.out.println("channel:" + channel + ", socket:" + socket);
        byte[] buf = new byte[1024];
        DatagramPacket packet = new DatagramPacket(buf, buf.length);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        InetAddress address = InetAddress.getByName(args[0]);

        while ( true )
        {
            System.out.println("waiting...");
            String line = reader.readLine();
            channel.connect(new InetSocketAddress(address, 9998));
            if ( channel.isConnected() )
                System.out.println("channel is connected");
            else
                System.out.println("channel is not connected");
            packet.setData("Hello".getBytes());
            ByteBuffer[] bufs = new ByteBuffer[2];
            bufs[0] = ByteBuffer.allocate(64);
            bufs[0].put("Hello".getBytes());
            bufs[0].flip();
            bufs[1] = ByteBuffer.allocate(64);
            bufs[1].put("World".getBytes());
            bufs[1].flip();

            channel.write(bufs);
            System.out.println("sent to " + address);
            channel.disconnect();
        }
    }

}



More information about the freebsd-java mailing list