Hello!
On Mon, Jul 8, 2013 at 11:18 PM, Glen Cao wrote:
> First thank you very much for providing such great ngx_lua.
>
Glad you like it :)
> ATT.
> We could eliminate the ngx_lua socket APIs' dependency on
> ngx_http_core_module.resolver directive, couldn't we?
>
I don't want to. Maybe you just want to support the /etc/resolv.conf
and /etc/hosts files? We *could* make the nginx core's resolver
support that.
> In the implementations of APIs of udpsocket:setpeername and
> tcpsocket:connect, we accept the first argument host in forms of both IP and
> domain name, and then call ngx_resolve_start to get the peer address.
> According to the implementations of ngx_resolve_start and ngx_inet_addr, we
> depend on the resolver derective closely.
>
If you're using IP addresses directly in setpeername() or connect(),
then you don't have to configure the "resolver" directive in
nginx.conf. Only when you use a domain name, the "resolver" directive
is required according to the current implementation.
Therefore, you can use external resolvers like lua-resty-dns to do the
DNS lookup completely in Lua and feed the IP address manually into the
setpeername() and connect() calls:
https://github.com/agentzh/lua-resty-dns
> Could we pre-process the pass-in host argument before we use that arugment
> and call ngx_resolve_start? e.g., We could use gethostbyname or getaddrinfo
> to get the IP of host which is a domain name, and then call
> ngx_resolve_start as usual (or even call ngx_inet_addr directly, I'm not
> sure), so that we need not depend on the ngx_http_core_module.resolver
> directive.
>
No, both the gethostbyname and getaddrinfo API functions are blocking,
which is unacceptable for event-driven single-threaded applications
like Nginx. And I believe that's also why Nginx implements its own
nonblocking resolver from scratch in the first place.
BTW, you're recommended to join the openresty-en mailing list and post
such questions there:
https://groups.google.com/group/openresty-en
Thank you for your collaborations! I'm cc'ing this list.
Best regards,
-agentzh