OnDataAvailable of nsIStreamListener

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

OnDataAvailable of nsIStreamListener

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-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: OnDataAvailable of nsIStreamListener

Boris Zbarsky
On 1/30/14 2:59 AM, [hidden email] wrote:
> Can anyone tell me how OnDataAvailable() should call first and then main thread will continue ?

Your main thread needs to spin the XPCOM event loop until it gets
OnStopRequest.

-Boris
_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Loading...