Re: TCP connect in Non Blocking Mode
- From: Alex Fraser <me@xxxxxxxxxxx>
- Date: Sun, 27 Apr 2008 21:09:41 +0100
Rainer Weikusat wrote:
Rainer Temme <Rainer_Temme@xxxxxxxxxxxxxxxxxxxxxx> writes:David Schwartz wrote:[...]If the connection succeeds, it will be writable but not readable,Whether a socket will become readable after connect
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.
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
This does not specify the case where a blocking connect() would have
failed, which is the issue at hand.
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. [...]
I agree, but the only reason I can think of for considering Rainer
Temme's suggestion is such is not reading the thread.
Alex
.
- Follow-Ups:
- Re: TCP connect in Non Blocking Mode
- From: Rainer Weikusat
- 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
- Re: TCP connect in Non Blocking Mode
- From: Rainer Weikusat
- TCP connect in Non Blocking Mode
- Prev by Date: sharing memory map between processes (same parent)
- Next by Date: Re: sharing memory map between processes (same parent)
- Previous by thread: Re: TCP connect in Non Blocking Mode
- Next by thread: Re: TCP connect in Non Blocking Mode
- Index(es):
Relevant Pages
|