[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Second shim




Thinking about a second shim to handle connection establishment, I've come up with code (not running yet ;-) to do a
	int connect_by_name(char *hostname, int port);
that can be implemented entirely as a library (using non-blocking connect() calls). It returns a socket file descriptor.


One could try to apply this technique to make connect() do the same thing, in coordination with getaddrinfo(), but that is more complex for several reasons: 1. Need the coordination between getaddrinfo() and connect() somewhere - need to store the alternate IP addresses so that connect() can find them. 2. Need to handle cases when the socket passed in to connect has already been bound, or has had some options set. 3. It isn't transparent to the application; the application might pass IP address B1 to the connect() call, but the connection is in fact made to IP address B2. Thus applications might fail due to this. The application needs to use getpeername() to find out the actual address to which it has connected.

For by connect_by_name() and the connect() hackery, this only applies to TCP; can't make it apply to UDP since UDP doesn't have a notion of "I succeeded using this IP address".

   Erik