You are not logged in.
Assume a record class has a RawUtf8 field which might contain 10MB of string data.
Now the client calls Retrieve() in a background thread to get the record from a remote server.
The question is is there a way to interrupt/abort that http request operation in the middle of the network transfer process? Something like the TIdHttp.OnWork event hanlder, as demonstrated here (https://stackoverflow.com/a/6923250/133516).
Please note I'm not asking about how to terminate my thread, because that thread is waiting for 10MB of data to be downloaded and it cannot respond your 'Terminate' call until the download is completely finished or time out.
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
I haven't tried this but you could just close the HINTERNET Handle from another thread.
https://docs.microsoft.com/en-us/window … losehandle
You would be looking at THttpRequest.InternalCloseRequest implemented in TWinHTTP, TWinINet or TCurlHTTP classes on how to do this.
The documentation warns not to close a synchronized request from another thread but in practice even chromium project was/is using this.
https://chromium.googlesource.com/exter … winhttp.cc
additional info :
https://stackoverflow.com/questions/893 … ed/8939394
Offline
@pvn0,
That's a bunch of helpful info and links you have provided, that gives me the direction for a possible solution for the issue! Thank you very much!
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
In case you use Linux (pthread) there is no problem at all - most of socket related functions is a cancellation points (see "cancellation points" section), so in case you terminate thread read/accept/recv and so on will not block termination. This is one on 100500 things which are made there right..
Last edited by mpv (2019-03-21 12:22:09)
Offline
@mpv,
Both the server and client are on Windows, and with the original post I meant cancelling the sockets on the client side.
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline