I think, the documentation is not correct (or complete) for all cases!
With asynchronous call of ReceiveHTTPFile
FinishHTTP should be used as follows:
... When using #PB_HTTP_Asynchronous, FinishHTTP() needs to be called when the download is finished (successfully or not). ...
This means that you have to use HTTProgress to determine the state of the download and only if Progress is Success, Failed OR Aborted, than you should use HTTPFinish.
But with asynchrous call of HTTPRequest
the documentation says:
... FinishHTTP() has to be always called to finish a successfully initialized HTTP request, even if the call was synchronous. ...
... this is not clear for me!
(1) with synchronous call a HTTP request only returns non-zero (== sucessfully initizialized) if the download itself was finished otherwise it returns zero!
(2) with asynchronous call a HTTP request retruns non-zero if the download has started succesfully.
Therfore I do not know what the quoted sentence "FinishHTTP() has to be always called to finish a successfully initialized HTTP request, even if the call was synchronous.
" really mean.
that all four asynchronous HTTP requests (HTTPRequest, HTTPRequestMemory, ReceiveHTTPFile, ReceiveHTTPMemory) share the same code base.
Therfore based on my assumptions for asynchronous HTTP requests I suggest
- Always check the return value of all HTTP request calls!
- Never use FinishHTTP() to abort a running asynchronous HTTP request!
- Only use FinishHTTP() if HTTPProgress returned #PB_Http_Sucess, #PB_Http_Failed or #PB_Http_Abort.
- If you need to call HTTPInfo or HTTPMemory, only do this before the call of HTTPFinish.
These rules work for me and I do not get the errors caused by your examples.
A more detailed and complete documetation of HTTP library would be fine!