Added fixed reconnection timeout.
This commit is contained in:
parent
f6777e66df
commit
a4d32efefb
|
|
@ -19,6 +19,7 @@ QAmqpClientPrivate::QAmqpClientPrivate(QAmqpClient *q)
|
|||
host(AMQP_HOST),
|
||||
virtualHost(AMQP_VHOST),
|
||||
autoReconnect(false),
|
||||
reconnectFixedTimeout(false),
|
||||
timeout(0),
|
||||
connecting(false),
|
||||
useSsl(false),
|
||||
|
|
@ -186,11 +187,14 @@ void QAmqpClientPrivate::_q_heartbeat()
|
|||
void QAmqpClientPrivate::_q_socketError(QAbstractSocket::SocketError error)
|
||||
{
|
||||
Q_Q(QAmqpClient);
|
||||
if (timeout <= 0) {
|
||||
timeout = 1000;
|
||||
} else {
|
||||
if (timeout < 120000)
|
||||
timeout *= 5;
|
||||
if(reconnectFixedTimeout == false)
|
||||
{
|
||||
if (timeout <= 0) {
|
||||
timeout = 1000;
|
||||
} else {
|
||||
if (timeout < 120000)
|
||||
timeout *= 5;
|
||||
}
|
||||
}
|
||||
|
||||
switch (error) {
|
||||
|
|
@ -753,10 +757,21 @@ bool QAmqpClient::autoReconnect() const
|
|||
return d->autoReconnect;
|
||||
}
|
||||
|
||||
void QAmqpClient::setAutoReconnect(bool value)
|
||||
void QAmqpClient::setAutoReconnect(bool value, int timeout)
|
||||
{
|
||||
Q_D(QAmqpClient);
|
||||
d->autoReconnect = value;
|
||||
|
||||
if((value == true) && (timeout > 0))
|
||||
{
|
||||
d->timeout = timeout;
|
||||
d->reconnectFixedTimeout = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
d->timeout = 0;
|
||||
d->reconnectFixedTimeout = false;
|
||||
}
|
||||
}
|
||||
|
||||
qint16 QAmqpClient::channelMax() const
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public:
|
|||
QAmqpAuthenticator *auth() const;
|
||||
|
||||
bool autoReconnect() const;
|
||||
void setAutoReconnect(bool value);
|
||||
void setAutoReconnect(bool value, int timeout = 0);
|
||||
|
||||
bool isConnected() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ public:
|
|||
// Network
|
||||
QByteArray buffer;
|
||||
bool autoReconnect;
|
||||
bool reconnectFixedTimeout;
|
||||
int timeout;
|
||||
bool connecting;
|
||||
bool useSsl;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ private Q_SLOTS:
|
|||
|
||||
public Q_SLOTS: // temporarily disabled
|
||||
void autoReconnect();
|
||||
void autoReconnectTimeout();
|
||||
void sslConnect();
|
||||
|
||||
private:
|
||||
|
|
@ -142,6 +143,25 @@ void tst_QAMQPClient::autoReconnect()
|
|||
QVERIFY(waitForSignal(&client, SIGNAL(connected()), 2));
|
||||
}
|
||||
|
||||
void tst_QAMQPClient::autoReconnectTimeout()
|
||||
{
|
||||
// TODO: this is a fairly crude way of testing this, research
|
||||
// better alternatives
|
||||
|
||||
QAmqpClient client;
|
||||
client.setAutoReconnect(true, 3);
|
||||
client.connectToHost();
|
||||
QVERIFY(waitForSignal(&client, SIGNAL(connected()), 60));
|
||||
qDebug() <<"connected" ;
|
||||
QProcess::execute("rabbitmqctl", QStringList() << "stop_app");
|
||||
QVERIFY(waitForSignal(&client, SIGNAL(disconnected()), 60));
|
||||
qDebug() <<"disconnected" ;
|
||||
QProcess::execute("rabbitmqctl", QStringList() << "start_app");
|
||||
QVERIFY(waitForSignal(&client, SIGNAL(connected()), 60));
|
||||
qDebug() <<"connected" ;
|
||||
|
||||
}
|
||||
|
||||
void tst_QAMQPClient::tune()
|
||||
{
|
||||
QAmqpClient client;
|
||||
|
|
|
|||
Loading…
Reference in New Issue