Article View: borland.public.cppbuilder.internet.socket
Article #2841Re: Problem with HTTP download locking up.
From: Tom
Date: Tue, 24 Jan 2006 02:29
Date: Tue, 24 Jan 2006 02:29
100 lines
5007 bytes
5007 bytes
>> Are you calling Get() in the context of the main thread? If so, then the >> freeze is to be expected. It is if I wasn't calling ProcessMessages() in the OnWork event. I plan on moving all of that work out of the event, it was just a quick conversion from TNMHttp over to TIdHTTP to see if that could correct the problem with it freezing. >> The ContentStream->Position is always at the end of the stream Not true, it updates as the data is received. I'm using this method because of another post by you that says AWorkCount is not accurate if the data is sent in different chunks. From my testing the ContentStream->Size (which is what you said to use in that other post) is set to the same size as the ContentLength. when the transfer is started. The Position updates as that data is received. >> Then your thread code was likely wrong to begin with. It was the same code except it was inside a Tthread. The UpdateStatus function was synchronized for access to the main forms visual controls. DLResult, IsDownloading and Retry all were public variables of the thread. >> That code has a memory leak if either TIdHTTP::Get() or >> TMemoryStream::SaveToFile() fail. Would an auto_ptr take care of that? I'm still looking for a good place to learn about them. Thanks, Tom "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:43d57fba$1@newsgroups.borland.com... > > "Tom" <thomasf1021@hotmail.com> wrote in message > news:43d571a6$1@newsgroups.borland.com... > >> The next file that gets downloaded is 24MB and as soon as the >> Get is called the program freezes solid. > > Are you calling Get() in the context of the main thread? If so, then the > freeze is to be expected. > >> I do have the AntiFreeze component on the form, and on my machine >> that doesn't lock up it functions just fine with being able to move the >> window, click buttons etc without it appearing to be frozen. > > TIdAntiFreeze is not perfect. A better solution would be to move the > downloading into a separate worker thread instead. > >> On his, it's locked up solid, can't move the windows, click the cancel > button, nothing. > > Then TIdHTTP (or something else in your code) has been completely blocked >> to the point where TIdHTTP cannot even call into TIdAntiFreeze at all. > Again, you should move the download into a separate thread. At least that > way, the program will not be frozen even if such a blockage occurs again. > >> I have the OnWork event setup to calculate the current progress >> of the transfer using the Http1->Response->ContentStream->Position >> and the ContentLength variables. > > The ContentStream->Position is always at the end of the stream You should > be using the AWorkCount value that is provided by the OnWork event > instead. > That is the total number of bytes that have been transferred since the > beginning of the transfer. > >> With a Application->ProcessMessages() thrown in to update >> the display. > > TIdAntiFreeze calls ProcessMessages() internally. Or, if you move the > code > into its own thread, then ProcessMessages() is not needed at all. > >> Initially I had it setup in a thread for the downloading with >> synchronize calls for updating the display, but rather than lockup, >> the thread was just dying without any errors being thrown. > > Then your thread code was likely wrong to begin with. Please show what > you > were doing. Also keep in mind that TThread swallows uncaught exceptions, > so > if you want an exception to be reported, you have to catch the exceptions > yourself so that you can respond to them accordingly. > >> bool Download(AnsiString const FileName, AnsiString const FullPath) > > That code has a memory leak if either TIdHTTP::Get() or > TMemoryStream::SaveToFile() fail. You are also doing a lot of processing > inside the OnWork event handler. You might consider streamlining the code > better to reduce the numbr of placesd where errors can occur. > > > Gambit > >
Technical Details
Message-ID:
<43d59052@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!newshub.sdsu.edu!peer01.west.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<43d571a6$1@newsgroups.borland.com> <43d57fba$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,1a95ad1eb7ec8c80 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Tom" <thomasf1021@hotmail.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <43d571a6$1@newsgroups.borland.com> <43d57fba$1@newsgroups.borland.com> Subject: Re: Problem with HTTP download locking up. Date: Mon, 23 Jan 2006 20:29:22 -0600 Lines: 102 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 68.1.78.156 Message-ID: <43d59052@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1138069586 68.1.78.156 (23 Jan 2006 18:26:26 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!newshub.sdsu.edu!peer01.west.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail