8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer

Florian Weimer fweimer at redhat.com
Wed Jan 23 10:55:11 UTC 2019


* Alan Bateman:

> On 23/01/2019 09:42, Florian Weimer wrote:
>> :
>> Do you plan to read from the socket buffer in the implementation of
>> available()?  The problem is that even if there is currently data in the
>> socket buffer, further data that arrives later can clear it.  I think
>> this can only happen as part of a connection reset.  Maybe that's okay
>> because reading will not block, but throw an exception instead?
>>
> Not planning for available to read. The long standing behavior in this
> area is for SIS.available to consistently return 0 after a connection
> reset has been detected. This is of course awkward to replicate in a
> new implementation as it requires detecting connection reset,
> something that was never implemented in the SocketChannel
> implementation (mostly because it's highly platform/implementation
> specific as to how read behaves when attempt after a connection
> reset).

Sorry, what I meant is that available() says that there are bytes, and
then when you try to read them, you get an exception because they are no
longer there.  I doubt that's the intent behind the
InputStream::available specification, but as I said, it still avoids
blocking, so it may match a literal interpretation.

But presumably this is already the behavior with SocketInputStream?

Thanks,
Florian


More information about the net-dev mailing list