Boost C++ Libraries: Ticket #3796: "Unhandled exception" with boost::asio library in vs2010 beta 2 https://svn.boost.org/trac10/ticket/3796 <p> I have a code snipper using boost::asio library, it runs well complied with vs2008, but occurs error compiled with vs2010 beta 2, just like this: "Unhandled exception at 0x012ec084 in SimpleC++.exe: 0xC0000005: Access violation reading location 0x00000000." </p> <p> see code below: </p> <p> #include "stdafx.h" #include &lt;iostream&gt; #include &lt;boost/asio.hpp&gt; #include &lt;boost/array.hpp&gt; #include &lt;string&gt; </p> <p> using namespace std; using boost::asio::ip::tcp; </p> <p> std::string make_header() { </p> <blockquote> <p> std::string str =""; str += "GET / HTTP/1.1\n"; str += "Host: www.google.com\n"; str += "User-Agent: Mozilla/5.0\n"; str += "Accept: */*\n"; str += "Accept-Encoding: gzip,deflate\n"; str += "\n\n"; </p> </blockquote> <blockquote> <p> return str; </p> </blockquote> <p> } </p> <p> int main(int argc, char* argv[]) { </p> <blockquote> <p> boost::asio::io_service io_service; tcp::resolver resolver(io_service); boost::asio::ip::tcp::resolver::query query("www.google.cn", "http"); tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); tcp::resolver::iterator end; </p> </blockquote> <blockquote> <p> tcp::socket socket(io_service); boost::system::error_code error = boost::asio::error::host_not_found; while (error &amp;&amp; endpoint_iterator != end) { </p> <blockquote> <p> socket.close(); </p> <blockquote> <p> socket.connect(*endpoint_iterator, error); </p> </blockquote> </blockquote> <p> } if (error) </p> <blockquote> <p> throw boost::system::system_error(error); </p> </blockquote> </blockquote> <blockquote> <p> std::string message = make_header(); </p> </blockquote> <blockquote> <p> cout &lt;&lt; message &lt;&lt; "\n"; try { </p> <blockquote> <p> size_t len = socket.send(boost::asio::buffer(message)); cout &lt;&lt; "send: " &lt;&lt; len &lt;&lt; "\n"; </p> </blockquote> <p> } catch (std::exception e) { </p> <blockquote> <p> cout &lt;&lt; e.what() &lt;&lt; std::endl; </p> </blockquote> <p> } </p> </blockquote> <p> </p> <blockquote> <p> size_t l = 0; for (;;) { </p> <blockquote> <p> boost::array&lt;char, 256&gt; buf; </p> </blockquote> </blockquote> <p> </p> <blockquote> <blockquote> <p> size_t len = socket.read_some(boost::asio::buffer(buf), error); if (error==boost::asio::error::eof) </p> <blockquote> <p> break; </p> </blockquote> <p> else if (error) </p> <blockquote> <p> throw boost::system::system_error(error); </p> </blockquote> <p> l += len; </p> </blockquote> </blockquote> <p> </p> <blockquote> <blockquote> <p> std::cout.write(buf.data(), len); </p> </blockquote> </blockquote> <blockquote> <p> } std::cout &lt;&lt;std::endl &lt;&lt; l &lt;&lt; " bytes received.\n"; </p> </blockquote> <blockquote> <p> io_service.run(); return 0; </p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3796 Trac 1.4.3 anonymous Fri, 25 Dec 2009 15:11:47 GMT attachment set https://svn.boost.org/trac10/ticket/3796 https://svn.boost.org/trac10/ticket/3796 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">SimpleC++.zip</span> </li> </ul> Ticket chris_kohlhoff Mon, 04 Jan 2010 11:55:18 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/3796#comment:1 https://svn.boost.org/trac10/ticket/3796#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/58669" title="Merge from trunk. ........ r57393 | hkaiser | 2009-11-05 11:26:15 ...">[58669]</a>) Merge from trunk. </p> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/57393" title="Asio: disabled VC workaround for VC2010 beta2 compiler">r57393</a> | hkaiser | 2009-11-05 11:26:15 +1100 (Thu, 05 Nov 2009) | 1 line </p> </blockquote> <p> </p> <blockquote> <p> Asio: disabled VC workaround for VC2010 beta2 compiler. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3796" title="#3796: Bugs: &#34;Unhandled exception&#34; with boost::asio library in vs2010 beta 2 (closed: fixed)">#3796</a>. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/58621" title="Wrap long line. ">r58621</a> | chris_kohlhoff | 2010-01-02 10:04:35 +1100 (Sat, 02 Jan 2010) | 2 lines </p> </blockquote> <p> </p> <blockquote> <p> Wrap long line. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/58624" title="Windows needs the OVERLAPPED structure to be valid until both the ...">r58624</a> | chris_kohlhoff | 2010-01-02 17:09:02 +1100 (Sat, 02 Jan 2010) | 3 lines </p> </blockquote> <p> </p> <blockquote> <p> Windows needs the OVERLAPPED structure to be valid until both the initiating function call has returned and the completion packet has been delivered. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/58625" title="e specific type_traits headers. ">r58625</a> | chris_kohlhoff | 2010-01-02 18:16:41 +1100 (Sat, 02 Jan 2010) | 2 lines </p> </blockquote> <p> </p> <blockquote> <p> Use specific type_traits headers. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/58626" title="Include specific headers in unit tests rather than the convenience ...">r58626</a> | chris_kohlhoff | 2010-01-02 18:18:09 +1100 (Sat, 02 Jan 2010) | 2 lines </p> </blockquote> <p> </p> <blockquote> <p> Include specific headers in unit tests rather than the convenience header asio.hpp. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/58627" title="Use boost::addressof to get the address of handler objects, rather ...">r58627</a> | chris_kohlhoff | 2010-01-02 19:24:12 +1100 (Sat, 02 Jan 2010) | 3 lines </p> </blockquote> <p> </p> <blockquote> <p> Use boost::addressof to get the address of handler objects, rather than applying operator&amp; directly. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2977" title="#2977: Bugs: asio incompatible with boost.phoenix (closed: fixed)">#2977</a>. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/58628" title="Don't block signals while performing system calls, but instead restart ...">r58628</a> | chris_kohlhoff | 2010-01-02 20:48:01 +1100 (Sat, 02 Jan 2010) | 3 lines </p> </blockquote> <p> </p> <blockquote> <p> Don't block signals while performing system calls, but instead restart the calls if they are interrupted. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/58629" title="Ensure that kqueue support is enabled for BSD platforms. Refs #3626. ">r58629</a> | chris_kohlhoff | 2010-01-02 21:20:12 +1100 (Sat, 02 Jan 2010) | 2 lines </p> </blockquote> <p> </p> <blockquote> <p> Ensure that kqueue support is enabled for BSD platforms. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3626" title="#3626: Bugs: kqueue is not used on freebsd (contradicts documentation) (closed: fixed)">#3626</a>. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/58630" title="Add boost_ prefix to extern &#34;C&#34; thread entry point function. Refs #3809. ">r58630</a> | chris_kohlhoff | 2010-01-02 21:30:41 +1100 (Sat, 02 Jan 2010) | 2 lines </p> </blockquote> <p> </p> <blockquote> <p> Add boost_ prefix to extern "C" thread entry point function. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3809" title="#3809: Bugs: global namespace polution (closed: fixed)">#3809</a>. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/58647" title="Use a pool of strand implementations to make copying of strands cheaper. ">r58647</a> | chris_kohlhoff | 2010-01-03 07:36:59 +1100 (Sun, 03 Jan 2010) | 2 lines </p> </blockquote> <p> </p> <blockquote> <p> Use a pool of strand implementations to make copying of strands cheaper. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/58650" title="In getaddrinfo emulation, only check the socket type (SOCK_STREAM or ...">r58650</a> | chris_kohlhoff | 2010-01-03 08:35:33 +1100 (Sun, 03 Jan 2010) | 4 lines </p> </blockquote> <p> </p> <blockquote> <p> In getaddrinfo emulation, only check the socket type (SOCK_STREAM or SOCK_DGRAM) if a service name has been specified. This should allow the emulation to work with raw sockets. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/58651" title="Add a workaround for some broken Windows firewalls that make a socket ...">r58651</a> | chris_kohlhoff | 2010-01-03 08:37:10 +1100 (Sun, 03 Jan 2010) | 3 lines </p> </blockquote> <p> </p> <blockquote> <p> Add a workaround for some broken Windows firewalls that make a socket appear bound to 0.0.0.0 when it is in fact bound to 127.0.0.1. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/58652" title="Only include implementation headers required for each platform. ">r58652</a> | chris_kohlhoff | 2010-01-03 08:38:44 +1100 (Sun, 03 Jan 2010) | 2 lines </p> </blockquote> <p> </p> <blockquote> <p> Only include implementation headers required for each platform. </p> </blockquote> <p> ........ </p> Ticket