Oh, and that's XULRunner 1.9.1 (and no, I can't use 1.9.2)

- Edmond -

On Thu, 26 May 2011 02:57:24 +1000, Edmond Begumisa <[email protected]> wrote:

Hello all,

I'm using nsIInputStreamPump to asynchronously read string data from a socket from JavaScript in my XULRunner application. I've got everything working except one small problem - I can't keep the socket connection opened!

Data streams down fine but when there's nothing there it closes after a few seconds, then I have to re-open. This is regardless of what setting I use for nsISocketTransportService.setTimeout for both TIMEOUT_CONNECT and TIMEOUT_READ_WRITE. Is there another setting somewhere maybe for nsIRequest that configures a separate timeout?

Thanks in advance for any help.

Below is the relevant code...

- Edmond -

(function() {
     ...
     const nsISocketTransportService =
                Cc["@mozilla.org/network/socket-transport-service;1"]
                      .getService(Ci.nsISocketTransportService);

     this.connect = function (aHost, aPort)
     {
         ...

_tpSrv = nsISocketTransportService.createTransport(null, 0, aHost,
                                                           aPort, null);

        //_tpSrv.setTimeout(Ci.nsISocketTransport.TIMEOUT_CONNECT, 0xFFFFFFFF);
//_tpSrv.setTimeout(Ci.nsISocketTransport.TIMEOUT_READ_WRITE, 0xFFFFFFFF);

         _asyncPacketReader = new AsyncPacketReaderUTF8(
                                    _tpSrv.openInputStream(0, 0, 0), // 
Non-Blocking, Buffered
                                    PACKET_END,
                                    that.onPacketArrived);
        ...
    };

...

}).apply(venkLink.client);



AsyncPacketReaderUTF8 = function (aInputStream, aPacketEndStr, oOnPacketArrived)
{
     ...        

     var _isp = Cc["@mozilla.org/network/input-stream-pump;1"]
                 .createInstance(Ci.nsIInputStreamPump);
     _isp.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE;
     _isp.init(aInputStream, -1, -1, 0, 0, false);

     /** @type {nsIStreamListener : nsIRequestObserver} Implementation */
     var _sl = {};
     _sl.onStartRequest = function (request, context) {};
     _sl.onStopRequest = function (request, context, status) {};
_sl.onDataAvailable = function (request, context, inputStream, offset,
                                     count)
     {
         var cis = Cc["@mozilla.org/intl/converter-input-stream;1"]
                         .createInstance(Ci.nsIConverterInputStream);
         var wrapStr = {};
         cis.init(inputStream, "UTF-8", 0, 0);
         cis.readString(count, wrapStr);

         ...
     };

     _isp.asyncRead(_sl, null);

};



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
_______________________________________________
dev-tech-network mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-network

Reply via email to