|
|
|
@ -27,6 +27,8 @@ bool DeviceManage::connectDevice(Device::DeviceParams params)
|
|
|
|
qInfo("over the maximum number of connections");
|
|
|
|
qInfo("over the maximum number of connections");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
// 没有必要分配端口,都用27183即可,连接建立以后server会释放监听的
|
|
|
|
quint16 port = 0;
|
|
|
|
quint16 port = 0;
|
|
|
|
if (params.useReverse) {
|
|
|
|
if (params.useReverse) {
|
|
|
|
port = getFreePort();
|
|
|
|
port = getFreePort();
|
|
|
|
@ -34,9 +36,11 @@ bool DeviceManage::connectDevice(Device::DeviceParams params)
|
|
|
|
qInfo("no port available, automatically switch to forward");
|
|
|
|
qInfo("no port available, automatically switch to forward");
|
|
|
|
params.useReverse = false;
|
|
|
|
params.useReverse = false;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
params.localPort = port;
|
|
|
|
qInfo("free port %d", port);
|
|
|
|
qInfo("free port %d", port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
Device *device = new Device(params);
|
|
|
|
Device *device = new Device(params);
|
|
|
|
connect(device, &Device::deviceDisconnect, this, &DeviceManage::onDeviceDisconnect);
|
|
|
|
connect(device, &Device::deviceDisconnect, this, &DeviceManage::onDeviceDisconnect);
|
|
|
|
m_devices[params.serial] = device;
|
|
|
|
m_devices[params.serial] = device;
|
|
|
|
@ -65,10 +69,10 @@ void DeviceManage::onDeviceDisconnect(QString serial)
|
|
|
|
|
|
|
|
|
|
|
|
quint16 DeviceManage::getFreePort()
|
|
|
|
quint16 DeviceManage::getFreePort()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
quint16 port = m_localPortStart;
|
|
|
|
quint16 port = m_localPortStart;
|
|
|
|
QMapIterator<QString, QPointer<Device>> i(m_devices);
|
|
|
|
|
|
|
|
while (port < m_localPortStart + DM_MAX_DEVICES_NUM) {
|
|
|
|
while (port < m_localPortStart + DM_MAX_DEVICES_NUM) {
|
|
|
|
bool used = false;
|
|
|
|
bool used = false;
|
|
|
|
|
|
|
|
QMapIterator<QString, QPointer<Device>> i(m_devices);
|
|
|
|
while (i.hasNext()) {
|
|
|
|
while (i.hasNext()) {
|
|
|
|
i.next();
|
|
|
|
i.next();
|
|
|
|
auto device = i.value();
|
|
|
|
auto device = i.value();
|
|
|
|
@ -82,6 +86,7 @@ quint16 DeviceManage::getFreePort()
|
|
|
|
if (!used) {
|
|
|
|
if (!used) {
|
|
|
|
return port;
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
port++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|