lua-users home
lua-l archive

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

On Mon, Jun 1, 2009 at 1:59 AM, Diego Nehab <> wrote:
> Hi,
>>> Yes, the DNS lookup can do that. What does an async DNS
>>> library look like?
>> It's a non-blocking wrapper[1] around a fixed and hacked up version[2]
>> of dns.lua[3]. A nice C replacement regularly features in our
>> dreams[4] :)
>> The catch is that we need to look up SRV records and need a reasonable
>> timeout, which the standard Linux resolver doesn't appear capable of.
> So there is a Lua implementation of gethostbyname that does
> not block?

Essentially yes, though it is a lot more powerful than gethostbyname().

>>> It seems as though you should have no
>>> trouble replacing the DNS lookup in LuaSocket with something
>>> else, without any changes to C code.
>> Oh so the DNS lookup is performed from inside LuaSocket? That greatly
>> simplifies things, thanks.
> I don't know what you mean by the question. LuaSocket has
> two DNS facilities. One is when you invoke
> socket.dns.toip(). The other is when you invoke connect()
> with a domain name. Both cases and up invoking
> gethostbyname.

Sorry, I was thinking that it was connect() which accepted the
unresolved hostname, my mistake of course :)

> What I meant is that if you have a Lua replacement of
> gethostbyname, you can do your own translation and pass the
> ip as a string to the non-blocking connect().

It would obviously have to function as a wrapper around the existing
connect()... the existing connect() would be called in a callback when
the DNS response arrives.

But this is certainly possible.