B
BMermuys
Hi,
[inline]
All this behaviour is mostly because the socket class isn't a new clean
desing but a wrapper around the winsock API. And the api function recv sets
the last error to WSA_WOULDBLOCK when you read on a non-blocking socket
which hasn't any data available.
..NET wraps this error/warning code inside a SocketException.
In the winsock API , recv never returns 0 when no data is available. As for
as I know, receive should only return 0 when the client gracefully
disconnected.
Yes, that's the way you should do it, only read on readable sockets returned
from Select, and if receive throws or returns 0 then the connection is lost.
Greetings
[inline]
Michi Henning said:Yes. I read the documentation too. What I'm suggesting is that, no matter
how well documented, the behavior is wrong. It doesn't make sense
to throw an exception for expected behavior (getting no data from a
non-blocking socket), but to not throw for unexpected behavior
(when the connection is lost).
No. With the above code, I would loop indefinitely waiting for data if the
connection is lost, because Available returns zero in that case, even though
the documentation says that it throws an exception (which it does not).
Sorry, but I don't get it. The behavior of Receive() is simply back to front:
it throws an exception for the expected behavior, and doesn't throw an
exception for unexpected behavior.
All this behaviour is mostly because the socket class isn't a new clean
desing but a wrapper around the winsock API. And the api function recv sets
the last error to WSA_WOULDBLOCK when you read on a non-blocking socket
which hasn't any data available.
..NET wraps this error/warning code inside a SocketException.
In the winsock API , recv never returns 0 when no data is available. As for
as I know, receive should only return 0 when the client gracefully
disconnected.
That's simply throwing rocks in my
path because it makes a my control structures a mess. And Available
doesn't behave as the documentation states it should.
If the behavior were right, I wouldn't have to pay the extra cost of
making yet another system call before every attempted read, just to
see whether the connection is still up. Besides, doing this is unnecessary:
I *can* work out whether the connection is lost by checking whether
Select() returned a readable socket, but the physical read returned zero
bytes.
Yes, that's the way you should do it, only read on readable sockets returned
from Select, and if receive throws or returns 0 then the connection is lost.
Greetings