I am writing a program that, among other things, should download a file with its URL. I'm too lazy to implement the Http / Https protocols manually, so I needed a library / object / function that will do the job.
Critical requirement . Download should be asynchronous. That is, the thread that issues the download should be able to do something else “bye” while downloading the file, as well as download it at any time without any barbaric side effects (for example, an internal call TerminateThread).
Good requirements:
- Must be able to load the file into memory. Means - read the contents of the file as they become available, do not necessarily save it in the file system file.
- It would be nice to have a convenient Win32 event notification mechanism (expected event, semahpore, completion port, etc.), and not just periodically check the download status.
I selected a COM object XmlHttpRequestto do this work. It seemed to work quite well, plus it supported asynchronous mode.
However, I noticed that after a while it just stops working. That is, after several successful file downloads, it stops downloading anything.
I periodically interviewed him to get his status, he reports "incomplete", but nothing actually happens, and there is no network activity. Moreover, when the same process creates another instance of the object XmlHttpRequestto perform new downloads, the effect is the same. The object reports "in progress", while it does not even try to connect to the server (in accordance with network sniffers and the system TCP state).
The only way to return this object is to restart the process. This makes me suspect that there is some kind of error in the object (sorry, I mean an undocumented function). Also, this is not an error at the level of an individual object, since the problem persists when the object is destroyed and another is created. This is probably some kind of global state of the DLL that implements this object.
- - ? ?
, , , - , XmlHttpRequest. , , .
BTW, , API MsgWaitXXXX. (, WSAAsyncSelect) - .