Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OnDataAvailable of nsIStreamListener

31 views
Skip to first unread message

neel...@gmail.com

unread,
Jan 30, 2014, 5:59:45 AM1/30/14
to
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

Boris Zbarsky

unread,
Jan 30, 2014, 12:47:35 PM1/30/14
to
On 1/30/14 2:59 AM, neel...@gmail.com 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
0 new messages