forked from qt-creator/qt-creator
SSH: Prepare infrastructure for more timeout handling.
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
#define SSHCHANNEL_P_H
|
#define SSHCHANNEL_P_H
|
||||||
|
|
||||||
#include <QtCore/QByteArray>
|
#include <QtCore/QByteArray>
|
||||||
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
@@ -39,8 +40,9 @@ namespace Internal {
|
|||||||
class SshIncomingPacket;
|
class SshIncomingPacket;
|
||||||
class SshSendFacility;
|
class SshSendFacility;
|
||||||
|
|
||||||
class AbstractSshChannel
|
class AbstractSshChannel : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum ChannelState {
|
enum ChannelState {
|
||||||
Inactive, SessionRequested, SessionEstablished, CloseRequested, Closed
|
Inactive, SessionRequested, SessionEstablished, CloseRequested, Closed
|
||||||
@@ -76,6 +78,9 @@ public:
|
|||||||
|
|
||||||
virtual ~AbstractSshChannel();
|
virtual ~AbstractSshChannel();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void timeout();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
AbstractSshChannel(quint32 channelId, SshSendFacility &sendFacility);
|
AbstractSshChannel(quint32 channelId, SshSendFacility &sendFacility);
|
||||||
|
|
||||||
|
@@ -41,13 +41,12 @@
|
|||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
SshChannelManager::SshChannelManager(SshSendFacility &sendFacility)
|
SshChannelManager::SshChannelManager(SshSendFacility &sendFacility,
|
||||||
: m_sendFacility(sendFacility), m_nextLocalChannelId(0)
|
QObject *parent)
|
||||||
|
: QObject(parent), m_sendFacility(sendFacility), m_nextLocalChannelId(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SshChannelManager::~SshChannelManager() {}
|
|
||||||
|
|
||||||
void SshChannelManager::handleChannelRequest(const SshIncomingPacket &packet)
|
void SshChannelManager::handleChannelRequest(const SshIncomingPacket &packet)
|
||||||
{
|
{
|
||||||
lookupChannel(packet.extractRecipientChannel())
|
lookupChannel(packet.extractRecipientChannel())
|
||||||
@@ -164,6 +163,7 @@ Core::SftpChannel::Ptr SshChannelManager::createSftpChannel()
|
|||||||
void SshChannelManager::insertChannel(AbstractSshChannel *priv,
|
void SshChannelManager::insertChannel(AbstractSshChannel *priv,
|
||||||
const QSharedPointer<QObject> &pub)
|
const QSharedPointer<QObject> &pub)
|
||||||
{
|
{
|
||||||
|
connect(priv, SIGNAL(timeout()), this, SIGNAL(timeout()));
|
||||||
m_channels.insert(priv->localChannelId(), priv);
|
m_channels.insert(priv->localChannelId(), priv);
|
||||||
m_sessions.insert(priv, pub);
|
m_sessions.insert(priv, pub);
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#define SSHCHANNELLAYER_P_H
|
#define SSHCHANNELLAYER_P_H
|
||||||
|
|
||||||
#include <QtCore/QHash>
|
#include <QtCore/QHash>
|
||||||
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QSharedPointer>
|
#include <QtCore/QSharedPointer>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
@@ -44,11 +45,11 @@ class AbstractSshChannel;
|
|||||||
class SshIncomingPacket;
|
class SshIncomingPacket;
|
||||||
class SshSendFacility;
|
class SshSendFacility;
|
||||||
|
|
||||||
class SshChannelManager
|
class SshChannelManager : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SshChannelManager(SshSendFacility &sendFacility);
|
SshChannelManager(SshSendFacility &sendFacility, QObject *parent);
|
||||||
~SshChannelManager();
|
|
||||||
|
|
||||||
QSharedPointer<SshRemoteProcess> createRemoteProcess(const QByteArray &command);
|
QSharedPointer<SshRemoteProcess> createRemoteProcess(const QByteArray &command);
|
||||||
QSharedPointer<SftpChannel> createSftpChannel();
|
QSharedPointer<SftpChannel> createSftpChannel();
|
||||||
@@ -66,6 +67,9 @@ public:
|
|||||||
void handleChannelEof(const SshIncomingPacket &packet);
|
void handleChannelEof(const SshIncomingPacket &packet);
|
||||||
void handleChannelClose(const SshIncomingPacket &packet);
|
void handleChannelClose(const SshIncomingPacket &packet);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void timeout();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef QHash<quint32, AbstractSshChannel *>::Iterator ChannelIterator;
|
typedef QHash<quint32, AbstractSshChannel *>::Iterator ChannelIterator;
|
||||||
|
|
||||||
|
@@ -149,11 +149,12 @@ namespace Internal {
|
|||||||
SshConnectionPrivate::SshConnectionPrivate(SshConnection *conn)
|
SshConnectionPrivate::SshConnectionPrivate(SshConnection *conn)
|
||||||
: m_socket(new QTcpSocket(this)), m_state(SocketUnconnected),
|
: m_socket(new QTcpSocket(this)), m_state(SocketUnconnected),
|
||||||
m_sendFacility(m_socket),
|
m_sendFacility(m_socket),
|
||||||
m_channelManager(new SshChannelManager(m_sendFacility)),
|
m_channelManager(new SshChannelManager(m_sendFacility, this)),
|
||||||
m_error(SshNoError), m_ignoreNextPacket(false), m_conn(conn)
|
m_error(SshNoError), m_ignoreNextPacket(false), m_conn(conn)
|
||||||
{
|
{
|
||||||
setupPacketHandlers();
|
setupPacketHandlers();
|
||||||
connect(&m_timeoutTimer, SIGNAL(timeout()), this, SLOT(handleTimeout()));
|
m_timeoutTimer.setSingleShot(true);
|
||||||
|
connect(m_channelManager, SIGNAL(timeout()), this, SLOT(handleTimeout()));
|
||||||
}
|
}
|
||||||
|
|
||||||
SshConnectionPrivate::~SshConnectionPrivate()
|
SshConnectionPrivate::~SshConnectionPrivate()
|
||||||
@@ -501,9 +502,8 @@ void SshConnectionPrivate::handleSocketError()
|
|||||||
|
|
||||||
void SshConnectionPrivate::handleTimeout()
|
void SshConnectionPrivate::handleTimeout()
|
||||||
{
|
{
|
||||||
if (m_state != ConnectionEstablished)
|
|
||||||
closeConnection(SSH_DISCONNECT_BY_APPLICATION, SshTimeoutError, "",
|
closeConnection(SSH_DISCONNECT_BY_APPLICATION, SshTimeoutError, "",
|
||||||
tr("Connection timed out."));
|
tr("Timeout waiting for reply from server."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SshConnectionPrivate::connectToHost(const SshConnectionParameters &serverInfo)
|
void SshConnectionPrivate::connectToHost(const SshConnectionParameters &serverInfo)
|
||||||
@@ -520,6 +520,7 @@ void SshConnectionPrivate::connectToHost(const SshConnectionParameters &serverIn
|
|||||||
SLOT(handleSocketError()));
|
SLOT(handleSocketError()));
|
||||||
connect(m_socket, SIGNAL(disconnected()), this,
|
connect(m_socket, SIGNAL(disconnected()), this,
|
||||||
SLOT(handleSocketDisconnected()));
|
SLOT(handleSocketDisconnected()));
|
||||||
|
connect(&m_timeoutTimer, SIGNAL(timeout()), this, SLOT(handleTimeout()));
|
||||||
this->m_connParams = serverInfo;
|
this->m_connParams = serverInfo;
|
||||||
m_state = SocketConnecting;
|
m_state = SocketConnecting;
|
||||||
m_timeoutTimer.start(m_connParams.timeout * 1000);
|
m_timeoutTimer.start(m_connParams.timeout * 1000);
|
||||||
@@ -538,6 +539,7 @@ void SshConnectionPrivate::closeConnection(SshErrorCode sshError,
|
|||||||
m_errorString = userErrorString;
|
m_errorString = userErrorString;
|
||||||
m_timeoutTimer.stop();
|
m_timeoutTimer.stop();
|
||||||
disconnect(m_socket, 0, this, 0);
|
disconnect(m_socket, 0, this, 0);
|
||||||
|
disconnect(&m_timeoutTimer, 0, this, 0);
|
||||||
try {
|
try {
|
||||||
m_channelManager->closeAllChannels();
|
m_channelManager->closeAllChannels();
|
||||||
m_sendFacility.sendDisconnectPacket(sshError, serverErrorString);
|
m_sendFacility.sendDisconnectPacket(sshError, serverErrorString);
|
||||||
|
@@ -141,7 +141,7 @@ private:
|
|||||||
SshStateInternal m_state;
|
SshStateInternal m_state;
|
||||||
SshIncomingPacket m_incomingPacket;
|
SshIncomingPacket m_incomingPacket;
|
||||||
SshSendFacility m_sendFacility;
|
SshSendFacility m_sendFacility;
|
||||||
QScopedPointer<SshChannelManager> m_channelManager;
|
SshChannelManager * const m_channelManager;
|
||||||
SshConnectionParameters m_connParams;
|
SshConnectionParameters m_connParams;
|
||||||
QByteArray m_incomingData;
|
QByteArray m_incomingData;
|
||||||
SshError m_error;
|
SshError m_error;
|
||||||
|
Reference in New Issue
Block a user