Autor Beitrag
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Di 22.03.11 20:43 
Hi!

ich benutze IdHTTP, um eine API abzufragen. Diese nutzt Long Polling, d.h. ein Request bleibt so lange offen bis Daten vorliegen und liefert diese dann quasi-"sofort". Damit das funktioniert, findet das .Get in einem separaten Thread statt. Soweit so gut, aber: mindestens zum Programmende brauche ich eine Möglichkeit, diesen Vorgang schnell abzubrechen. Bis zum Timeout (~30s) zu warten ist hier keine Option.

Gibt es dazu eine Möglichkeit, und wenn ja, wie sieht die aus?
Ich würde mal auf irgendwas mit Silent Exceptions tippen, aber das ist nicht grade schön. Oder muss das bei Indy so? Normalerweise nutze ich die nicht, aber hier muss das aus externen Gründen mal sein.

Danke schonmal,
Martok

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19340
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 22.03.11 21:55 
Du musst eine Exception im OnWork Ereignis auslösen. Nämlich EAbort. Du kannst auch einfach Abort (in der Unit SysUtils) dafür aufrufen.

Der Hintergrund:
Exceptions sind im Indy Projekt (und in manchen meiner Projekte) keine Fehler, sondern Unterbrechungen des normalen Betriebsablaufs. Und genau das willst du ja erreichen.
Martok Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 23.03.11 00:08 
Ah, danke! Auf OnWork bin ich nicht gekommen.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Martok Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 23.03.11 14:47 
Hm, so ganz wars das noch nicht. Dadurch, dass keine Daten kommen gibts auch kein OnWork...

Andere Ideen?

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19340
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 23.03.11 14:53 
Solange der Socket blockiert, kannst du den Vorgang auch nicht abbrechen. Das liegt daran, dass Indy mit Blocking Sockets arbeitet. In diesem Moment wird also kein Code von Indy ausgeführt.
Martok Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 23.03.11 18:03 
Das tolle ist: da blockiert nix, der geht nur in eine Endlosschleife die so lange läuft, bis die Response komplett ist oder die Connection abreißt. Und genau hier kann man ansetzen:
ausblenden Delphi-Quelltext
1:
  http.IOHandler:= nil;					

Vom Hauptthread aus ausgeführt ist das ziemlich riskant, weil man halt direkt in einem Thread rumpfuscht, aber es funktioniert.

Dann trifft in der IdTCPConnection         if Assigned(FRecvBuffer) and Assigned(IOHandler) then begin //APR: disconnect from other thread und man muss dann nur noch die EIdNotConnected-Exception wegfangen.


Deswegen nutze ich lieber ICS, da gibts zwar nicht so viele Komponenten, aber die die da sind lassen sich wenigstens ordentlich bedienen. :roll:

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."

Für diesen Beitrag haben gedankt: BenBE