Re: i/o in trasparente proxy??

From: <[email protected]>
Date: Wed, 15 Apr 98 01:16:55 EDT

>>>>> "Duane" == Duane Wessels <wessels@nlanr.net> writes:

Duane> What does select return if the connection failed?

Duane> We call connect() again to find out if it is really connected
Duane> (EISONN), or not (EINVAL).

Ah grasshopper, you have stumbled upon one of the great mysteries of UNIX.

In other words: It depends.

Select()/poll() returns writeability on async connect() completion. It also
returns readability if it had an error. But you may have received data from
the server before you called select()/poll() again, making the return
ambiguous.

So, you think you have an error - what do you do? The best option is to call
getsockopt() to get SO_ERROR. Unfortunately, some versions of UNIX don't
support that.

Your next option is to call connect() again - this will either return
EISCONN, or give you a SIGPIPE (which I hope you've handled...), or return
some error code which may or may not be the reason the connection failed (it
isn't under Solaris 2.x)

Another possibility is to try a zero-byte read(). This should tell you
whether or not connect() succeeded, and frequently gives you the actual
error, but your OS has to support zero-byte reads.

So, in short, it's a mess. I usually put in all three options and enable
whichever one gives me correct error information ("broken pipe" is amazingly
useless in tracking down why something failed...)

-- 
Carson Gaspar -- carson@cs.columbia.edu carson@tla.org carson@cugc.org
http://www.cs.columbia.edu/~carson/home.html
Queen Trapped in a Butch Body
Received on Wed Apr 15 1998 - 00:53:59 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:39:42 MST