shared_ptr<Face> EthernetFactory::createMulticastFace(const NetworkInterfaceInfo& interface, const ethernet::Address& address) { if (!address.isMulticast()) BOOST_THROW_EXCEPTION(Error(address.toString() + " is not a multicast address")); auto face = findMulticastFace(interface.name, address); if (face) return face; face::GenericLinkService::Options opts; opts.allowFragmentation = true; opts.allowReassembly = true; auto linkService = make_unique<face::GenericLinkService>(opts); auto transport = make_unique<face::EthernetTransport>(interface, address); face = make_shared<Face>(std::move(linkService), std::move(transport)); auto key = std::make_pair(interface.name, address); m_multicastFaces[key] = face; connectFaceClosedSignal(*face, [this, key] { m_multicastFaces.erase(key); }); return face; }
shared_ptr<EthernetFace> EthernetFactory::createMulticastFace(const NetworkInterfaceInfo& interface, const ethernet::Address &address) { if (!address.isMulticast()) throw Error(address.toString() + " is not a multicast address"); shared_ptr<EthernetFace> face = findMulticastFace(interface.name, address); if (face) return face; auto socket = make_shared<boost::asio::posix::stream_descriptor>(ref(getGlobalIoService())); face = make_shared<EthernetFace>(socket, interface, address); auto key = std::make_pair(interface.name, address); face->onFail += [this, key] (const std::string& reason) { m_multicastFaces.erase(key); }; m_multicastFaces.insert({key, face}); return face; }