Subject: [Boost-bugs] [Boost C++ Libraries] #3796: "Unhandled exception" with boost::asio library in vs2010 beta 2
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-12-25 15:10:52
#3796: "Unhandled exception" with boost::asio library in vs2010 beta 2
-----------------------------------+----------------------------------------
Reporter: sumandeng@⦠| Owner: chris_kohlhoff
Type: Bugs | Status: new
Milestone: Boost 1.42.0 | Component: asio
Version: Boost 1.41.0 | Severity: Problem
Keywords: asio, vs2010 |
-----------------------------------+----------------------------------------
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."
see code below:
#include "stdafx.h"
#include <iostream>
#include <boost/asio.hpp>
#include <boost/array.hpp>
#include <string>
using namespace std;
using boost::asio::ip::tcp;
std::string make_header()
{
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";
return str;
}
int main(int argc, char* argv[])
{
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;
tcp::socket socket(io_service);
boost::system::error_code error = boost::asio::error::host_not_found;
while (error && endpoint_iterator != end)
{
socket.close();
socket.connect(*endpoint_iterator, error);
}
if (error)
throw boost::system::system_error(error);
std::string message = make_header();
cout << message << "\n";
try
{
size_t len = socket.send(boost::asio::buffer(message));
cout << "send: " << len << "\n";
}
catch (std::exception e)
{
cout << e.what() << std::endl;
}
size_t l = 0;
for (;;)
{
boost::array<char, 256> buf;
size_t len = socket.read_some(boost::asio::buffer(buf), error);
if (error==boost::asio::error::eof)
break;
else if (error)
throw boost::system::system_error(error);
l += len;
std::cout.write(buf.data(), len);
}
std::cout <<std::endl << l << " bytes received.\n";
io_service.run();
return 0;
}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/3796> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:02 UTC