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

  • SEARCH
  • Home
  • 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 7596809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:00:40+00:00 2026-05-30T22:00:40+00:00

I use boost::asio as a network framework. As a read/write medium it uses boost::asio::streambuf

  • 0

I use boost::asio as a network framework. As a read/write medium it uses boost::asio::streambuf. I want to:

  • read some message in one buffer
  • append second buffer at the beginning of the first one
  • send new composite message

What are the possible efficient (zero-copy) options to do this?

  • 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-30T22:00:41+00:00Added an answer on May 30, 2026 at 10:00 pm

    The principle is called scatter/gather IO. Basically a way of transmitting multiple buffers at once (in order), without expensive memory-copying. It is well supported under boost::asio with the very flexible and powerful, (but also difficult to grasp) buffers-concept, and buffer-sequence concept.

    A simple (untested, but I believe correct) example to get you started, would be:

    std::vector<boost::asio::streambuf::const_buffers_type> buffers;
    buffers.push_back( my_first_streambuf.data() );
    buffers.push_back( my_second_streambuf.data() );
    
    std::size_t length = boost::asio::write( mySocket, buffers );
    

    Of course, one simple option would be to just read both messages into the streambuf and simply sending the entire streambuf, but from your question I’m guessing it’s not an option for some reason?

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

Sidebar

Related Questions

I am attempting to use boost::asio to read and write from a device on
I'm writing server using boost.asio. I have read and write buffer for each connection
I use boost::asio::buffer to send a message using void Send(const std::string& messageData) { socket.async_write(boost::asio::buffer(messageData),
When using a boost::asio::ip::tcp:socket there are many methods one can use to write/send data.
I use boost::asio::read (or may be the equivalent async_read ) to read some data
I want to use boost::asio but I don't want boost to throw exceptions, because
I have the following code in ANSII: boost::asio::streambuf buffer; std::ostream oss(&buffer); boost::asio::async_write(socket_, buffer, strand_.wrap(
I want to use Boost core libraries (like lambda) and Boost ASIO library in
I have some socket connection code that makes use of boost::asio which reads from
I am trying to adapt one of the boost::asio examples to use c++11 /

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.