Re: TCP connect in Non Blocking Mode



Alex Fraser <me@xxxxxxxxxxx> writes:
Rainer Weikusat wrote:
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

This does not specify the case where a blocking connect() would have
failed, which is the issue at hand.

It specifies the case I was refering to, which happened to be the one
the discussion had moved to at this point, cf

,----
| If the connection succeeds, it will be writable but not
| readable, so checking for 'read'ability won't detect
| connection success.
`----

and

,----
| Whether a socket will become readable after connect
| also depends on the protocol used ... SMTP and FTP
`----

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.

Comparing

,----
| 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.
`----

with

,----
| A style of programming dominated by ritual inclusion of code
| or program structures that serve no real purpose. A cargo cult
| programmer will usually explain the extra code as a way of
| working around some bug encountered in the past,
`----

I consider the first text to be a near-perfect example of what is
described in the second. If it is or it isn't is completely
independent of anything related to me, and your ad hominem is
therefore besides the point.




.



Relevant Pages

  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation [try #3]
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... kernel socket family. ... presentation side is left to the client. ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... Make it possible for the client socket to be used to go to more than one ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation [try #2]
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... Make it possible for the client socket to be used to go to more than one ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • Re: Socket Exception
    ... In this case the server most likely rejected your ... connection. ... Each command is a new socket connection that is opened and closed ... /// Required designer variable. ...
    (microsoft.public.win32.programmer.networks)
  • Re: attn:MVPs
    ... winsock dll to the managed .net environment. ... I have an asynchronous TCP socket that listens for data from ... The Slave should not initiate any connection requests/ send other messages ... EXCEPT the acknowledgement for the incoming messages from master, ...
    (microsoft.public.dotnet.framework)