玉兔远程控制 0.0.31
载入中...
搜索中...
未找到
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_bExit(false),
14 m_Parameter(parameter)
15{
16 qDebug(log) << "CSSHTunnelThread::CSSHTunnelThread";
17 bool check = false;
18 check = connect(this, SIGNAL(finished()),
19 this, SLOT(deleteLater()));
20 Q_ASSERT(check);
21}
22
23CSSHTunnelThread::~CSSHTunnelThread()
24{
25 qDebug(log) << "CSSHTunnelThread::~CSSHTunnelThread";
26}
27
28void CSSHTunnelThread::Exit()
29{
30 m_bExit = true;
31}
32
33void CSSHTunnelThread::run()
34{
35 int nRet = 0;
36 qDebug(log) << "CSSHTunnelThread run";
38 if(!p)
39 return;
40
41 do{
42 bool check = connect(p, SIGNAL(sigServer(QString, quint16)),
43 this, SIGNAL(sigServer(QString, quint16)));
44 Q_ASSERT(check);
45 check = connect(p, SIGNAL(sigServer(QString)),
46 this, SIGNAL(sigServer(QString)));
47 Q_ASSERT(check);
48 if(!p->open(QIODevice::ReadWrite)) {
49 break;
50 }
51
52 while (!m_bExit && nRet >= 0) {
53 nRet = p->Process();
54 if(nRet) {
55 qCritical(log) << "Process fail" << p->errorString();
56 break;
57 }
58 }
59
60 p->close();
61 } while(0);
62
63 if(nRet)
64 emit sigError(nRet, p->errorString());
65
66 emit sigDisconnect();
67 p->deleteLater();
68 qDebug(log) << "CSSHTunnelThread end";
69}
包括 SSH 隧道和用于转发数据的本地 SOCKET 服务。 实现通过本地 SOCKET 与 SSH 隧道转发数据。适用于库没有实现传输层接口,只有 socket 的情况。
virtual bool open(OpenMode mode) override
实现通过本地 SOCKET 与 SSH 隧道转发数据。适用于库没有实现传输层接口,只有 socket 的情况。
void sigServer(QString szHost, quint16 nPort)
当 SOCKET 服务建立监听后触发,用于通知其它本地 SOCKET 可以连接它