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

(fc) FileChannel.transferFrom/transferFromArbitraryChannel to return -1 at some error condition

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Won't Fix
    • P4
    • None
    • None
    • core-libs

    Description

      in FileChannel.transferFromArbitraryChannel, when src.read returns -1, it means "the channel has reached end-of-stream", it could be a socket underlying is reset by peer host, or some other conditions. But this "-1" is completely hidden when transferFromArbitraryChannel returns back to File.Channel.transferFrom.

      Would it better to return -1 in FileChannel.transferFrom/transferFromArbitraryChannel when src.read returns -1 and tw is 0?

      The reason for such a request is: We met some condition where user is relying on Channel.isOpen to tell if the underlying socket is usable (I know this is not the expected behavior) and then call FileChannel.transferFrom. it looks like following code snippet:
      while (srcSocketChannel.isOpen()) {
        long l = fileChannel.transferFrom(srcSocketChannel,...);
        if (l == -1) { // break out the while loop }
      }
      There is one condition, where peer side has closed the underlying socket, at this situation, the above loop will be a infinite loop.

      I think it's more friendly for end user if we could change the behavior of FileChannel.transferFrom/transferFromArbitraryChannel to return -1 when src.read returns -1 and tw is 0.

      How do you think about it?

      Attachments

        Issue Links

          Activity

            People

              mli Hamlin Li
              mli Hamlin Li
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: