TB: async listener: onStopRequest called, when data not yet complete - Mozilla
This is a discussion on TB: async listener: onStopRequest called, when data not yet complete - Mozilla ; Hello,
I'm reading the body of an email asynchronously, which works fine for
smaller emails. I'm using the solution from here:
http://groups.google.com/group/mozil...059ab9fe94dfc#
to get the finaldata. However with emails with big attachments it
didn't read out everything. The finaldata is ...
-
TB: async listener: onStopRequest called, when data not yet complete
Hello,
I'm reading the body of an email asynchronously, which works fine for
smaller emails. I'm using the solution from here:
http://groups.google.com/group/mozil...059ab9fe94dfc#
to get the finaldata. However with emails with big attachments it
didn't read out everything. The finaldata is missing the last part
then. Here how it is:
{
...
if (msg_stream._finaldata){
export_email(msg_stream._finaldata, msg_stream._email,
msg_stream._session);
}else{
msg_stream._callback = export_email;
}
}
//msg_stream is of type async_stream
async_stream = function(){
var listener = {
_first: true,
_data: null,
_callback: null,
_finaldata: null,
_email: null,
_session: null,
QueryInterface : function(iid){
...
},
onStartRequest : function(aRequest, aContext){
...
},
onStopRequest : function(aRequest, aContext, aStatusCode)
{
this._finaldata = this._data;
log(this._finaldata);
if (this._callback){
this._callback
(this._finaldata,this._email,this._session);
}
},
onDataAvailable : function (aRequest, aContext,
aInputStream, aOffset, aCount){
var bin_input_stream = Components.classes["@mozilla.org/
binaryinputstream;1"].createInstance
(Components.interfaces.nsIBinaryInputStream);
bin_input_stream.setInputStream(aInputStream);
if(this._first){
this._data = bin_input_stream.readBytes(bin_input_stream.availa ble
());
this._first = false;
}else{
this._data += bin_input_stream.readBytes
(bin_input_stream.available());
bin_input_stream.close();
}
},
};
return listener;
}
I looked on how long the finaldata is, when it's in onStopRequest and
it is exactly 131072 long. I tried it with 3 different mails and it
was always the same length. Why does it stop at 131072?? Or is that
just accidental?
At http://groups.google.com/group/mozil...66215ef5016d02
someone said "That function is called once all the data from the
connection has been sent to the listener." Does that mean that, if
onDataAvailable is finished and not called again, then onStopRequest
is called? That's how I thought the listener works so far, but now I'm
not so sure anymore...
Any links/explanations/suggestions are greatly appreciated.
Greetings,
Serratia
-
Re: TB: async listener: onStopRequest called, when data not yetcomplete
On 8 Apr., 15:52, "Red_Serra...@hotmail.de"
wrote:
> Hello,
> I'm reading the body of an email asynchronously, which works fine for
> smaller emails. I'm using the solution from here:http://groups.google.com/group/mozil...rowse_thread/t...
> to get the finaldata. However with emails with big attachments it
> didn't read out everything. The finaldata is missing the last part
> then. Here how it is:
> {
> * * * *...
> * * * *if (msg_stream._finaldata){
> * * * * * * * *export_email(msg_stream._finaldata, msg_stream._email,
> msg_stream._session);
> * * * *}else{
> * * * * * * * *msg_stream._callback = export_email;
> * * * *}
>
> }
>
> //msg_stream is of type async_stream
> async_stream = function(){
> * * * var listener = {
> * * * * * * * * * * * * _first: true,
> * * * * * * * * * * * * _data: null,
> * * * * * * * * * * * * _callback: null,
> * * * * * * * * * * * * _finaldata: null,
> * * * * * * * * * * * * _email: null,
> * * * * * * * * * * * * _session: null,
>
> * * * * * * QueryInterface : function(iid){
> * * * * * * * * ...
> * * * * * * },
>
> * * * * * * onStartRequest : function(aRequest, aContext){
> * * * * * * * * ...
> * * * * * * },
>
> * * * * * * onStopRequest : function(aRequest, aContext, aStatusCode)
> {
> * * * * * * * * * * * * this._finaldata = this._data;
> * * * * * * * * * * * *log(this._finaldata);
> * * * * * * * * * * * * if (this._callback){
> * * * * * * * * * * * * * * * * this._callback
> (this._finaldata,this._email,this._session);
> * * * * * * * * * * * * }
> * * * * * * },
>
> * * * * * * onDataAvailable : function (aRequest, aContext,
> aInputStream, aOffset, aCount){
> * * * * * * * * * * * * * * * * var bin_input_stream = Components.classes["@mozilla.org/
> binaryinputstream;1"].createInstance
> (Components.interfaces.nsIBinaryInputStream);
> * * * * * * * * * * * * * * * * bin_input_stream.setInputStream(aInputStream);
> * * * * * * * * * * * * * * * * if(this._first){
> * * * * * * * * * * * * * * * * * * * * this._data = bin_input_stream.readBytes(bin_input_stream.availa ble
> ());
> * * * * * * * * * * * * * * * * * * * * this._first = false;
> * * * * * * * * * * * * * * * * }else{
> * * * * * * * * * * * * * * * * * * * * this._data += bin_input_stream.readBytes
> (bin_input_stream.available());
> * * * * * * * * * * * * * * * * * * * * bin_input_stream.close();
> * * * * * * * * * * * * * * * * }
> * * * * * * * * * * * * },
> * * * * * * * * };
> * * * * * * * * return listener;
>
> }
>
> I looked on how long the finaldata is, when it's in onStopRequest and
> it is exactly 131072 long. I tried it with 3 different mails and it
> was always the same length. Why does it stop at 131072?? Or is that
> just accidental?
>
> Athttp://groups.google.com/group/mozilla.dev.tech.network/browse_thread....
> someone said "That function is called once all the data from the
> connection has been sent to the listener." Does that mean that, if
> onDataAvailable is finished and not called again, then onStopRequest
> is called? That's how I thought the listener works so far, but now I'm
> not so sure anymore...
>
> Any links/explanations/suggestions are greatly appreciated.
>
> Greetings,
> Serratia
BTW: reason for stopping (aka aStatusCode in OnStopRequest) was always
0, regardless whether all was read or end was missing.
Also in one email which had 5 pdfs as attachments, after the whole
process of reading/etc. the attachments have disappeared. Since if the
reading is done synchronously this emails works fine, it has to do
something with the asynchronous reading. Not sure what though...