It looks like you are using nsIDNSService correctly, but I don't see how you are hooking this code up to the rest of Firefox. You said that you based your code on nsSample.js, but I don't see the code here that handles XPCOM component registration. Feel free to attach a complete example, and I'll help debug.

-Darin



Ludovic LANGE wrote:

Hello,

Forgive me if it's not the right place to ask. I am trying to use the dns-service from an extension (XPI), and while the 'resolve' method is working as it should, using the 'asyncResolve' leads to FireFox hanging.

The code I'm using in my javascript file is at the end of the message, slightly edited, and so is the output of the console. FireFox seems to hang right after exiting the see_main() function.

I'm using FireFox v1.0PR under Windows.

I have no experience in writing listener (XPCom components in Javascript) and most of my inspiration comes from lxr.mozilla.org/seamonkey/source/xpcom/sample/nsSample.js concerning the 'listener' variable.
However, I don't know if I must 'register' this new component to XPCom, or if passing the variable 'listener' to the asyncResolve procedure is enough.


If there is nothing obviously wrong with this code, can you point me towards any ressource that could help me going forward on this subject ?

Regards,

Ludovic LANGE.

Javascript
========================================================
var DNS = null;

function see_DNS() {
if( !DNS ) {
var clazz = Components.classes['@mozilla.org/network/dns-service;1'];
var iface = Components.interfaces.nsIDNSService;
DNS = clazz.getService(iface);
//DNS.init();
}
return DNS;
}


var listener =
{
    QueryInterface : function(aIID)
    /* {00000000-0000-0000-c000-000000000046} */
    {
        dump("myListener: QueryInterface(" + aIID + ")\n");
        if (aIID.equals(Components.interfaces.nsIDNSListener) ||
             aIID.equals(Components.interfaces.nsISupports) ) {
            dump("myListener: QueryInterface : ok\n");
            return this;
        }
        throw Components.results.NS_NOINTERFACE;
        Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
        return null;
    },

onLookupComplete: function( aRequest, aRecord, aStatus )
{
dump("myListener: onLookupComplete(" + aRequest + ", " + aRecord + ", " + aStatus +")\n");
if( this._thumb && aStatus ) {
var sIp = aRecord.getNextAddrAsString();
if( sIp ) {
dump("myListener: onLookupComplete() sIp = " + sIp + "\n");
}
}
}
}


function sResolve(domain) {
dump("sResolve(" + domain + ")\n");
var dns = see_DNS();
if( dns ) {
var ip = null;
if( domain ) {
try {
ip = dns.resolve( domain, false ).getNextAddrAsString();
}
catch( ex ) {
dump("sResolve() Exception : " + domain + "\n");
}
if( ip ) {
dump("sResolve() Resolving '" + domain + "' as '" + ip + "'\n");
}
}
}
dump("sResolve() return\n");
return false;
}


function aResolve(domain) {
    dump("aResolve(" + domain + ")\n");
    var dns = see_DNS();
    if( dns ) {
        var ip = null;
        if( domain ) {
            try {
                ip = dns.asyncResolve( domain, false, listener, null );
            }
            catch( ex ) {
                dump("aResolve: Exception : " + href + "\n");
            }
        }
    }
    dump("aResolve() return\n");
    return false;
}


see_main() { dump("see_main()\n"); dump("begin\n"); sResolve("yahoo.co.uk"); aResolve("yahoo.com"); dump("see_main() return\n"); }

window.addEventListener("load",function() {see_main();} ,true);

========================================================


Console ======================================================== see_main() begin sResolve(yahoo.co.uk) sResolve() Resolving 'yahoo.co.uk' as '217.12.3.11' sResolve() return aResolve(yahoo.com) myListener: QueryInterface({00000000-0000-0000-c000-000000000046}) myListener: QueryInterface : ok aResolve() return see_main() return ======================================================== _______________________________________________ Mozilla-xpcom mailing list [EMAIL PROTECTED] http://mail.mozilla.org/listinfo/mozilla-xpcom


_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to