1

I know that concurrent calls of methods of the same socket object leads to undefined behaviour.

But what about calling an asynchronous operation and calling it again (non concurrently) before the completion handler of the first one is invoked?

Say, what is the expected behaviour of the following (if any):

boost::asio::ip::udp::socket socket;

// make socket join a multicast group, for instance

socket.async_receive( boost::asio::null_buffers( ) , & handler1 );

// assume handler1() is not called between this two lines

socket.async_receive( boost::asio::null_buffers( ) , & handler2 );

?

This seems something someone should not be doing, but I couldn't find in the docs any specific place where such an issue is addressed.

Tarc
  • 3,214
  • 3
  • 29
  • 41

1 Answers1

2

You're right, that's a big no-no in async i/o. Calling async_receive twice does actually make little sense, but to avoid this kind of situation while sending can imply using some sort of queue, a boost::circular_buffer, or the likes. This entirely depends on your application.

I think the issue is not addressed because the boost documentation assumes the reader is already familiar with using async sockets.

Michaël Roy
  • 6,338
  • 1
  • 15
  • 19