Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5942249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:13:34+00:00 2026-05-22T16:13:34+00:00

bool Connection::Receive(){ boost::shared_ptr<std::string> buffer(new std::string()); socket_.async_receive(boost::asio::buffer(*buffer), boost::bind(&Connection::handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); //std::cout<<buffer<<std::endl; int recvlen =

  • 0
bool Connection::Receive(){
    boost::shared_ptr<std::string> buffer(new std::string());

    socket_.async_receive(boost::asio::buffer(*buffer), boost::bind(&Connection::handler, this, 
        boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));

    //std::cout<<buffer<<std::endl;

    int recvlen = buffer->length();
    if (recvlen <= 0) {
        return false;
    }
    //this->OnReceived(buffer, recvlen);
    return true;
}

Error:

Error   1   error C2440: '<function-style-cast>' : cannot convert from 'const boost::asio::const_buffers_1' to 'boost::asio::mutable_buffer'    e:\boost_1_46_1\boost_1_46_1\boost\asio\detail\buffer_sequence_adapter.hpp  211
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:13:35+00:00Added an answer on May 22, 2026 at 4:13 pm

    The async_receive function need to change the content of the buffer, but you can’t change a constant buffer.

    Use a mutable_buffer instead of a constant buffer. You can find some informations here

    You need to pass a pointer and the size to the mutable buffer:

    std::vector<char> content_buffer(max_buffer_size);
    
    ... boost::asio::mutable_buffer(content.data(), content.size()) ...
    

    It’s important that you declare your content_buffer in a global scope, bacause the async_receive function is accessing the buffer async. If you declare your buffer in the function, it go out of scope before data get received.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

bool Connection::Receive(){ std::vector<uint8_t> buf(1000); boost::asio::async_read(socket_,boost::asio::buffer(buf,1000), boost::bind(&Connection::handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); int rcvlen=buf.size(); ByteBuffer b((std::shared_ptr<uint8_t>)buf.data(),rcvlen); if(rcvlen
class Connection { public: typedef boost::shared_ptr<Connection> pointer; static pointer create(boost::asio::io_service& io_service){return pointer(new Connection(io_service));} explicit
bool isValid = false; string username = someadmin; If( !String.IsNullOrEmpty(username) && !( username.IndexOf(admin) !=
Sometimes boost::asio seems to disconnect before I want it to, i.e. before the server
I wrote a small tcp client using boost::asio, providing the following function: typedef boost::function<void(const
I am attempting to convert the return value of the function boost::asio::async_read to an
If I where to have a Queue holding a collection of objects (Custom object,bool,bool,bool,bool)
bool operator()(Iterator it1, Iterator it2) const { return (*it1 < *it2); } Can someone
- (BOOL) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { CocosNode* spHead = [self getChildByTag:tagHead]; CocosNode* spBody
bool is_something_ok(int param,SomeStruct* p) { bool is_ok = false; // check if is_ok if(is_ok)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.