优化结构,尽量使用槽连接,使用信号返回信息
This commit is contained in:
+65
-47
@@ -29,32 +29,35 @@ quint32 ipv4str_to_int(const QString& ipstr)
|
||||
void trytry::run()
|
||||
{
|
||||
|
||||
|
||||
QTcpSocket m_socket;
|
||||
m_socket.connectToHost(ipstr, ipint, QTcpSocket::ReadWrite);
|
||||
if (m_socket.waitForConnected(timeout))
|
||||
if (ipint != 0 && ipstr != "")
|
||||
{
|
||||
while(*outputbusy);
|
||||
*outputbusy+=1;
|
||||
QString temp = QString("%1:%2").arg(ipstr).arg(ipint);
|
||||
//output_list->append(temp);
|
||||
qDebug() << ipstr<<":"<< ipint;
|
||||
//msleep(1);
|
||||
*outputbusy-=1;
|
||||
//qDebug()<<ipstr<<":"<<ipint;
|
||||
QTcpSocket m_socket;
|
||||
m_socket.connectToHost(ipstr, ipint, QTcpSocket::ReadWrite);
|
||||
if (m_socket.waitForConnected(timeout))
|
||||
{
|
||||
while(*outputbusy);
|
||||
*outputbusy+=1;
|
||||
QString temp = QString("%1:%2").arg(ipstr).arg(ipint);
|
||||
output_list->append(temp);
|
||||
//qDebug() << ipstr<<":"<< ipint;
|
||||
//msleep(1);
|
||||
*outputbusy-=1;
|
||||
}
|
||||
m_socket.disconnectFromHost();
|
||||
m_socket.disconnect();
|
||||
|
||||
|
||||
//while(*barbusy);
|
||||
//*barbusy+=1;
|
||||
|
||||
//str.asprintf("停止 %.3f",((0.0+*nt_bar)/(0.0+*t_bar))*100);
|
||||
//bt->setText(QString("%1%").arg(((0.0+*nt_bar)/(0.0+*t_bar))*100));
|
||||
//qDebug()<<*nt_bar<<"/"<<*t_bar;
|
||||
//*barbusy-=1;
|
||||
|
||||
//*now_thread_num-=1;
|
||||
}
|
||||
m_socket.disconnectFromHost();
|
||||
m_socket.disconnect();
|
||||
|
||||
|
||||
//while(*barbusy);
|
||||
//*barbusy+=1;
|
||||
*nt_bar+=1;
|
||||
//str.asprintf("停止 %.3f",((0.0+*nt_bar)/(0.0+*t_bar))*100);
|
||||
//bt->setText(QString("%1%").arg(((0.0+*nt_bar)/(0.0+*t_bar))*100));
|
||||
//qDebug()<<*nt_bar<<"/"<<*t_bar;
|
||||
//*barbusy-=1;
|
||||
|
||||
*now_thread_num-=1;
|
||||
}
|
||||
|
||||
dispatch::dispatch()
|
||||
@@ -66,38 +69,52 @@ dispatch::dispatch()
|
||||
void dispatch::tray(const QString& ipstr, quint32 ipint)
|
||||
{
|
||||
|
||||
if (ipint != 0 && ipstr != "")
|
||||
|
||||
|
||||
//qDebug()<<"thread "<<now_thread_num<<":"<<set_thread_num;
|
||||
while (now_thread_num> set_thread_num)
|
||||
{
|
||||
//qDebug()<<"while "<<now_thread_num<<":"<<set_thread_num;
|
||||
}
|
||||
|
||||
//qDebug()<<"thread "<<now_thread_num<<":"<<set_thread_num;
|
||||
while (now_thread_num> set_thread_num)
|
||||
{
|
||||
//qDebug()<<"while "<<now_thread_num<<":"<<set_thread_num;
|
||||
}
|
||||
try_telnet=new trytry;
|
||||
try_telnet->ipstr = ipstr;
|
||||
try_telnet->ipint = ipint;
|
||||
try_telnet->timeout = timeout;
|
||||
try_telnet->output_list = output_list;
|
||||
|
||||
try_telnet=new trytry;
|
||||
try_telnet->ipstr = ipstr;
|
||||
try_telnet->ipint = ipint;
|
||||
try_telnet->timeout = timeout;
|
||||
try_telnet->output_list = output_list;
|
||||
try_telnet->bt=bt;
|
||||
|
||||
try_telnet->now_thread_num = &now_thread_num;
|
||||
try_telnet->now_thread_num = &now_thread_num;
|
||||
|
||||
try_telnet->t_bar=&t_bar;
|
||||
try_telnet->nt_bar=&nt_bar;
|
||||
try_telnet->t_bar=t_bar;
|
||||
try_telnet->nt_bar=nt_bar;
|
||||
|
||||
try_telnet->outputbusy=&outputbusy;
|
||||
try_telnet->barbusy=&barbusy;
|
||||
try_telnet->outputbusy=&outputbusy;
|
||||
try_telnet->barbusy=&barbusy;
|
||||
|
||||
|
||||
|
||||
//try_telnet->moveToThread(main_thread);
|
||||
try_telnet->start();
|
||||
//try_telnet->moveToThread(main_thread);
|
||||
|
||||
connect(try_telnet,&QThread::started,[=]()
|
||||
{
|
||||
now_thread_num+=1;
|
||||
|
||||
}
|
||||
thread_start_lock=0;
|
||||
|
||||
});
|
||||
connect(try_telnet,&QThread::finished,[=]()
|
||||
{
|
||||
now_thread_num-=1;
|
||||
|
||||
});
|
||||
|
||||
while(thread_start_lock);
|
||||
try_telnet->start();
|
||||
thread_start_lock=1;
|
||||
|
||||
*nt_bar+=1;
|
||||
emit dispatch_one();
|
||||
}
|
||||
|
||||
void dispatch::run()
|
||||
@@ -152,8 +169,8 @@ void dispatch::run()
|
||||
}
|
||||
}
|
||||
|
||||
t_bar=ips_num*ports_num;
|
||||
nt_bar=0;
|
||||
*t_bar=ips_num*ports_num;
|
||||
*nt_bar=0;
|
||||
outputbusy=0;
|
||||
|
||||
\
|
||||
@@ -221,7 +238,8 @@ void dispatch::run()
|
||||
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
//sleep(1);
|
||||
while(now_thread_num);
|
||||
emit dispatch_finish();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user