简体   繁体   中英

boost::asio udp socket read and write

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?

PS I'm using one thread ioservice::run

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM