Socket InputStream.available may return a positive value after shutdown

Jing LV lvjing at linux.vnet.ibm.com
Thu Feb 17 00:09:30 PST 2011


于 2011-1-26 20:32, Alan Bateman 写道:
> Jing LV wrote:
>> Hello,
>>
>> I am using java.net.Socket and find an strange behaviour. If Socket
>> inputstream is shutdown, and there was still some data remaining, its
>> available() method may still return a positive value. I checked with the
>> java spec, and the document of Socket.shutdownInput() said:
>> "Places the input stream for this socket at "end of stream". Any data
>> sent to the input stream side of the socket is acknowledged and then
>> silently discarded.
>> If you read from a socket input stream after invoking shutdownInput() on
>> the socket, the stream will return EOF. "
>> What's more, as I check inputStream.read(), it return a EOF, So I guess
>> it would not be correct if available return a positive value.
> I agree this needs to be looked at and I've created a bug to track it:
>
> 7014860: Socket.getInputStream().available() not clear for case that 
> connection is shutdown for reading
>
> (should be available on bugs.sun.com within 24h).
>
> As it stands the behavior is highly platform specific. Solaris's 
> ioctl(FIONREAD) does return 0 when the connection has been shutdown 
> for reading. Linux continues to return the number of bytes in the 
> socket buffer, as does Windows. There may be alternative SocketImpls 
> that do something different. Minimally, Socket#getInputStream and 
> Socket#shutdownInput should be clarified to make it clear what the 
> expected behavior is, even if is platform specific.
>
> -Alan
Thanks Alan! I try to follow this issue but has no luck on bugs.sun.com 
with the number 7014860. Am I miss something?

-- 
Best Regards,
Jimmy, Jing LV





More information about the net-dev mailing list