Boost logo

Boost :

From: Christopher Kohlhoff (chris_at_[hidden])
Date: 2005-12-16 05:11:25


Turns out the AV only occurs with MSVC 7.1. With VC 8.0 Express I was
able to diagnose the true error: PostQueuedCompletionStatus is failing
with ERROR_NO_SYSTEM_RESOURCES, however I was not checking the return
value. My bad :*)

Here is a diff to fix this (against CVS version of asio). With this
change the test runs successfully to completion.

Cheers,
Chris

----------------------

Index: win_iocp_demuxer_service.hpp
===================================================================
RCS file:
/cvsroot/asio/asio/include/asio/detail/win_iocp_demuxer_service.hpp,v
retrieving revision 1.21
diff -u -r1.21 win_iocp_demuxer_service.hpp
--- win_iocp_demuxer_service.hpp 2 Dec 2005 01:44:56 -0000 1.21
+++ win_iocp_demuxer_service.hpp 16 Dec 2005 10:02:57 -0000
@@ -102,7 +102,12 @@
         if (::InterlockedExchangeAdd(&interrupted_, 0) != 0)
         {
           // Wake up next thread that is blocked on
GetQueuedCompletionStatus.
- ::PostQueuedCompletionStatus(iocp_.handle, 0, 0, 0);
+ if (!::PostQueuedCompletionStatus(iocp_.handle, 0, 0, 0))
+ {
+ DWORD last_error = ::GetLastError();
+ system_exception e("pqcs", last_error);
+ boost::throw_exception(e);
+ }
           break;
         }
       }
@@ -113,7 +118,14 @@
   void interrupt()
   {
     if (::InterlockedExchange(&interrupted_, 1) == 0)
- ::PostQueuedCompletionStatus(iocp_.handle, 0, 0, 0);
+ {
+ if (!::PostQueuedCompletionStatus(iocp_.handle, 0, 0, 0))
+ {
+ DWORD last_error = ::GetLastError();
+ system_exception e("pqcs", last_error);
+ boost::throw_exception(e);
+ }
+ }
   }
 
   // Reset the demuxer in preparation for a subsequent run invocation.
@@ -183,8 +195,15 @@
   template <typename Handler>
   void post(Handler handler)
   {
- win_iocp_operation* op = new handler_operation<Handler>(*this,
handler);
- ::PostQueuedCompletionStatus(iocp_.handle, 0, 0, op);
+ handler_operation<Handler>* op =
+ new handler_operation<Handler>(*this, handler);
+ if (!::PostQueuedCompletionStatus(iocp_.handle, 0, 0, op))
+ {
+ DWORD last_error = ::GetLastError();
+ delete op;
+ system_exception e("pqcs", last_error);
+ boost::throw_exception(e);
+ }
   }
 
 private:


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk