bool MythRAOPConnection::Init(void) { // connect up the request socket m_textStream = new NetStream(m_socket); m_textStream->setCodec("UTF-8"); if (!connect(m_socket, SIGNAL(readyRead()), this, SLOT(readClient()))) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to connect client socket signal."); return false; } // create the data socket m_dataSocket = new ServerPool(); if (!connect(m_dataSocket, SIGNAL(newDatagram(QByteArray, QHostAddress, quint16)), this, SLOT(udpDataReady(QByteArray, QHostAddress, quint16)))) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to connect data socket signal."); return false; } // try a few ports in case the first is in use m_dataPort = m_dataSocket->tryBindingPort(m_dataPort, RAOP_PORT_RANGE); if (m_dataPort < 0) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to bind to a port for data."); return false; } LOG(VB_GENERAL, LOG_INFO, LOC + QString("Bound to port %1 for incoming data").arg(m_dataPort)); // load the private key if (!LoadKey()) return false; // use internal volume control m_allowVolumeControl = gCoreContext->GetNumSetting("MythControlsVolume", 1); // start the watchdog timer to auto delete the client after a period of inactivity m_watchdogTimer = new QTimer(); connect(m_watchdogTimer, SIGNAL(timeout()), this, SLOT(timeout())); m_watchdogTimer->start(10000); m_dequeueAudioTimer = new QTimer(); connect(m_dequeueAudioTimer, SIGNAL(timeout()), this, SLOT(ProcessAudio())); return true; }
void ServerPool::newUdpDatagram(void) { QUdpSocket *socket = dynamic_cast<QUdpSocket*>(sender()); while (socket->state() == QAbstractSocket::BoundState && socket->hasPendingDatagrams()) { QByteArray buffer; buffer.resize(socket->pendingDatagramSize()); QHostAddress sender; quint16 senderPort; socket->readDatagram(buffer.data(), buffer.size(), &sender, &senderPort); emit newDatagram(buffer, sender, senderPort); } }
MythUDPListener::MythUDPListener() { m_socketPool = new ServerPool(this); connect(m_socketPool, SIGNAL(newDatagram(QByteArray, QHostAddress, quint16)), this, SLOT(Process(const QByteArray, QHostAddress, quint16))); QList<QHostAddress> addrs = ServerPool::DefaultListen(); addrs << ServerPool::DefaultBroadcast(); if (!m_socketPool->bind(addrs, gCoreContext->GetNumSetting("UDPNotifyPort", 0), false)) { delete m_socketPool; m_socketPool = NULL; } }