Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using WinInet HTTP functions in Full Asynchronous Mode
#1
Can you show me an example to use this in QM?

Quote:To use WinInet functions in full asynchronous mode, you must do things in the right order:

Use INTERNET_FLAG_ASYNC to open the session
Set a status callback using InternetSetStatusCallback
Open the connection using InternetOpenUrl
If InternetOpenUrl returned NULL and GetLastError is ERROR_IO_PENDING:
wait for the INTERNET_STATUS_HANDLE_CREATED notification in the callback, and save the connection Handle.
wait for the INTERNET_STATUS_REQUEST_COMPLETE notification in the callback before going further.
Extract the content-length from the header and set up an INTERNET_BUFFERS structure:
dwStructSize = sizeof(INTERNET_BUFFERS)
lpvBuffer = your allocated buffer
dwBufferLength = its length
Use InternetReadFileEx with the IRF_ASYNC flag to read the remaining data asynchronously. Don�t use InternetReadFile since it is a synchronous function.
If InternetReadFileEx returned False and GetLastError is ERROR_IO_PENDING: wait for the INTERNET_STATUS_REQUEST_COMPLETE notification in the callback before going further.
Warning: INTERNET_BUFFERS members are modified asynchronously (only the dwBufferLength member and the content of the buffer).

If the dwBufferLength member is not 0, move the lpvBuffer pointer from this amount and subtract this amount from the buffer length so dwBufferLength reflects the remaining size lpvBuffer points to, then loop to 6.
Close the connection handle with InternetCloseHandle and wait for INTERNET_STATUS_HANDLE_CLOSING and the facultative INTERNET_STATUS_REQUEST_COMPLETE notification (sent only if an error occurs � like a sudden closed connection -, you must test the cases).
At this state, you can either begin a new connection process or close the session handle. But before closing it, you should un-register the callback function.

from http://www.codeproject.com/KB/IP/asyncwininet.aspx
#2
I don't want to learn how to use wininet functions in async mode because QM is multithreaded program, you can use wininet functions in sync mode in another thread to avoid blocking your thread. Creating and testing Http etc classes was quite much work for me. In async mode it should be even more difficult. When we already have sync functions, and can use multiple threads, i don't want to create another Http class for async mode.
#3
Ok.

Thanks.


Forum Jump:


Users browsing this thread: 2 Guest(s)