线程还是会时不时暴毙,还需要优化
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 6.0.1, 2022-01-05T20:45:49. -->
|
<!-- Written by QtCreator 6.0.1, 2022-01-06T00:49:24. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
@@ -240,12 +240,14 @@
|
|||||||
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/wuwen/Desktop/tcp_ip_scan/ip_sacaner/ip_sacaner.pro</value>
|
||||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">C:/Users/wuwen/Desktop/tcp_ip_scan/ip_sacaner/ip_sacaner.pro</value>
|
||||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
|
||||||
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
||||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
|
<value type="QString" key="RunConfiguration.WorkingDirectory.default">C:/Users/wuwen/Desktop/tcp_ip_scan/build-ip_sacaner-Desktop_Qt_6_2_2_MinGW_64_bit-Debug</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
|
|||||||
+12
-12
@@ -30,7 +30,6 @@ void trytry::run()
|
|||||||
{
|
{
|
||||||
//qDebug() << ipstr<<":"<< ipint;
|
//qDebug() << ipstr<<":"<< ipint;
|
||||||
|
|
||||||
|
|
||||||
QTcpSocket m_socket;
|
QTcpSocket m_socket;
|
||||||
m_socket.connectToHost(ipstr, ipint, QTcpSocket::ReadWrite);
|
m_socket.connectToHost(ipstr, ipint, QTcpSocket::ReadWrite);
|
||||||
if (m_socket.waitForConnected(timeout))
|
if (m_socket.waitForConnected(timeout))
|
||||||
@@ -39,22 +38,20 @@ void trytry::run()
|
|||||||
*outputbusy=1;
|
*outputbusy=1;
|
||||||
QString temp = QString("%1:%2").arg(ipstr).arg(ipint);
|
QString temp = QString("%1:%2").arg(ipstr).arg(ipint);
|
||||||
output_list->append(temp);
|
output_list->append(temp);
|
||||||
|
//msleep(1);
|
||||||
*outputbusy=0;
|
*outputbusy=0;
|
||||||
}
|
}
|
||||||
m_socket.disconnectFromHost();
|
m_socket.disconnectFromHost();
|
||||||
m_socket.disconnect();
|
m_socket.disconnect();
|
||||||
|
|
||||||
//msleep(timeout);//test
|
//qDebug()<<*nt_bar<<"/"<<*t_bar;
|
||||||
|
while(*barbusy);
|
||||||
|
*barbusy=1;
|
||||||
*now_thread_num-=1;
|
*now_thread_num-=1;
|
||||||
|
|
||||||
*nt_bar+=1;
|
*nt_bar+=1;
|
||||||
//((*nt_bar)/(*t_bar))*100
|
//str.asprintf("停止 %.3f",((0.0+*nt_bar)/(0.0+*t_bar))*100);
|
||||||
//the_bar->setValue(((0.0+*nt_bar)/(*t_bar))*100);
|
bt->setText(QString("%1%").arg(((0.0+*nt_bar)/(0.0+*t_bar))*100));
|
||||||
//qDebug()<<((0.0+*nt_bar)/(0.0+*t_bar))*100<<"%";
|
*barbusy=0;
|
||||||
//the_bar->setValue(10);
|
|
||||||
qDebug()<<*nt_bar<<"/"<<*t_bar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch::dispatch()
|
dispatch::dispatch()
|
||||||
@@ -80,7 +77,7 @@ void dispatch::tray(const QString& ipstr, quint32 ipint)
|
|||||||
try_telnet->ipint = ipint;
|
try_telnet->ipint = ipint;
|
||||||
try_telnet->timeout = timeout;
|
try_telnet->timeout = timeout;
|
||||||
try_telnet->output_list = output_list;
|
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;
|
||||||
|
|
||||||
@@ -88,8 +85,9 @@ void dispatch::tray(const QString& ipstr, quint32 ipint)
|
|||||||
try_telnet->nt_bar=&nt_bar;
|
try_telnet->nt_bar=&nt_bar;
|
||||||
|
|
||||||
try_telnet->outputbusy=&outputbusy;
|
try_telnet->outputbusy=&outputbusy;
|
||||||
|
try_telnet->barbusy=&barbusy;
|
||||||
|
|
||||||
|
|
||||||
try_telnet->the_bar=the_bar;
|
|
||||||
|
|
||||||
//try_telnet->moveToThread(main_thread);
|
//try_telnet->moveToThread(main_thread);
|
||||||
try_telnet->start();
|
try_telnet->start();
|
||||||
@@ -101,6 +99,8 @@ void dispatch::tray(const QString& ipstr, quint32 ipint)
|
|||||||
|
|
||||||
void dispatch::run()
|
void dispatch::run()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//qDebug()<< ui->IP_list->toPlainText();
|
//qDebug()<< ui->IP_list->toPlainText();
|
||||||
|
|
||||||
//the_bar->setValue(20);
|
//the_bar->setValue(20);
|
||||||
|
|||||||
@@ -2,12 +2,13 @@
|
|||||||
#define SCAN_RUN_H
|
#define SCAN_RUN_H
|
||||||
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include "widget.h"
|
|
||||||
#include "ui_widget.h"
|
#include "ui_widget.h"
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
#include <QProgressBar>
|
#include <QProgressBar>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTcpSocket> //socket
|
#include <QTcpSocket> //socket
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -16,16 +17,16 @@ class trytry : public QThread
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
quint16 *outputbusy;
|
quint16 *outputbusy;
|
||||||
|
quint16 *barbusy;
|
||||||
quint16 timeout;
|
quint16 timeout;
|
||||||
QString ipstr;
|
QString ipstr;
|
||||||
quint32 ipint;
|
quint32 ipint;
|
||||||
int *now_thread_num;
|
int *now_thread_num;
|
||||||
QTextEdit* output_list;
|
QTextEdit* output_list;
|
||||||
|
QLabel *bt;
|
||||||
quint64 *t_bar;
|
quint64 *t_bar;
|
||||||
quint64 *nt_bar;
|
quint64 *nt_bar;
|
||||||
QProgressBar* the_bar;
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
|
||||||
@@ -44,11 +45,12 @@ public:
|
|||||||
quint64 t_bar=0;
|
quint64 t_bar=0;
|
||||||
quint64 nt_bar=0;
|
quint64 nt_bar=0;
|
||||||
quint16 outputbusy=0;
|
quint16 outputbusy=0;
|
||||||
|
quint16 barbusy=0;
|
||||||
//QThread* main_thread;
|
//QThread* main_thread;
|
||||||
QTextEdit* ip_list;
|
QTextEdit* ip_list;
|
||||||
QTextEdit* port_list;
|
QTextEdit* port_list;
|
||||||
QTextEdit* output_list;
|
QTextEdit* output_list;
|
||||||
QProgressBar* the_bar;
|
QLabel *bt;
|
||||||
trytry* try_telnet;
|
trytry* try_telnet;
|
||||||
|
|
||||||
void tray(const QString& ipstr, quint32 ipint);
|
void tray(const QString& ipstr, quint32 ipint);
|
||||||
|
|||||||
@@ -42,20 +42,22 @@ Widget::Widget(QWidget *parent)
|
|||||||
ui->stard_scan->setText("停止");
|
ui->stard_scan->setText("停止");
|
||||||
|
|
||||||
|
|
||||||
dispatch* dispatch_thread;
|
//dispatch* dispatch_thread;
|
||||||
dispatch_thread = new dispatch;
|
dispatch_thread = new dispatch;
|
||||||
|
|
||||||
dispatch_thread->ip_list = ui->IP_list;
|
dispatch_thread->ip_list = ui->IP_list;
|
||||||
dispatch_thread->port_list = ui->port_list;
|
dispatch_thread->port_list = ui->port_list;
|
||||||
dispatch_thread->output_list = ui->outputlist;
|
dispatch_thread->output_list = ui->outputlist;
|
||||||
|
dispatch_thread->bt=ui->type_bar;
|
||||||
|
|
||||||
dispatch_thread->set_thread_num = ui->threads->value();
|
dispatch_thread->set_thread_num = ui->threads->value();
|
||||||
dispatch_thread->now_thread_num = 0;
|
dispatch_thread->now_thread_num = 0;
|
||||||
dispatch_thread->timeout = ui->timeout->value();
|
dispatch_thread->timeout = ui->timeout->value();
|
||||||
dispatch_thread->the_bar=ui->type_bar;
|
|
||||||
//dispatch_thread->main_thread = main_thread;
|
//dispatch_thread->main_thread = main_thread;
|
||||||
//dispatch_thread->moveToThread(main_thread);
|
//dispatch_thread->moveToThread(main_thread);
|
||||||
dispatch_thread->start();
|
dispatch_thread->start();
|
||||||
connect(dispatch_thread, &dispatch::dispatch_finish, [=]()
|
connect(dispatch_thread, &dispatch::finished, [=]()
|
||||||
{
|
{
|
||||||
ui->IP_list->setReadOnly(false);
|
ui->IP_list->setReadOnly(false);
|
||||||
ui->port_list->setReadOnly(false);
|
ui->port_list->setReadOnly(false);
|
||||||
@@ -69,7 +71,8 @@ Widget::Widget(QWidget *parent)
|
|||||||
});
|
});
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
//dispatch_thread->exit();
|
qDebug() << "tray_exit";
|
||||||
|
dispatch_thread->terminate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public:
|
|||||||
Widget(QWidget *parent = nullptr);
|
Widget(QWidget *parent = nullptr);
|
||||||
~Widget();
|
~Widget();
|
||||||
|
|
||||||
|
dispatch *dispatch_thread;
|
||||||
|
|
||||||
void auto_edit();
|
void auto_edit();
|
||||||
|
|
||||||
|
|||||||
+24
-13
@@ -28,9 +28,9 @@
|
|||||||
<widget class="QTextEdit" name="port_list">
|
<widget class="QTextEdit" name="port_list">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>500</x>
|
<x>490</x>
|
||||||
<y>100</y>
|
<y>100</y>
|
||||||
<width>91</width>
|
<width>101</width>
|
||||||
<height>111</height>
|
<height>111</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@@ -56,10 +56,21 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>420</x>
|
<x>420</x>
|
||||||
<y>220</y>
|
<y>220</y>
|
||||||
<width>171</width>
|
<width>71</width>
|
||||||
<height>41</height>
|
<height>41</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<stylestrategy>PreferDefault</stylestrategy>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>开始扫描</string>
|
<string>开始扫描</string>
|
||||||
</property>
|
</property>
|
||||||
@@ -152,13 +163,13 @@ domain.com</string>
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>10</x>
|
<x>10</x>
|
||||||
<y>300</y>
|
<y>270</y>
|
||||||
<width>581</width>
|
<width>581</width>
|
||||||
<height>191</height>
|
<height>221</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="readOnly">
|
<property name="readOnly">
|
||||||
<bool>true</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_2">
|
||||||
@@ -193,17 +204,17 @@ domain.com</string>
|
|||||||
<number>100</number>
|
<number>100</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QProgressBar" name="type_bar">
|
<widget class="QLabel" name="type_bar">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>10</x>
|
<x>500</x>
|
||||||
<y>270</y>
|
<y>240</y>
|
||||||
<width>581</width>
|
<width>53</width>
|
||||||
<height>23</height>
|
<height>16</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="value">
|
<property name="text">
|
||||||
<number>0</number>
|
<string>0%</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
Reference in New Issue
Block a user