InternetCloseHandle() confusion

Started by
8 comments, last by Teric 18 years, 7 months ago
MSDN:
Quote: If asynchronous requests are pending for the handle or any of its child handles, the handle cannot be closed immediately, but it will be invalidated. Any new requests attempted using the handle will return with an ERROR_INVALID_HANDLE notification. The asynchronous requests will complete with INTERNET_STATUS_REQUEST_COMPLETE. Applications must be prepared to receive any INTERNET_STATUS_REQUEST_COMPLETE indications on the handle before the final INTERNET_STATUS_HANDLE_CLOSING indication is made, which indicates that the handle is completely closed.
I dont' get it. I'm using asyncronous Internet functions and as far as I know I must receive only INTERNET_STATUS_HANDLE_CLOSING when InternetCloseHandle() is executed? Am I right? Thanks.
ai-blog.org: AI is discussed here.
Advertisement
That would be correct, unless there are still actions pending for that particular handle (i.e. you made a call to some function such as InternetOpenUrl() that hasn't completed yet).

If there are still actions pending on a given handle, you could still receive an INTERNET_STATUS_REQUEST_COMPLETE message even after you've called InternetCloseHandle() on that handle.
I am always open to feedback, positive or negative...
Quote:Original post by Teric
That would be correct, unless there are still actions pending for that particular handle (i.e. you made a call to some function such as InternetOpenUrl() that hasn't completed yet).

If there are still actions pending on a given handle, you could still receive an INTERNET_STATUS_REQUEST_COMPLETE message even after you've called InternetCloseHandle() on that handle.


INTERNET_STATUS_HANDLE_CLOSING status code will be received the last. Or I will receive INTERNET_STATUS_HANDLE_CLOSING and then maybe several INTERNET_STATUS_REQUEST_COMPLETE. But I thought that InternetCloseHandle() abortsall pending operations.

The scene is like that:
I'm having asynchronous Internet class w/ timeout cotrol support. When some, e.g. InternetReadFileEx() is timed out I call InternetCloseHandle(). What status code could I retrieve after that?
ai-blog.org: AI is discussed here.
I just want to know what is the last status code sent? Is it INTERNET_STATUS_HANDLE_CLOSING? Am I right?
ai-blog.org: AI is discussed here.
As far as I'm aware, InternetCloseHandle does not cancel any pending actions for that handle. It simply disallows any additional actions on that handle. Once all of those actions are complete, the last message you will receive for that handle is INTERNET_STATUS_HANDLE_CLOSING.
I am always open to feedback, positive or negative...
Quote:Original post by cpp forever
I just want to know what is the last status code sent? Is it INTERNET_STATUS_HANDLE_CLOSING? Am I right?


AS it says on MSDN:

Quote:Applications must be prepared to receive any INTERNET_STATUS_REQUEST_COMPLETE indications on the handle before the final INTERNET_STATUS_HANDLE_CLOSING indication is made, which indicates that the handle is completely closed.


In other words; You might receive any number of INTERNET_STATUS_REQUEST_COMPLETE. But the last status code will be INTERNET_STATUS_HANDLE_CLOSING. This means that the handle is now closed.
Quote:Original post by crudbreeder
Quote:Original post by cpp forever
I just want to know what is the last status code sent? Is it INTERNET_STATUS_HANDLE_CLOSING? Am I right?


AS it says on MSDN:

Quote:Applications must be prepared to receive any INTERNET_STATUS_REQUEST_COMPLETE indications on the handle before the final INTERNET_STATUS_HANDLE_CLOSING indication is made, which indicates that the handle is completely closed.


In other words; You might receive any number of INTERNET_STATUS_REQUEST_COMPLETE. But the last status code will be INTERNET_STATUS_HANDLE_CLOSING. This means that the handle is now closed.


And the next question. I want to implement InternetCloseHandle() timeout in my class. But I don't know ho to unregister a callback function to stop it from receiving status codes. Cos when it will receive a status code and InternetCloseHandle() was timeout and besides the worst - I have deleted the object of my class (then my status callback function will access to my object, pointer of which is passed as context).
ai-blog.org: AI is discussed here.
MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/internetsetstatuscallback.asp

To remove a status callback you simply call InternetSetStatusCallback with NULL as the second argument.

It seems like you can't remove a callback (or change it) while there are operations pending for the handle though.
Quote:Original post by crudbreeder
MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/internetsetstatuscallback.asp

To remove a status callback you simply call InternetSetStatusCallback with NULL as the second argument.

It seems like you can't remove a callback (or change it) while there are operations pending for the handle though.


But I need this. Maybe some ideas of such implementation?
ai-blog.org: AI is discussed here.
From reading the docs, it looks like you can't remove the callback handler until all of the handles are closed. Moreover, an async handle will not close until all pending actions on it have completed. Thus, it appears that you cannot simply interrupt the process and kill it mid-stream (probably because you're dealing with responses from a remote server and you can't interrupt its remote processes and any messages it sends back to you).

If you're trying to 'time out' an internet action, I suggest you keep an internal timer for the timeout, and when that timer has expired, display a 'timed-out' message to the user, but allow the pending remote requests to continue in the background until you get a INTERNET_STATUS_HANDLE_CLOSING message.
I am always open to feedback, positive or negative...

This topic is closed to new replies.

Advertisement