-1 and orderly socket shutdown

Alan Bateman Alan.Bateman at Sun.COM
Wed Apr 22 12:55:32 PDT 2009


Leon Finker wrote:
>
> Is there a reason that result of -1 is used instead of somewhat 
> universal 0 for detecting graceful shutdown on recv side for sockets? 
> Thanks!
>
EOF can't be indicated by 0 as otherwise you couldn't distinguish it 
from cases where zero bytes are read (say a SocketChannel configured in 
non-blocking mode).

-Alan.



More information about the nio-discuss mailing list