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>

next in thread | raw e-mail | index | archive | help
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 th=
e 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:4=
14)
        at sun.nio.ch.DatagramChannelImpl.write(DatagramChannelImpl.java:43=
1)
        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 =3D DatagramChannel.open();
        DatagramSocket socket =3D channel.socket();
        System.out.println("channel:" + channel + ", socket:" + socket);
        byte[] buf =3D new byte[1024];
        DatagramPacket packet =3D new DatagramPacket(buf, buf.length);
        BufferedReader reader =3D new BufferedReader(new InputStreamReader(=
System.in));
        InetAddress address =3D InetAddress.getByName(args[0]);

        while ( true )
        {
            System.out.println("waiting...");
            String line =3D 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 =3D new ByteBuffer[2];
            bufs[0] =3D ByteBuffer.allocate(64);
            bufs[0].put("Hello".getBytes());
            bufs[0].flip();
            bufs[1] =3D ByteBuffer.allocate(64);
            bufs[1].put("World".getBytes());
            bufs[1].flip();

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

}




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