The class must open several sockets, listen asynchronously and write them to the buffer allocated with the class.
In the private: ad section:
std::vector<SHP_Socket> vecSock; std::vector<udp::endpoint> vecEndpoint; std::vector<uint8_t[8000]> vecData; std::vector<uint8_t[8000]> vecData2; where SHP_Socket is: typedef std::shared_ptr<udp::socket> SHP_Socket; .
I initialize sockets as follows:
SHP_Socket a; udp::endpoint sender_endpoint; a.reset(new udp::socket(io_service_, udp::endpoint(udp::v4(), my_ports[i]))); vecSock.push_back(a); Estimated class method that will listen on this socket in a separate thread:
void Class::receive(const boost::system::error_code &err, std::size_t bytes, int i) { if (bytes > 12) { memcpy(vecData2[i], vecData[i], bytes); } vecSock[i]->async_receive_from(buffer(vecData[i]), vecEndpoint[i], /*[1]*/); } It would be desirable that the Class::receive function be passed again by the async_receive_from parameter. How to do it?