Re: Review of gnio, round 1



On 05/12/2009 05:22 AM, Paul LeoNerd Evans wrote:
> Speaking of GResolver, in the API (which I'm currently staring at here:
> 
> http://git.gnome.org/cgit/glib/diff/gio/gresolver.h?h=gresolver&id=05507dce1f540581028e8be0e220e68c44fade2f
> 
> ) I don't see any attempt at the gai()-style "hostname + servicename"
> resolver. Where's the ability to connect to, say, "www.google.com:http"?
> 
> Half the point of gai+gni was to unify the separate operations of
> hostname->IP and servicename->port, so they're in one combined place.
> gai() can therefore support things like SRV records, which the previous
> pair of gethostbyname+getservbyname cannot.

You're mixing up two very different things. getaddrinfo *does not* use
SRV records. When you pass a (non-numeric) string to getaddrinfo for
"service", it just looks that string up in /etc/services to translate it
to a port number, and returns that port number (regardless of whether or
not that service is really running on the host).

libresolv doesn't provide any dedicated SRV-lookup API. (You have to do
it by hand with res_query.) But GResolver supports SRV lookup via
g_resolver_lookup_service() and g_resolver_lookup_service_async(). (And
at a higher level via GNetworkService.)

GResolver intentionally does not support doing the servicename->port
mapping thing that getaddrinfo/getsrvbyname does though, because it's a
bad API; you can't know for sure what's going to be in /etc/services on
any given machine, and in particular, if you're using some very new
protocol, it's very likely that some people are going to try to run your
application on machines that don't have that protocol listed in
/etc/services. So it's always better to just provide your own #define
FOOBAR_PORT with the right port number, and then use that, rather than
crossing your fingers and hoping that GResolver will be able to map
"foobar" to the right number for you.

-- Dan


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