Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8053479

(dc) DatagramChannel.read() throws exception instead of discarding data when buffer too small

    XMLWordPrintable

Details

    • b07
    • x86
    • windows

    Backports

      Description

        If a DG channel is connected to a remote destination and read is called with a buffer that is smaller than the packet to be received, it is supposed to fill the buffer and discard the remaining data. On Windows, instead you get an exception with EMSGSIZE error ("Result too large")

        receive() works as expected. Given the different call paths, it might just require different flags to WSARecv() than are currently used.

        Test that shows the problem:

        import java.net.*;
        import java.nio.*;
        import java.nio.channels.*;
        import java.io.IOException;

        public class NioTest {
            public static void main (String[] args) throws Exception {

                InetAddress local = InetAddress.getLocalHost();
                InetSocketAddress bindaddr = new InetSocketAddress(local, 0);

                String host = local.getHostName();

                DatagramChannel c1 = DatagramChannel.open().bind(bindaddr);
                DatagramChannel c2 = DatagramChannel.open().bind(bindaddr);

                InetSocketAddress ad1 = (InetSocketAddress)c1.getLocalAddress();
                InetSocketAddress ad2 = (InetSocketAddress)c2.getLocalAddress();

                ByteBuffer bb = ByteBuffer.wrap("Hello world".getBytes());
                ByteBuffer bbb = ByteBuffer.allocate(1);

        c2.connect(ad1);
                c1.send(bb, ad2);

                c2.read(bbb);
            }
        }

        Attachments

          Issue Links

            Activity

              People

                alanb Alan Bateman
                michaelm Michael McMahon
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: