Hi folks.
I'm experiencing an odd problem using a non-blocking connect() call. Our
code is vanilla in this respect - it uses fcntl() to set the non-blocking
bit, etc., and the code works fine. However, during testing, we tried
running the code against machines on the net which are not listening at the
standard ports for our application. We expected that this would cause our
background connection attempts to fail, which we would detect by periodic
select() calls to see if the socket is writable. However, this non-blocking
connect() call _always_ seems to succeed when run against a valid host
which does not have our server running. To further confuse the issue, when
we vary the port number, it seems that the non-blocking connect() _always_
succeeds. Also, when we use a _blocking_ connect call to the same address
and port, we get (again, as expected), a -1 returned from connect, with
errno = ECONNREFUSED.
The problem is, our code sends a message to the server when the connection
is "established", i.e. when select() indicates the socket is writable.
However, such a socket isn't writable, really - there is no server at the
other end. As you might expect, when we send the message, we get a SIGPIPE,
which we catch, so our program doesn't crash.
Am I missing something here? I thought the point of using a non-blocking
connect() was to put it in the background. Is there some other step that
must be taken in order to ensure that the connection has been established?
Any help or ideas appreciated.
Eric Winter
Hughes STX