Discussion:
Abort Inet function from another thread
(too old to reply)
n***@sneakemail.com
2007-07-26 21:44:39 UTC
Permalink
I have an app that is acting as an FTP client. I have a thread that
is doing the ftp work and another that is monitoring
a socket for commands. When the ftp thread is in the middle of an
FTP command (such as a large download) is
there a way to abort the connection from the command thread?

If so, how?

Thanks.
Vladimir Scherbina [MVP]
2007-07-27 16:04:31 UTC
Permalink
You may (theoretically) terminate the thread, but this approach might cause
unexpected behaviour of wininet, + quite possible that thread data would not
be released. I think the solution for you is to implement this functionality
in async mode. Once you need to calcel the operation, just signal the asyn
handler about it.
--
Vladimir, Windows SDK MVP
http://msmvps.com/blogs/v_scherbina/
Post by n***@sneakemail.com
I have an app that is acting as an FTP client. I have a thread that
is doing the ftp work and another that is monitoring
a socket for commands. When the ftp thread is in the middle of an
FTP command (such as a large download) is
there a way to abort the connection from the command thread?
If so, how?
Thanks.
n***@sneakemail.com
2007-07-27 17:02:23 UTC
Permalink
On Jul 27, 12:04 pm, "Vladimir Scherbina [MVP]"
Post by Vladimir Scherbina [MVP]
You may (theoretically) terminate the thread, but this approach might cause
unexpected behaviour of wininet, + quite possible that thread data would not
be released. I think the solution for you is to implement this functionality
in async mode. Once you need to calcel the operation, just signal the asyn
handler about it.
--
Post by n***@sneakemail.com
I have an app that is acting as an FTP client. I have a thread that
is doing the ftp work and another that is monitoring
a socket for commands. When the ftp thread is in the middle of an
FTP command (such as a large download) is
there a way to abort the connection from the command thread?
If so, how?
Thanks.
Thanks for the reply. I did a google search for inet async mode but
can decipher what is relevant to your response. Can you give me a bit
more direction?

Thanks.
n***@sneakemail.com
2007-07-27 20:20:00 UTC
Permalink
On Jul 27, 12:04 pm, "Vladimir Scherbina [MVP]"
Post by Vladimir Scherbina [MVP]
You may (theoretically) terminate the thread, but this approach might cause
unexpected behaviour of wininet, + quite possible that thread data would not
be released. I think the solution for you is to implement this functionality
in async mode. Once you need to calcel the operation, just signal the asyn
handler about it.
--
I found information on inet async mode but nothing on the async
handler. Can you elaborate?

Thanks
Vladimir Scherbina [MVP]
2007-07-28 23:24:56 UTC
Permalink
I mean the INTERNET_STATUS_CALLBACK which is passed to
InternetSetStatusCallback.

P.S. Take a look at
http://www.codeproject.com/internet/asyncwininet.asp?df=100&forumid=1409&exp=0&select=403859
--
Vladimir, Windows SDK MVP
http://msmvps.com/blogs/v_scherbina/
Post by n***@sneakemail.com
On Jul 27, 12:04 pm, "Vladimir Scherbina [MVP]"
Post by Vladimir Scherbina [MVP]
You may (theoretically) terminate the thread, but this approach might cause
unexpected behaviour of wininet, + quite possible that thread data would not
be released. I think the solution for you is to implement this functionality
in async mode. Once you need to calcel the operation, just signal the asyn
handler about it.
--
I found information on inet async mode but nothing on the async
handler. Can you elaborate?
Thanks
Paul Baker [MVP, Windows - SDK]
2007-07-30 14:11:21 UTC
Permalink
What I do is perform internet operations synchronously in a separate thread
and abort it from the controlling thread using InternetCloseHandle. This
will in most cases immediately terminate any call that is using the handle
closed.

Paul
Post by Vladimir Scherbina [MVP]
I mean the INTERNET_STATUS_CALLBACK which is passed to
InternetSetStatusCallback.
P.S. Take a look at
http://www.codeproject.com/internet/asyncwininet.asp?df=100&forumid=1409&exp=0&select=403859
--
Vladimir, Windows SDK MVP
http://msmvps.com/blogs/v_scherbina/
Post by n***@sneakemail.com
On Jul 27, 12:04 pm, "Vladimir Scherbina [MVP]"
Post by Vladimir Scherbina [MVP]
You may (theoretically) terminate the thread, but this approach might cause
unexpected behaviour of wininet, + quite possible that thread data would not
be released. I think the solution for you is to implement this functionality
in async mode. Once you need to calcel the operation, just signal the asyn
handler about it.
--
I found information on inet async mode but nothing on the async
handler. Can you elaborate?
Thanks
n***@sneakemail.com
2007-08-01 21:00:53 UTC
Permalink
On Jul 30, 10:11 am, "Paul Baker [MVP, Windows - SDK]"
Post by Paul Baker [MVP, Windows - SDK]
What I do is perform internet operations synchronously in a separate thread
and abort it from the controlling thread using InternetCloseHandle. This
will in most cases immediately terminate any call that is using the handle
closed.
Paul
Paul,

Do you close the handle from InternetOpen() or InternetConnect() ?

Thanks.
Vladimir Scherbina [MVP]
2007-08-01 23:12:29 UTC
Permalink
If you want to cancel the session, then it's better to close handle returned
from InternetConnect. However, I suggest not to follow this approach,
because in rear cases the call is still blocking, and noone knows why ;). I
saw a long time ago MS example saying that this approach is also possible,
however I strongly recommend to follow async way.
--
Vladimir, Windows SDK MVP
http://msmvps.com/blogs/v_scherbina/
Post by n***@sneakemail.com
On Jul 30, 10:11 am, "Paul Baker [MVP, Windows - SDK]"
Post by Paul Baker [MVP, Windows - SDK]
What I do is perform internet operations synchronously in a separate thread
and abort it from the controlling thread using InternetCloseHandle. This
will in most cases immediately terminate any call that is using the handle
closed.
Paul
Paul,
Do you close the handle from InternetOpen() or InternetConnect() ?
Thanks.
Loading...