Note that there are some explanatory texts on larger screens.

plurals
  1. POboost test and async IO : memory access violation at address : no mapping at fault address
    primarykey
    data
    text
    <p>i am trying to setup a boost test for async I/O for tcpip.</p> <p>my function to send tcp msg:</p> <pre><code> int TcpClient::sendMsgToServer(string msg) { if (isConnected == true) { Logger::debug("Asynch send request for msg: " + msg, __LINE__, __FILE__); sendSequence++; msg.append("\r\n"); int length = msg.length() + 2; //+2 is for \r\n char* buffer = (char*) msg.c_str(); Logger::debug(buffer, __LINE__, __FILE__); m_Socket.async_send(boost::asio::buffer(buffer, length), boost::bind(&amp;fingigcc::TcpClient::sendMsgToServerErrorHandler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); std::string sentMsg = "Sent Msg: " + msg; Logger::debug(sentMsg, __LINE__, __FILE__); return 0; } else { return -1; } } void TcpClient::sendMsgToServerErrorHandler( const boost::system::error_code&amp; error, std::size_t bytes_transferred) { Logger::debug("Sending complete: ", __LINE__, __FILE__); sendResponseSequence++; int i = error.value(); std::stringstream ss; ss.clear(); ss &lt;&lt; i; Logger::debug("RESULTCODE: " + ss.str(), __LINE__, __FILE__); if (i == 0) { Logger::debug("RESULT: " + error.message(), __LINE__, __FILE__); } else { Logger::crit(error.message(), __LINE__, __FILE__); m_Socket.close(); isConnected = false; connectionStateChanged(isConnected); } } </code></pre> <p>now this function works fine if i just run it in the main thread ( not running doing a boost test)</p> <p>my boost test function looks like this:</p> <pre><code>BOOST_AUTO_TEST_CASE( CommunicationCore_sendTcpIpMsg_test ) { CommunicationCoreFixture f; int compare = f.c-&gt;initializeTcpIpConnection(serverAddress, serverPort); // i initialize the connection here. runs fine with any issue sleep(2); compare = f.c-&gt;sendMsgToServer("IDENTIFY console-2"); BOOST_MESSAGE("Sending returned value : " &lt;&lt; compare); BOOST_CHECK(compare == 0); } </code></pre> <p>and it fails with the following error:</p> <pre><code> Entering test case "CommunicationCore_sendTcpIpMsg_test" unknown location(0): fatal error in "CommunicationCore_sendTcpIpMsg_test": memory access violation at address: 0x01003255: no mapping at fault address *****************Test is aborted </code></pre> <p>Is there anything i should be aware of while testing such async functions?</p> <p>my build information is:</p> <pre><code>Platform: linux Compiler: GNU C++ version 4.7.2 STL : GNU libstdc++ version 20120920 Boost : 1.49.0 </code></pre> <hr> <p>EDIT:</p> <p>I have tried modifying it in the following manner as well..but still getting the same error:</p> <pre><code>int TcpClient::sendMsgToServer(string msg) { if (isConnected == true) { Logger::debug("Asynch send request for msg: " + msg, __LINE__, __FILE__); sendSequence++; msg.append("\r\n"); char *buffer = new char[msg.size() + 1]; buffer[msg.size()] = 0; memcpy(buffer, msg.c_str(), msg.size()); Logger::debug(buffer, __LINE__, __FILE__); m_Socket.async_send(boost::asio::buffer(buffer, (msg.size() + 1)), boost::bind(&amp;fingigcc::TcpClient::sendMsgToServerErrorHandler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); std::string sentMsg = "Sent Msg: " + msg; Logger::debug(sentMsg, __LINE__, __FILE__); return 0; } else { return -1; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload