nsIStreamListener call

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

nsIStreamListener call

neel5481
Hi All,

As we have called AsyncOpen() method to open the channel and get the data from the channel and added nsIStreamListener to that.

When the data is available then OnDataAvailable() callback will be called and we will read the data from the channel and mail thread continue to process as per the data available.

Below is the code.

class nsStreamListener : public nsIStreamListener
{
public:
        NS_DECL_ISUPPORTS
        //NS_DECL_NSISTREAMLISTENER
        //NS_DECL_NSIREQUESTOBSERVER

        nsresult OnStartRequest(nsIRequest *req, nsISupports *ctx)
        {
       
                printf ("######### START REQUEST #######\n");
        }
        nsresult OnStopRequest(nsIRequest*, nsISupports*, nsresult)
        {
               
                printf ("######### STOP REQUEST #######\n");
        }

        NS_IMETHOD OnDataAvailable(nsIRequest *request, nsISupports *contxt, nsIInputStream *input_stream, PRUint32 offset, PRUint32 count)
        {
        }

}
int main()

{
  ......
  ......

  nsIStreamListener *listener;
  listener = new nsStreamListener();

        rv = channel->AsyncOpen(listener, nsnull);
        if (NS_FAILED(rv))
        {
                wxLogError(_("Failed to open async: %x"), rv);
                return NULL;
        }

       return 0;

}



Here we are able to get the data from the channel. but here the issue is out application exist and after that callback OnDataAvailable is getting called. So we are not able to get the data.

If we put sleep before "return 0" then also callback is getting called after the main application exits.

Can anyone tell me how OnDataAvailable() should call first and then main thread will continue ?

Thanks in Advance
_______________________________________________
dev-tech-xul mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xul
Reply | Threaded
Open this post in threaded view
|

Re: nsIStreamListener call

Neil-4
[hidden email] wrote:

>When the data is available then OnDataAvailable() callback will be called and we will read the data from the channel and main thread continue to process as per the data available.
>
Callbacks don't work like that.

All Gecko threads run an event loop. In the case of the UI thread this
thread processes native UI events. Other threads only process Gecko
events, known as runnables.

Once you call AsyncOpen you need to return to your calling event loop.
At some point a runnable will be posted to the loop which will trigger
the OnDataAvailable call.

--
Warning: May contain traces of nuts.
_______________________________________________
dev-tech-xul mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xul