Rabbit Remote Control 0.0.36
Loading...
Searching...
No Matches
SSHTunnelThread.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include <QLoggingCategory>
4#include <QThread>
5
6#include "ChannelSSHTunnelForward.h"
7#include "SSHTunnelThread.h"
8
9static Q_LOGGING_CATEGORY(log, "Channel.SSH.Tunnel.Thread")
10
12 : QThread(nullptr),
13 m_pConnect(pConnect),
14 m_bExit(false),
15 m_pParameter(parameter),
16 m_pRemoteNet(remote)
17{
18 qDebug(log) << "CSSHTunnelThread::CSSHTunnelThread";
19 bool check = false;
20 check = connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
21 Q_ASSERT(check);
22}
23
24CSSHTunnelThread::~CSSHTunnelThread()
25{
26 qDebug(log) << "CSSHTunnelThread::~CSSHTunnelThread";
27}
28
29void CSSHTunnelThread::Exit()
30{
31 m_bExit = true;
32}
33
34void CSSHTunnelThread::run()
35{
36 int nRet = 0;
37 qDebug(log) << "CSSHTunnelThread run";
39 m_pParameter, m_pRemoteNet, m_pConnect);
40 if(!p)
41 return;
42
43 do{
44 bool check = connect(p, SIGNAL(sigServer(QString, quint16)),
45 this, SIGNAL(sigServer(QString, quint16)));
46 Q_ASSERT(check);
47 check = connect(p, SIGNAL(sigServer(QString)),
48 this, SIGNAL(sigServer(QString)));
49 Q_ASSERT(check);
50 check = connect(p, SIGNAL(sigError(int,QString)), this,
51 SIGNAL(sigError(int,QString)));
52 Q_ASSERT(check);
53
54 if(!p->open(QIODevice::ReadWrite)) {
55 emit m_pConnect->sigShowMessageBox(
56 tr("Error"), p->errorString(), QMessageBox::Critical);
57 nRet = -1;
58 break;
59 }
60 while (!m_bExit && nRet >= 0) {
61 nRet = p->Process();
62 if(nRet) {
63 qCritical(log) << "Process fail" << p->errorString();
64 break;
65 }
66 }
67
68 p->close();
69 } while(0);
70
71 if(nRet)
72 emit sigError(nRet, p->errorString());
73
74 emit sigDisconnect();
75 p->deleteLater();
76
77 qDebug(log) << "CSSHTunnelThread end";
78}
Includes SSH tunneling and a local socket service for forwarding data.
virtual bool open(OpenMode mode) override
Connect interface.
Definition Connect.h:45
void sigShowMessageBox(const QString &szTitle, const QString &szMessage, const QMessageBox::Icon &icon=QMessageBox::Information)
Trigger the display of a message dialog (QMessageBox) in the main thread from a background thread wit...
Basic network parameters.
Data is forwarded over a local socket and SSH tunnel.
void sigServer(QString szHost, quint16 nPort)
It is triggered when the socket service establishes a listener and is used to notify other local sock...