Francois,
Thank you for your explanation.
To get into more detail... I'm attempting to code something where I download
a file using GetASync() and where I'm able to report *all* errors that might
occur during the download process. However, I'm having some trouble handling
some situations where things go wrong...
Below is a very small piece of code that helps to illustrate the problem...
=====
void HttpComponent::StartDownload(void)
{
HttpCli->OnDocBegin=HttpDocBegin;
HttpCli->OnDocEnd=HttpDocEnd;
HttpCli->OnRequestDone=HttpRequestDone;
HttpCli1->GetASync();
// *** No need for Try{} since exceptions are
// *** triggered in a different context anyway ?
}
=====
void __fastcall HttpComponent::HttpRequestDone
(TObject *Sender, THttpRequest RqType, WORD Error)
{
// *** Not sure what WORD Error actually contains ?
DebugText("Error=%d",Error);
DebugText("StatusCode=%d",HttpCli->StatusCode);
}
=====
void __fastcall HttpComponent::HttpDocBegin(TObject *Sender)
{
HttpCli->RcvdStream=new TFileStream(HttpDestinationFile,fmCreate);
}
=====
void __fastcall HttpComponent::HttpDocEnd(TObject *Sender)
{
delete HttpCli1->ReceivedStream;
}
=====
When everything goes well and HttpRequestDone() is eventually called I get :
Error=0
StatusCode=200 (=OK)
I was wondering what would happen if the writing to the FileStream would
fail for any reason (e.g. no more free space). To simulate such an error I
saved the FileStream to an USB memory stick that did not have sufficient
space on it to contain the downloaded file.
This triggers following exception every time a piece of the downloaded file
is written as soon as I run out of free space on the memory stick :
=> procedure TStream.WriteBuffer : 'Stream write error'
When HttpRequestDone() is eventually called it will report :
Error=0
StatusCode=200 (=OK)
Even though the actual http transfer never encountered a problem (as
confirmed by StatusCode=200) things clearly went wrong when when writing the
received data to the filestream.
I have following questions which I hope someone can clarify :
(1) How can I detect that procedure TStream.WriteBuffer has encountered a
'Stream write error' ? I need to catch this exception so I can abort the
http transfer (HttpCli->Abort()), but haven't got a clue how/where to do
this. Preferably I need a way to communicate this error so that
HttpRequestDone() is able not only to take HttpCli->StatusCode into account,
but also any stream write errors that might have occurred.
(2) I was wondering what the variable WORD Error in HttpRequestDone(TObject
*Sender, THttpRequest RqType, WORD Error) actually means ?
(3) Is it correct to assume that, unlike the synchronous Get, the
GetASync()-call does not need a Try{} since, as you already indicated, these
exceptions are triggered in a different context anyway ?
Thank you,
Kris
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Francois Piette
Sent: dinsdag 28 februari 2006 8:48
To: ICS support mailing
Subject: Re: [twsocket] HttpCli->GetASync() exception
> The httptest1.cpp example for HttpCli has following exception handling...
>
> try {
> HttpCli1->Get();
> } __except (TRUE) {
> DisplayMemo->Lines->Add("GET Failed !");
> DisplayMemo->Lines->Add("StatusCode = " +
> IntToStr(HttpCli1->StatusCode));
> return;
> }
>
> I was wondering if an exception can also occur when using
> HttpCli->GetASync() instead of HttpCli1->Get() ?
> If so, is it possible to give me an example which errors can be
> encountered here when calling GetASync() ?
The same exceptions can occur. But they will be triggered in another context
since it is asynchronous. You can trap them from the
Application->OnException. You can also trap them where ever you call the
message pump (all events are actually subroutines called from the message
pump).
--
Contribute to the SSL Effort. Visit
http://www.overbyte.be/eng/ssl.html
--
[EMAIL PROTECTED]
Author of ICS (Internet Component Suite, freeware) Author of MidWare
(Multi-tier framework, freeware) http://www.overbyte.be
--
To unsubscribe or change your settings for TWSocket mailing list please goto
http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be