RFR: 8310807: java/nio/channels/DatagramChannel/Connect.java timed out [v2]

Daniel Fuchs dfuchs at openjdk.org
Thu Nov 16 16:41:52 UTC 2023


On Thu, 16 Nov 2023 15:44:11 GMT, Mark Sheppard <msheppar at openjdk.org> wrote:

>> test/jdk/java/nio/channels/DatagramChannel/Connect.java line 160:
>> 
>>> 158:                     if (!RESPONSE.equals(cb.toString())) {
>>> 159:                         log.println("Initiator received unexpected message: continue waiting");
>>> 160:                         continue;
>> 
>> `DatagramChannel.read(ByteBuffer)`, through the contract of `ReadableByteChannel.read(ByteBuffer)`, says that the number of bytes added into the passed `ByteBuffer` may not always be the remaining space in the buffer. i.e. `dc.read(bb)` may just read in few bytes at a time.
>> 
>> Do you think that's a practical possibility in the context of this test and would that then mean, in this current proposed form, the `RESPONSE.equals(cb.toString())` will never evaluate to `true` and we would end up looping forever?
>> 
>> Perhaps we should use the return value of `dc.read(bb)` to determine when to do this response equality check and until then keep accumulating the received bytes?
>
> UDP send and receive is atomic, there are no partial send or receive of a datagram (unlike a stream). Thus the initiator send its message as a complete datagram, then when the responder invokes receive and if the send has been successful, the receive will be the complete datagram sent by the initiator -- no partial datagram. That is unless the datagram is a stray datagram from another source, in which the responder continues to wait for the expected datagram. The reverse is true for the responder, it will receive a complete (atomic) message and echo that back to the initiator

Yes - for DatagramChannel the whole UDP payload is copied in the ByteBuffer. It may get truncated if the ByteBuffer doesn't have enough remaining bytes, but I made sure that the ByteBuffers used in the test are big enough to contain the UDP payload of the datagrams sent by the test. Bytes that don't fit in the ByteBuffer are discarded. Two calls to read would get you two payloads from two different datagrams.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16661#discussion_r1396016255


More information about the nio-dev mailing list