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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:11:21+00:00 2026-05-13T12:11:21+00:00

I couldn’t find any thing about what happens if you try to do a

  • 0

I couldn’t find any thing about what happens if you try to do a second write to a boost::asio socket before a previous one completed. This seems like something that could potentially happen in many asynchronous programs (since after doing the first write, the program will then continue before waiting for it to finish, potentially causing a second message to be sent and so on). I’ve thought of a few possible things that could happen (this is assuming that in all cases the message is sent with a single call to async_write).

void handleWrite(const boost::system::error_code&error)
{
    if(error)throw NetError(error);
}

vodi sendStuff()
{
    const char msg1 = "Red, Green, Blue";
    const char msg2 = "One, Two, Three";

    asio::async_write(socket,asio::buffer(msg1,sizeof(msg1)),boost::bind(&handleWrite,_1));
    //assume msg1 has still not been sent by the time we get here
    asio::async_write(socket,asio::buffer(msg2,sizeof(msg2)),boost::bind(&handleWrite,_1));
}

So assuming that the first send doesn’t cause an error:

  • Asio sends msg1, then msg2, in order, possible even in a single TCP packet
  • The second async_write call blocks until msg1 is done
  • The result is undefined

If an error occurs in msg1s, i’m assuming the exception will cause msg2 to abort as well?

Also is this effected by if the associated io_service has a thread pool, or just a single thread?

If it’s not safe, then has any one written some kind of simple wrapper that maintains a queue of messages to send, sending them one by one and aborting if any write handler throws an exception?

  • 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-13T12:11:22+00:00Added an answer on May 13, 2026 at 12:11 pm

    So, with normal non-blocking sockets, you can write some implementation-dependant amount of stuff to the socket, then eventually a write will return -EWOULDBLOCK and not do the write so you can retry later. Poking around in the source tells me that Boost wraps that, so that everything you write should get there eventually (or raise an error, not including would_block or try_again).

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

Sidebar

Related Questions

Couldn't find any documentation about this: what is the order of execution of the
I couldn't find any information in the reference page of MPMoviePlayerController or in the
Couldn't find any file-tree component (cross-platform, of course) in the FireMonkey framework. Anyone has
I couldn't find enough resource about this subject and i need to learn how
Couldn't find any real answers on google.
I couldn't find the answer to this in any other question. Suppose that I
I couldn't find any mapview template for the graphical layout. Mapview is from google,
Couldn't find any good information on how to do this so I thought I'd
(Couldn't think of any simpler way to write the title for this, but the
Couldn't find any answer to this problem, or not even any questions asked. So

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.