#3796 closed Bugs (fixed)
"Unhandled exception" with boost::asio library in vs2010 beta 2
Reported by: | Owned by: | chris_kohlhoff | |
---|---|---|---|
Milestone: | Boost 1.42.0 | Component: | asio |
Version: | Boost 1.41.0 | Severity: | Problem |
Keywords: | asio, vs2010 | Cc: |
Description
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;
}
Attachments (1)
Change History (2)
by , 13 years ago
Attachment: | SimpleC++.zip added |
---|
comment:1 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In [58669]) Merge from trunk.
........
........
........
........
........
........
........
........
........
........
........
........
........
........