Daniel Stenberg <[EMAIL PROTECTED]> writes:

> On Tue, 15 Jan 2002, Hrvoje Niksic wrote:
> 
>> > Well, why extract the addresses when you can just leave them in the
>> > struct and pass a pointer to that?
>>
>> Because I'm caching the result of the lookup, and making a deep
>> copy of `struct hostent' is not exactly easy.  (Yes, I know libcurl
>> does it, but the code is not exactly pretty, and I'd like to avoid
>> doing that.)
> 
> No, the code doing that copy is not pretty. Deep-copying a struct
> like the hostent one can hardly be made pretty.

Agreed.  That, and the fact that I don't *need* other data from
hostent, made me decide that I don't want to keep struct hostent
around.

> The "easiness" comes with the fact that you have one pointer to the
> complete host info.  Be it hostent for IPv4 or addrinfo for
> IPv6. Then the connect code can take that pointer and walk through
> the list of addresses and attempt to connect.

Yes, but that's exactly the abstraction I've built for 1.8.  That
pointer is called `struct address_list'.

>> >       struct addrinfo *ai;
>> >
>> >       sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
>> >       rc = connect(sockfd, ai->ai_addr, ai->ai_addrlen);
>>
>> Except the port number can be different for each connection.
> 
> I think that's the intended beauty of this API. It sort of hides
> that fact.  We don't even have to bother about which protocol it
> uses. It works the same.

I don't think it's useful to hide the fact that one can connect to a
different port of the same port.  For example, `wget http://foo:80/'
and `wget http://foo:81/' must connect to different ports, and I'd
prefer to look up `foo' only once.

But maybe I just don't see the beauty.  :-)

>> And it won't work in IPv4 where I don't have `struct addrinfo'
>> handy.
> 
> The getaddrinfo() could theoreticly work just as well on IPv4-only
> machines, as it is IP version unbound.

Sure, but older OS'es don't have it implemented -- so I need to
support the old API anyway.

> I still think you can do it like this:
> 
> #ifdef HAVE_GETADDRINFO
> typedef struct addrinfo *hostinformation;
> #else
> /* current system */
> typedef struct whateveryouhavetoday *hostinformation;
> #endif

That could of course work, but it'd defeat the very idea behind the
struct whateverihavetoday (`struct address_list'), which is to allow
the callers to use a clean API to access the underlying host
information.

> But, I'm talking a lot more than what I have knowledge about with
> regard to how the wget code is designed. My discussion is generic
> and may not apply to wget internals.

If you have time, please take a glance at Wget 1.8.1's `host.c' and
`connect.c'.  I believe it will make my POV much clearer.

Reply via email to