[ICS HTTPCli] Implémenter un TimeOut dans mon appli
Bonjour à tous,
Est-ce que quelqu'un peut m'aider à implémenter un timeout dans mon appli,
plus précisement me dire :
- Qu'est-ce qu'il faut que j'ajoute ?
- Comment gérer ensuite le TimeOut ?
car je dois le faire dans une appli déjà existante, qui utilise des Threads
et qui crée dynamiquement les HTTP
Voici les bouts de codes que je peux publier, est-ce que cela vous suffit
pour me dire comment ajouter à chaque Http créée un timout dynamique,
c'est à dire qu'il se crée pour chaque TMyHTTP.
Merci à tous pour votre aide
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| // Initialisation
procedure TCHild.InitHttpList(MAX_THREAD : Integer);
var
i : integer;
Http : TMyHttp;
Begin
FHttpList.Clear;
for i:=0 to MAX_THREAD-1 do
begin
Http:=TMyHttp.Create(Self);
Http.Proxy :=Main.ProxyHostName;
Http.ProxyPort :=Main.ProxyPort;
Http.ProxyUsername :=Main.ProxyUserName;
Http.ProxyPassword :=Main.ProxyPassword;
Http.Username :=FSearch.UserAccount;
Http.Password :=FSearch.UserPassword;
Http.OnRequestDone :=HttpRequestDone;
Http.OnDocData :=HttpDocData;
Http.OnLocationChange :=HttpLocationChange;
FHttpList.Add(Http)
end;
End; |
Dans un autre fichier j'ai :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| unit MyHttp_U;
interface
uses
Classes, HttpProt, windows;
const
// Nombre maximum de changement d'url par le champs LOCATION
// (Si infini mettre un nombre inferieur a 0)
DEFAULT_RELOCATION = 3;
type
TMyHttp = class(THttpCli)
private { Déclarations privées }
FTrace: TStringList;
FData: TObject;
FRelocation: Integer;
FOnLocationChange: TNotifyEvent;
procedure DoLocationChange(Sender: TObject);
protected { Déclarations protégées }
property FollowRelocation;
public { Déclarations publiques }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published { Déclarations publiées }
property Relocation: Integer read FRelocation write FRelocation default
DEFAULT_RELOCATION;
property OnLocationChange: TNotifyEvent read FOnLocationChange write
FOnLocationChange;
property Trace: TStringList read FTrace;
property Data: TObject read FData write FData;
end;
implementation
{ TMyHttp }
constructor TMyHttp.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FollowRelocation:=False;
FRelocation:=DEFAULT_RELOCATION;
FTrace:=TStringList.Create;
inherited OnLocationChange:=DoLocationChange;
end; {* cons .Create *}
destructor TMyHttp.Destroy;
begin
FTrace.Free;
inherited Destroy;
end; {* dest .Destroy *}
procedure TMyHttp.DoLocationChange(Sender: TObject);
begin
FTrace.Add(inherited Location);
if (Relocation=0) or (Relocation>0) and (Trace.Count>Relocation) then
Abort;
if Assigned(FOnLocationChange) then
FOnLocationChange(Sender);
end; {* proc .DoLocationChange *}
end. |