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 6677725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:09:25+00:00 2026-05-26T04:09:25+00:00

async_read_until expects a basic_streambuf into which the data will be read. I don’t want

  • 0

async_read_until expects a basic_streambuf into which the data will be read. I don’t want to allocate additional memory, but using a memory address (from a specified interface that I’m not allowed to change) as the target buffer.

Is it possible to create a streambuf with an external memory address or do I need to write a wrapper-class?

  • 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-26T04:09:25+00:00Added an answer on May 26, 2026 at 4:09 am

    Finally solved the issue by writing my own async_read_until_delim class which expects a memory-pointer and a maximum value of bytes to read. It’s as close as possible to the original boost implementation, but has a few adjustments which should lead to a more performant execution.

    namespace {
    
    template<typename read_handler>
    class async_read_until_delim
    {
    public:
        async_read_until_delim(tcp::socket& socket, void* buffer, std::size_t max_read_size_in_bytes,
            char delim, read_handler& handler)
                : m_socket(socket), m_cur(static_cast<char*>(buffer)),
                  m_end(static_cast<char*>(buffer) + max_read_size_in_bytes), m_delim(delim),
                  m_handler(handler), m_pos(0)
            {
                read_some();
            }
        async_read_until_delim(async_read_until_delim const& other)
            : m_socket(other.m_socket), m_cur(other.m_cur), m_end(other.m_end), m_delim(other.m_delim),
              m_handler(other.m_handler), m_pos(other.m_pos)
            {
            }
    
        void operator()(boost::system::error_code const& error, std::size_t bytes_transferred)
            {
                if (!error)
                {    
                    if (std::find(m_cur, m_end, m_delim) != m_end)
                    {
                        m_handler(error, m_pos + bytes_transferred);
                        return;
                    }
                    else if (m_cur == m_end)
                    {
                        m_handler(boost::asio::error::not_found, -1);
                        return;
                    }
    
                    m_cur += bytes_transferred;
                    m_pos += bytes_transferred;
    
                    read_some();
                }
                else
                    m_handler(error, m_pos);
            }
    
    private:
        void read_some()
            {
                m_socket.async_read_some(
                    boost::asio::buffer(m_cur, m_end - m_cur), async_read_until_delim(*this));
            }
    
        tcp::socket&  m_socket;
        char         *m_cur,
                     *m_end;
        char          m_delim;
        read_handler  m_handler;
        std::size_t   m_pos;
    };
    
    template<typename read_handler>
    inline void do_async_read_until_delim(tcp::socket& socket, void* buffer, std::size_t max_read_size_in_bytes,
        char delim, read_handler& handler)
    {
        async_read_until_delim<read_handler>(socket, buffer, max_read_size_in_bytes, delim, handler);
    }
    
    } /* anonymous namespace */
    

    So, I hope it will be usefull for someone too.

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

Sidebar

Related Questions

I have an app in which I read some gps data and I display
I need to read from NetworkStream which would send data randomly and the size
I'm trying to implement a pattern I read from Don Syme's blog ( https://blogs.msdn.microsoft.com/dsyme/2010/01/09/async-and-parallel-design-patterns-in-f-parallelizing-cpu-and-io-computations/
Suppose you want to make an async request in JavaScript, but you want to
If am am calling boost::asio::async_write/async_read directly after each other, will the data be ordered?
I am using a Socket to receive data via TCP, and TextReader.ReadLine to read
I have a multipart mail which is processed using async read on sockets. The
I'm using StructureMap to inject a LINQ data context ( DB class) into my
I am using async_read_some to read data from a port that is saved in
When reading data in chunks of say, 1024, how do I continue to read

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.