Commit d3d010d0 authored by jcacerec's avatar jcacerec
Browse files

fix id issue with re-connecting clients

parent 66aa0027
......@@ -214,11 +214,13 @@ int JackTripWorker::setJackTripFromClientHeader(JackTrip& jacktrip)
int PeerNumChannels = jacktrip.getPeerNumChannels(full_packet);
int PeerConnectionMode = jacktrip.getPeerConnectionMode(full_packet);
/*
cout << "getPeerBufferSize = " << PeerBufferSize << endl;
cout << "getPeerSamplingRate = " << PeerSamplingRate << endl;
cout << "getPeerBitResolution = " << PeerBitResolution << endl;
cout << "getPeerNumChannels = " << PeerNumChannels << endl;
cout << "getPeerConnectionMode = " << PeerConnectionMode << endl;
*/
jacktrip.setNumChannels(PeerNumChannels);
return PeerConnectionMode;
......
......@@ -43,6 +43,7 @@
#include <QTcpServer>
#include <QTcpSocket>
#include <QStringList>
#include <QMutexLocker>
#include "UdpMasterListener.h"
#include "JackTripWorker.h"
......@@ -148,7 +149,8 @@ void UdpMasterListener::run()
while ( isNewAddress(PeerAddress.toIPv4Address(), peer_udp_port) == -1 )
{ cout << "removing" << endl; QThread::msleep(10); }
// Get a new ID for this client
id = isNewAddress(PeerAddress.toIPv4Address(), peer_udp_port);
//id = isNewAddress(PeerAddress.toIPv4Address(), peer_udp_port);
id = getPoolID(PeerAddress.toIPv4Address(), peer_udp_port);
}
// Assign server port and send it to Client
server_udp_port = mBasePort+id;
......@@ -302,17 +304,44 @@ void UdpMasterListener::bindUdpSocket(QUdpSocket& udpsocket, int port) throw(std
// check by comparing 32-bit addresses
int UdpMasterListener::isNewAddress(uint32_t address, uint16_t port)
{
QMutexLocker lock(&mMutex);
bool busyAddress = false;
int id = 0;
/*
while ( !busyAddress && (id<mThreadPool.activeThreadCount()) )
{
if ( address==mActiveAddress[id][0] && port==mActiveAddress[id][1]) { busyAddress = true; }
id++;
}
if ( !busyAddress ) {
*/
for (int i = 0; i<gMaxThreads; i++) {
if ( address==mActiveAddress[i][0] && port==mActiveAddress[i][1]) {
id = i;
busyAddress = true;
//cout << i << "##########################BUSY############################"<< endl;
}
}
if ( !busyAddress ) {
/*
mActiveAddress[id][0] = address;
mActiveAddress[id][1] = port;
} else {
*/
id = 0;
bool foundEmptyAddress = false;
while ( !foundEmptyAddress && (id<gMaxThreads) ) {
if ( (mActiveAddress[id][0] == 0) && (mActiveAddress[id][1] == 0) ) {
foundEmptyAddress = true;
mActiveAddress[id][0] = address;
mActiveAddress[id][1] = port;
} else {
id++;
cout << id << endl;
}
}
}
//cout << "ID -------------------------------> " << id << "BUSYADDRESS " << busyAddress << endl;
return ((busyAddress) ? -1 : id);
}
......@@ -320,7 +349,8 @@ int UdpMasterListener::isNewAddress(uint32_t address, uint16_t port)
//*******************************************************************************
int UdpMasterListener::getPoolID(uint32_t address, uint16_t port)
{
for (int id = 0; id<mThreadPool.activeThreadCount(); id++ )
//for (int id = 0; id<mThreadPool.activeThreadCount(); id++ )
for (int id = 0; id<gMaxThreads; id++ )
{
if ( address==mActiveAddress[id][0] && port==mActiveAddress[id][1])
{ return id; }
......@@ -332,8 +362,11 @@ int UdpMasterListener::getPoolID(uint32_t address, uint16_t port)
//*******************************************************************************
int UdpMasterListener::releaseThread(int id)
{
QMutexLocker lock(&mMutex);
mActiveAddress[id][0] = 0;
mActiveAddress[id][1] = 0;
mTotalRunningThreads--;
cout << "THREAD RELEASED UdpMasterListener" << endl;
QThread:sleep(2);
return 0; /// \todo Check if we really need to return an argument here
}
......@@ -47,6 +47,7 @@
#include <QHostAddress>
#include <QTcpSocket>
#include <QTcpServer>
#include <QMutex>
#include "jacktrip_types.h"
#include "jacktrip_globals.h"
......@@ -128,6 +129,7 @@ private:
/// Boolean stop the execution of the thread
volatile bool mStopped;
int mTotalRunningThreads; ///< Number of Threads running in the pool
QMutex mMutex;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment