Em 16/08/2006, às 11:00, Justin Erenkrantz escreveu:
On 8/16/06, Davi Arnaut <[EMAIL PROTECTED]> wrote:
The only portable way to "detect" a broken connection is using
SO_KEEPALIVE
or to write/read "ping" data through the socket -- which is what
keepalive does.
How would SO_KEEPALIVE help? The other end is deliberately closing
the connection and we need to know that.
It would help detect a broken connection, not a RST state.
Would a non-blocking read() followed by a poll()/select() be useful?
We'd still get a 0 back from read() - but if it was the EOF, would the
state of the socket change to be in the 'exceptional' state then if we
repoll? -- justin
Humm, read returning 0 is a EOF, you could also maybe
getsockopt(SO_ERROR) on the socket to confirm the EOF.
Upon receive of a RST the socket should move to the closed
state, and poll should return immediately if the POLLHUP mask
was passed for that socket, and SO_ERROR should be one of
ECONNREFUSED (syn sent)/EPIPE (close wait)/ECONNRESET
or none if the socket was already closed.
Select is a different beast because of the definition of what is
a "exceptional condition" which may be pending error conditions
or oob data. I think the "exception fd" of select is similar to a poll
with POLLPRI mask, so it shoud'nt signal a connection reset.
--
Davi Arnaut