8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
Alan Bateman
Alan.Bateman at oracle.com
Wed Jan 23 12:11:37 UTC 2019
On 23/01/2019 10:55, Florian Weimer wrote:
> :
> 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?
>
It's very platform specific as to whether you can read bytes in the
socket buffer when a connection reset is reported. This was something we
discussed on net-dev last year in the context of other changes to detach
the write path from interference due to connection reset. Classic
networking has always attempted to mask the differences by remembering
the connection reset so that subsequent calls to read work consistently
across platforms. There's nothing in the proposed changes that touches
or changes the long standing behavior.
As regards reading after available returns a position value then the
spec can only says that it doesn't block. It can't guarantee that the
read doesn't throw I/O exception. Calling close between available and
read is another scenario where read will fail.
-Alan
More information about the net-dev
mailing list