-->
Page 1 of 1

heap, DNS failure, pcall

PostPosted: Sun Dec 14, 2014 12:07 pm
by GeoNomad
It seems that currently, if the DNS lookup fails, there is no way to trap the call, it merely prints 'DNS Failed' on the console.

Failure can be due to an incorrect host name, or failure of the DNS lookup by the router, etc.

Code: Select allconn=net.createConnection(net.TCP, 0)
conn:dns('xxxbenlo.com',function(conn,ip) ipaddr=ip conn:close() end)


For example. This also results in permanently lost RAM.

I hoped that pcall would remedy this:

Code: Select allif pcall( function() dofile('IPLookup.lua') end ) then
   print(ipaddr)
else
   print('failed')
end


But sadly not. With a correct host name like benlo.com, pcall does return true and the function does not eat heap.

In general, will Lua functions work correctly inside a pcall? This will be pretty important for production code to handle exceptions. Do any work now?

On the subject of DNS lookup, it is not clear whether the DNS is currently assigned by the DHCP or as rumor has it, fixed to some Chinese site. Either way, we should be able to override it with the IP address of our preferred DNS server, such as Open DNS: 208.67.222.222 or 208.67.220.220 or Google 8.8.8.8 or 8.8.4.4