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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:55:53+00:00 2026-05-25T09:55:53+00:00

I am using Boost Asio to set up a socket connection. I would like

  • 0

I am using Boost Asio to set up a socket connection. I would like to peek at the data in the buffer without consuming it, and I would like to use a completion condition to ensure that I could stop the blocking call if necessary.

I can get the peek functionality from basic_stream_socket::receive:

template<
    typename MutableBufferSequence>
std::size_t receive(
    const MutableBufferSequence & buffers,
    socket_base::message_flags flags,
    boost::system::error_code & ec);

One of the possible message_flags is basic_stream_socket::message_peek. However, this call blocks until at least one byte is read or an error occurs. I can get the completion condition functionality from read:

template<
    typename SyncReadStream,
    typename MutableBufferSequence,
    typename CompletionCondition>
std::size_t read(
    SyncReadStream & s,
    const MutableBufferSequence & buffers,
    CompletionCondition completion_condition,
    boost::system::error_code & ec);

I can provide a completion_condition method which checks if the call should be aborted before continuing.

My question is this: Is there a way to get a message_flags parameter and a completion_condition parameter in the same method call?

  • 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-25T09:55:54+00:00Added an answer on May 25, 2026 at 9:55 am

    I would like to peek at the data in the buffer without consuming it,
    and I would like to use a completion condition to ensure that I could
    stop the blocking call if necessary.

    Don’t do this. Use asynchronous methods such as async_read() and async_write(). To stop outstanding asynchronous operations, use cancel().

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

Sidebar

Related Questions

I'm writing server using boost.asio. I have read and write buffer for each connection
I have a socket server, written in C++ using boost::asio, and I'm sending data
I am using boost::asio::ip::udp::socket to communicate. I use socket.receive_from(...) to receive messages from clients.
I have a TCP server using boost asio. I have accepted a socket connection.
I'm reading from a boost::asio::ip::udp::socket like this: using boost::asio::ip::udp; // ... char recv_buf[128]; udp::endpoint
I have a TCP server using boost asio. I have accepted a socket connection.
I am receiving data from a server through a socket using boost asio, and
I'm using boost::asio, and I have code like this: void CServer::Start(int port) { tcp::acceptor
I have been trying to set the TTL on ICMP packets using the boost::asio::ip::unicast::hops
I'm want to check for incoming data packages on the serial port, using boost.asio

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.