Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 31 Jan 2010 18:01:38 -0600
From:      Joe Lin <jlin@maxiscale.com>
To:        "freebsd-java@freebsd.org" <freebsd-java@freebsd.org>
Subject:   DatagramCahnnel scatter/gather problem on diablo 1.6.0_07-b02
Message-ID:  <8B6860326495B2438DCBEA74AA981C7A78B220E0@MBX01.exg5.exghost.com>

index | next in thread | raw e-mail

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();
        }
    }

}



home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8B6860326495B2438DCBEA74AA981C7A78B220E0>