From: Christopher Kohlhoff (chris_at_[hidden])
Date: 2006-06-25 23:53:02
Giovanni P. Deretta <gpderetta_at_[hidden]> wrote:
> Pedro Lamarão wrote:
> > Peter Petrov escreveu:
> > > Why is "resolver" in the "ip::tcp" namespace? A DNS
> > > resolver certainly has nothing to do with the TCP
> > > protocol. It should be in the "ip" namespace instead.
> > It shouldn't be in the "ip" namespace either.
> > The name translation service in any modern operating system
> > can return address objects for any network families it
> > supports.
> > In practice, getaddrinfo can return addresses for IPv4 and
> > IPv6. There is no reason why it can't return addresses for
> > any other kind of network (unless naming objects in that
> > network is radically different from "host"/"service").
> Just because the system resolver (getaddrinfo) could in
> principle resolve all kind of addresses, it doesn't mean that
> the asio resolver should.
> The asio resolver returns a protocol specific address
> (actually an iterator to a list of protocol specific
> addresses) and thus is strongly typed. If the resolver where
> to be generic, it would return an iterator to an heterogeneous
> list of addresses: the address (and socket types initialized
> from the address) would need to be dynamically typed. The asio
> interface is designed with static (not dynamic) polymorphisms
> in mind, so the resolver should be protocol specific.
What Giovanni said. After all, it was his suggestion in the
review to add this strong typing :)
I do feel that the new asio interface strikes the right balance
between strong typing (to allow the compiler to detect more
errors) and dynamic typing (in that you can use ip::tcp::socket
without needing to know if it's IPv4 or IPv6).
Note that it is possible to implement a generic socket using
asio. You would have to create a runtime-polymorphic protocol
class, and then instantiate the basic_*_socket<> and
basic_resolver<> templates on it.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk