/*** This file is part of snapcast Copyright (C) 2014-2016 Johannes Pohl This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ***/ #include #include #include "publishBonjour.h" #include "common/log.h" typedef union { unsigned char b[2]; unsigned short NotAnInteger; } Opaque16; PublishBonjour::PublishBonjour(const std::string& serviceName) : PublishmDNS(serviceName), active_(false) { /// dns-sd -R Snapcast _snapcast._tcp local 1704 /// dns-sd -R Snapcast _snapcast-jsonrpc._tcp local 1705 } PublishBonjour::~PublishBonjour() { active_ = false; pollThread_.join(); for (auto client: clients) { if (client) DNSServiceRefDeallocate(client); } } void PublishBonjour::worker() { // int dns_sd_fd = client ? DNSServiceRefSockFD(client) : -1; // 1. Set up the fd_set as usual here. // This example client has no file descriptors of its own, // but a real application would call FD_SET to add them to the set here fd_set readfds; FD_ZERO(&readfds); std::vector dns_sd_fds; int nfds = -1; for (size_t n=0; n 0) { for (size_t n=0; n& services) { for (auto service: services) { DNSServiceFlags flags = 0; Opaque16 registerPort = { { static_cast(service.port_ >> 8), static_cast(service.port_ & 0xFF) } }; DNSServiceRef client = NULL; // DNSServiceRegister(&client, flags, kDNSServiceInterfaceIndexAny, serviceName_.c_str(), service.name_.c_str(), NULL, NULL, registerPort.NotAnInteger, service.txt_.size(), service.txt_.empty()?NULL:service.txt_.c_str(), reg_reply, this); DNSServiceRegister(&client, flags, kDNSServiceInterfaceIndexAny, serviceName_.c_str(), service.name_.c_str(), NULL, NULL, registerPort.NotAnInteger, 0, NULL, reg_reply, this); clients.push_back(client); } pollThread_ = std::thread(&PublishBonjour::worker, this); }