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