Re: TCP connect in Non Blocking Mode
- From: Rainer Weikusat <rweikusat@xxxxxxxxxxx>
- Date: Sun, 27 Apr 2008 14:24:55 +0200
Rainer Temme <Rainer_Temme@xxxxxxxxxxxxxxxxxxxxxx> writes:
David Schwartz wrote:
[...]
If the connection succeeds, it will be writable but not readable,
so checking for 'read'ability won't detect connection success.
This is why the typical pattern is to check an asynchronous 'connect'
attempt only for writability.
Whether a socket will become readable after connect
also depends on the protocol used ... SMTP and FTP
are exaples of protocols where the serverside
will send an immediate message to the client
after successful connection.
Anyhow, my suggestion was to set the bit in the readset
as well as in the writeset. You might regard this as redundant
but (as even you had to admit) it will not harm.
The to-be-expected behaviour is actually standardized:
If the connection cannot be established immediately and
O_NONBLOCK is set for the file descriptor for the socket,
connect() shall fail and set errno to [EINPROGRESS], but the
connection request shall not be aborted, and the connection
shall be established asynchronously. Subsequent calls to
connect() for the same socket, before the connection is
established, shall fail and set errno to [EALREADY].
When the connection has been established asynchronously,
select() and poll() shall indicate that the file descriptor
for the socket is ready for writing.
http://www.opengroup.org/onlinepubs/009695399/functions/connect.html
Additionally, 'cargo cult programming'
http://catb.org/jargon/html/C/cargo-cult-programming.html
does harm. It causes the technical damage of keeping the machine busy
with doing useless instead of useful things. But that's the less
serious problem. The much more serious one is that code is
harder to understand and change meaningfully when it is more
complicated and the most complicated thing to understand is something
which defies understanding because it is inherently without meaning.
The latter becomes especially nasty when someone different from the
original author inherits the code.
.
- Follow-Ups:
- Re: TCP connect in Non Blocking Mode
- From: Alex Fraser
- Re: TCP connect in Non Blocking Mode
- References:
- TCP connect in Non Blocking Mode
- From: Prabhu
- Re: TCP connect in Non Blocking Mode
- From: Rainer Temme
- Re: TCP connect in Non Blocking Mode
- From: David Schwartz
- Re: TCP connect in Non Blocking Mode
- From: Rainer Temme
- Re: TCP connect in Non Blocking Mode
- From: David Schwartz
- Re: TCP connect in Non Blocking Mode
- From: Rainer Temme
- TCP connect in Non Blocking Mode
- Prev by Date: Re: stack, pop, push and min in o(1)
- Next by Date: Re: /dev/urandom too slow on my system
- Previous by thread: Re: TCP connect in Non Blocking Mode
- Next by thread: Re: TCP connect in Non Blocking Mode
- Index(es):
Relevant Pages
|