-
Bug
-
Resolution: Fixed
-
P4
-
7, 8, 11, 15
-
b07
-
x86
-
windows
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8320893 | 11.0.22 | Kangcheng Xu | P4 | Resolved | Fixed | b05 |
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);
}
}
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);
}
}
- backported by
-
JDK-8320893 (dc) DatagramChannel.read() throws exception instead of discarding data when buffer too small
- Resolved