Is Socket.Available guaranteed to throw a SocketException on disconnect?

249 Views Asked by At

The information below is given on the MSDN article on the Socket.Available property.

If the remote host shuts down or closes the connection, Available can throw a SocketException.

The keyword here being can. My question is:

Is Socket.Available just as reliable as Socket.Receive() to throw a SocketException on disconnect, and more directly, under what circumstances will Socket.Available not throw a SocketException?

1

There are 1 best solutions below

1
On

Internally Available is calling the native method ioctlsocket with the command FIONREAD, if that function returns SOCKET_ERROR then it raises a SocketException.

So to answer your question Socket.Available not throw a SocketException when a call to ioctlsocket could be made without error.