unit HttpGetThreads;
interface
uses
Classes,
IdBaseComponent, IdComponent,IdTCPConnection,IdTCPClient, IdHTTP,IdObjs;
//Indy
type
TMyHttpThreads =
class(TThread)
private
IdHTTP: TIdHTTP;
ContentStream:TStringStream;
FURL:
string;
FTerminated:Boolean;
procedure loadComplete;
public
property ActualURL:
String read FURL;
property Terminated:Boolean
read FTerminated;
protected
procedure Execute;
override;
end;
implementation
uses JobQueueMultiThread;
//Main
procedure TMyHttpThreads.Execute;
var loop:Integer;
begin
try
FTerminated:=False;
IdHTTP:=TIdHTTP.Create;
while ((JobQueue.Joblist.Count>0)
and Terminated=false)
do
begin;
FURL:=JobQueue.Joblist.Strings[0];
JobQueue.Joblist.Delete(0);
ContentStream:= TStringStream.Create(toEOF);
try
IdHTTP.Get(FURL,ContentStream);
except
on e:EIdHTTPProtocolException
do
begin
JobQueue.Joblist.Add(FURL);
end;
end;
ContentStream.Seek(0, soFromBeginning);
Synchronize(loadComplete);
ContentStream.Destroy;
end;
finally
FTerminated:=True;
IdHTTP.Destroy;
if Assigned (ContentStream)
then ContentStream.Destroy;
end;
end;
procedure TMyHttpThreads.loadComplete;
begin
JobQueue.ThreadResult(ContentStream);
end;
end.