boost::asio udp socket read and write

Viewed 36

I need an advice with the situation

I'm doing a udp async multicast transiver:

  • he can accepts data from multicast group
  • he can send data to multicast group

Data is sent in the following cases:

  • async_receive_from -> callback -> async_send (in the same thread)
  • by external timer -> async_send(in another thread)
  1. I use one socket for receive and send. Do I need synchronize async_receive_from and async_send_to from external timer? booast::asio doc says that objects are unsafe. My solution is use a ioserivce post/dispatch for external timer data, that async_send_to call in the same thread

  2. If I make two sockets - one for read, one for thread, who works this one multicast groud. Do I need synchronize this?

P.S. I'm using one thread ioservice::run

1 Answers

As soon as an external timer is involved likely a strand is required for synchronization. The only exception is when the service is restricted to a single thread already - and the "external timer" trigger originates from that same thread. This is called the implicit strand.

Related