fixing http-transport crash

This commit is contained in:
John Preston 2014-11-24 16:21:27 +03:00
parent 3ce8d9f0b7
commit e97cc9f172
6 changed files with 34 additions and 21 deletions

View file

@ -677,8 +677,16 @@ namespace MTP {
void killSession(int32 dc) {
Sessions::iterator i = sessions.find(dc);
if (i != sessions.end()) {
bool wasMain = (i.value() == mainSession);
i.value()->stop();
sessions.erase(i);
if (wasMain) {
mainSession = MTProtoSessionPtr(new MTProtoSession());
mainSession->start(mtpMainDC());
sessions[mainSession->getDC()] = mainSession;
}
}
}

View file

@ -298,16 +298,16 @@ int32 MTProtoConnection::start(MTPSessionData *sessionData, int32 dc) {
dc = data->getDC();
if (!dc) {
delete data;
delete thread;
data = 0;
thread = 0;
return 0;
}
thread->start();
return dc;
}
void MTProtoConnection::restart() {
emit data->needToRestart();
}
void MTProtoConnection::stop() {
if (data) data->stop();
if (thread) thread->quit();
@ -318,6 +318,7 @@ void MTProtoConnection::stopped() {
if (data) data->deleteLater();
thread = 0;
data = 0;
delete this;
}
int32 MTProtoConnection::state() const {
@ -1107,20 +1108,20 @@ MTProtoConnectionPrivate::MTProtoConnectionPrivate(QThread *thread, MTProtoConne
connect(thread, SIGNAL(started()), this, SLOT(socketStart()));
connect(thread, SIGNAL(finished()), this, SLOT(doFinish()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
connect(&retryTimer, SIGNAL(timeout()), this, SLOT(retryByTimer()));
connect(&connCheckTimer, SIGNAL(timeout()), this, SLOT(onBadConnection()));
connect(&oldConnectionTimer, SIGNAL(timeout()), this, SLOT(onOldConnection()));
connect(sessionData->owner(), SIGNAL(authKeyCreated()), this, SLOT(updateAuthKey()));
connect(sessionData->owner(), SIGNAL(authKeyCreated()), this, SLOT(updateAuthKey()), Qt::QueuedConnection);
connect(this, SIGNAL(needToRestart()), this, SLOT(restartNow()));
connect(this, SIGNAL(needToReceive()), sessionData->owner(), SLOT(tryToReceive()));
connect(this, SIGNAL(stateChanged(qint32)), sessionData->owner(), SLOT(onConnectionStateChange(qint32)));
connect(sessionData->owner(), SIGNAL(needToSend()), this, SLOT(tryToSend()));
connect(this, SIGNAL(needToSendAsync()), sessionData->owner(), SIGNAL(needToSend()));
connect(this, SIGNAL(sessionResetDone()), sessionData->owner(), SLOT(onResetDone()));
connect(this, SIGNAL(sendAnythingAsync(quint64)), sessionData->owner(), SLOT(sendAnything(quint64)));
connect(sessionData->owner(), SIGNAL(needToRestart()), this, SLOT(restartNow()), Qt::QueuedConnection);
connect(this, SIGNAL(needToReceive()), sessionData->owner(), SLOT(tryToReceive()), Qt::QueuedConnection);
connect(this, SIGNAL(stateChanged(qint32)), sessionData->owner(), SLOT(onConnectionStateChange(qint32)), Qt::QueuedConnection);
connect(sessionData->owner(), SIGNAL(needToSend()), this, SLOT(tryToSend()), Qt::QueuedConnection);
connect(this, SIGNAL(needToSendAsync()), sessionData->owner(), SIGNAL(needToSend()), Qt::QueuedConnection);
connect(this, SIGNAL(sendHttpWait()), sessionData->owner(), SLOT(sendHttpWait()), Qt::QueuedConnection);
connect(this, SIGNAL(sessionResetDone()), sessionData->owner(), SLOT(onResetDone()), Qt::QueuedConnection);
connect(this, SIGNAL(sendAnythingAsync(quint64)), sessionData->owner(), SLOT(sendAnything(quint64)), Qt::QueuedConnection);
}
void MTProtoConnectionPrivate::onConfigLoaded() {
@ -1986,7 +1987,7 @@ void MTProtoConnectionPrivate::handleReceived() {
}
}
if (conn->needHttpWait()) {
sessionData->owner()->send(MTPHttpWait(MTP_http_wait(MTP_int(100), MTP_int(30), MTP_int(25000))));
emit sendHttpWait();
}
}
@ -3399,5 +3400,4 @@ void MTProtoConnectionPrivate::stop() {
}
MTProtoConnection::~MTProtoConnection() {
stopped();
}

View file

@ -71,7 +71,6 @@ public:
MTProtoConnection();
int32 start(MTPSessionData *data, int32 dc = 0); // return dc
void restart();
void stop();
void stopped();
~MTProtoConnection();
@ -312,6 +311,8 @@ signals:
void needToSendAsync();
void sendAnythingAsync(quint64);
void sendHttpWait();
public slots:
void retryByTimer();

View file

@ -460,7 +460,7 @@ void MTProtoConfigLoader::load() {
void MTProtoConfigLoader::done() {
_enumDCTimer.stop();
if (_enumRequest) MTP::cancel(_enumRequest);
if (_enumCurrent) MTP::killSession(_enumCurrent);
if (_enumCurrent) MTP::killSession(MTP::cfg + _enumCurrent);
emit loaded();
}

View file

@ -120,9 +120,7 @@ void MTProtoSession::start(int32 dcenter, uint32 connects) {
}
void MTProtoSession::restart() {
for (MTProtoConnections::const_iterator i = connections.cbegin(), e = connections.cend(); i != e; ++i) {
(*i)->restart();
}
emit needToRestart();
}
void MTProtoSession::stop() {
@ -158,6 +156,10 @@ void MTProtoSession::sendAnything(quint64 msCanWait) {
}
}
void MTProtoSession::sendHttpWait() {
send(MTPHttpWait(MTP_http_wait(MTP_int(100), MTP_int(30), MTP_int(25000))), RPCResponseHandler(), 50);
}
void MTProtoSession::checkRequestsByTimer() {
QVector<mtpMsgId> resendingIds;
QVector<mtpMsgId> removingIds; // remove very old (10 minutes) containers and resend requests

View file

@ -250,8 +250,8 @@ public:
signals:
void authKeyCreated();
void needToSend();
void needToRestart();
public slots:
@ -265,6 +265,8 @@ public slots:
void sendAnything(quint64 msCanWait);
void sendHttpWait();
private:
typedef QList<MTProtoConnection*> MTProtoConnections;