Re: [asio-users] Summary: Cancelation not working on windows
Brought to you by:
chris_kohlhoff
From: Thomas R. <tho...@it...> - 2008-02-26 11:32:11
|
Hi. I've got some strange possibly related problem. Although I am calling socket.close() already on my open TCP connection. The problem is that my outstanding handlers are still not called and therefore my object is not destroyed and my app hangs in a loop which tries to make sure all connections are closed.. Any ideas? P.S.: I even tried defining ASIO_DISABLE_IOCP in my (vs 2005) project) -----Original Message----- From: asi...@li... [mailto:asi...@li...] On Behalf Of Christopher Kohlhoff Sent: Dienstag, 19. Februar 2008 00:41 To: asi...@li... Subject: Re: [asio-users] Summary: Cancelation not working on windows Roland Schwarz wrote: > Today I tried to investigate what really is preventing CancelIo to > work on my windows xp box. This is what I found: ... Thanks for the info -- very interesting indeed. > I suggest defining a semantic for cancel that can be guaranteed > irrespective of user configuration of the network stack. (e.g. > closesocket) The cancel() function can't be implemented in terms of closesocket(), as that would give it destructive semantics. One can already use the socket object's close() function to portably achieve that result anyway. I also have to consider the fact that some people are using this function successfully, albeit in constrained scenarios. E.g. it might be ok to use it in an application destined for in-house use, where you have complete control over the environment in which it runs. On the other hand, I now wouldn't recommend using it in a shrinkwrapped application, given what you've discovered. So here's what I propose to do: - By default, use of CancelIo will be disabled. Calls to cancel() on XP and earlier will return the error operation_not_supported. - Use of CancelIo may be enabled by defining ASIO_ENABLE_CANCELIO. Defining this macro will be equivalent to having read and accepted the "terms of conditions" of using CancelIo. - Add a big, scary note to the documentation for cancel() along the lines of: ------------- * @note Calls to cancel() will always fail with * asio::error::operation_not_supported when run on Windows XP, * Windows Server 2003, and earlier versions of Windows, unless * ASIO_ENABLE_CANCELIO is defined. However, the CancelIo function * has two issues that should be considered before enabling its * use: * * @li It will only cancel asynchronous operations that were * initiated in the current thread. * * @li It can appear to complete without error, but the request to * cancel the unfinished operations may be silently ignored by the * operating system. Whether it works or not seems to depend on * the drivers that are installed. * * For portable cancellation, consider using one of the following * alternatives: * * @li Disable asio's I/O completion port backend by defining * ASIO_DISABLE_IOCP. * * @li Use the close() function to simultaneously cancel the * outstanding operations and close the socket. * * When running on Windows Vista, Windows Server 2008, and later, * the CancelIoEx function is always used. This function does not * have the problems described above. ------------- An alternative approach, that I might consider using in the future, would be to adapt your latest cancellation test code to become a runtime test performed by asio at program startup. If the cancellation test succeeds, then it uses CancelIo(). If it fails, it forces cancel() to return an error. Cheers, Chris ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ asio-users mailing list asi...@li... https://lists.sourceforge.net/lists/listinfo/asio-users |