Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#3796 closed Bugs (fixed)

"Unhandled exception" with boost::asio library in vs2010 beta 2

Reported by: sumandeng@… 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)

SimpleC++.zip (40.2 KB ) - added by anonymous 13 years ago.

Download all attachments as: .zip

Change History (2)

by anonymous, 13 years ago

Attachment: SimpleC++.zip added

comment:1 by chris_kohlhoff, 13 years ago

Resolution: fixed
Status: newclosed

(In [58669]) Merge from trunk.

........

r57393 | hkaiser | 2009-11-05 11:26:15 +1100 (Thu, 05 Nov 2009) | 1 line

Asio: disabled VC workaround for VC2010 beta2 compiler. Fixes #3796.

........

r58621 | chris_kohlhoff | 2010-01-02 10:04:35 +1100 (Sat, 02 Jan 2010) | 2 lines

Wrap long line.

........

r58624 | chris_kohlhoff | 2010-01-02 17:09:02 +1100 (Sat, 02 Jan 2010) | 3 lines

Windows needs the OVERLAPPED structure to be valid until both the initiating function call has returned and the completion packet has been delivered.

........

r58625 | chris_kohlhoff | 2010-01-02 18:16:41 +1100 (Sat, 02 Jan 2010) | 2 lines

Use specific type_traits headers.

........

r58626 | chris_kohlhoff | 2010-01-02 18:18:09 +1100 (Sat, 02 Jan 2010) | 2 lines

Include specific headers in unit tests rather than the convenience header asio.hpp.

........

r58627 | chris_kohlhoff | 2010-01-02 19:24:12 +1100 (Sat, 02 Jan 2010) | 3 lines

Use boost::addressof to get the address of handler objects, rather than applying operator& directly. Fixes #2977.

........

r58628 | chris_kohlhoff | 2010-01-02 20:48:01 +1100 (Sat, 02 Jan 2010) | 3 lines

Don't block signals while performing system calls, but instead restart the calls if they are interrupted.

........

r58629 | chris_kohlhoff | 2010-01-02 21:20:12 +1100 (Sat, 02 Jan 2010) | 2 lines

Ensure that kqueue support is enabled for BSD platforms. Fixes #3626.

........

r58630 | chris_kohlhoff | 2010-01-02 21:30:41 +1100 (Sat, 02 Jan 2010) | 2 lines

Add boost_ prefix to extern "C" thread entry point function. Fixes #3809.

........

r58647 | chris_kohlhoff | 2010-01-03 07:36:59 +1100 (Sun, 03 Jan 2010) | 2 lines

Use a pool of strand implementations to make copying of strands cheaper.

........

r58650 | chris_kohlhoff | 2010-01-03 08:35:33 +1100 (Sun, 03 Jan 2010) | 4 lines

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.

........

r58651 | chris_kohlhoff | 2010-01-03 08:37:10 +1100 (Sun, 03 Jan 2010) | 3 lines

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.

........

r58652 | chris_kohlhoff | 2010-01-03 08:38:44 +1100 (Sun, 03 Jan 2010) | 2 lines

Only include implementation headers required for each platform.

........

Note: See TracTickets for help on using tickets.