-
Enhancement
-
Resolution: Won't Fix
-
P4
-
None
-
None
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?
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?
- relates to
-
JDK-8260694 (fc) Clarify FileChannel.transferFrom to better describe "no bytes available" case
-
- Resolved
-