fixed crash in next/previous_chat(), MTP::dld/upl -> functions, download and upload sessions count reduced to 2

This commit is contained in:
John Preston 2016-02-29 14:34:44 +03:00
parent fcd713b8a6
commit 08072346fd
7 changed files with 34 additions and 30 deletions

View file

@ -51,8 +51,8 @@ enum {
MTPIPv4ConnectionWaitTimeout = 1000, // 1 seconds waiting for ipv4, until we accept ipv6
MTPMillerRabinIterCount = 30, // 30 Miller-Rabin iterations for dh_prime primality check
MTPUploadSessionsCount = 4, // max 4 upload sessions is created
MTPDownloadSessionsCount = 4, // max 4 download sessions is created
MTPUploadSessionsCount = 2, // max 2 upload sessions is created
MTPDownloadSessionsCount = 2, // max 2 download sessions is created
MTPKillFileSessionTimeout = 5000, // how much time without upload / download causes additional session kill
MTPEnumDCTimeout = 8000, // 8 seconds timeout for help_getConfig to work (then move to other dc)

View file

@ -1522,6 +1522,11 @@ void DialogsInner::destroyData() {
}
void DialogsInner::peerBefore(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const {
if (!inPeer) {
outPeer = 0;
outMsg = 0;
return;
}
if (_state == DefaultState) {
DialogsList::RowByPeer::const_iterator i = dialogs.list.rowByPeer.constFind(inPeer->id);
if (i == dialogs.list.rowByPeer.constEnd()) {
@ -1606,6 +1611,11 @@ void DialogsInner::peerBefore(const PeerData *inPeer, MsgId inMsg, PeerData *&ou
}
void DialogsInner::peerAfter(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const {
if (!inPeer) {
outPeer = 0;
outMsg = 0;
return;
}
if (_state == DefaultState) {
DialogsList::RowByPeer::const_iterator i = dialogs.list.rowByPeer.constFind(inPeer->id);
if (i == dialogs.list.rowByPeer.constEnd()) {

View file

@ -103,7 +103,7 @@ void FileUploader::currentFailed() {
void FileUploader::killSessions() {
for (int i = 0; i < MTPUploadSessionsCount; ++i) {
MTP::stopSession(MTP::upl[i]);
MTP::stopSession(MTP::upl(i));
}
}
@ -187,9 +187,9 @@ void FileUploader::sendNext() {
}
mtpRequestId requestId;
if (i->docSize > UseBigFilesFrom) {
requestId = MTP::send(MTPupload_SaveBigFilePart(MTP_long(i->id()), MTP_int(i->docSentParts), MTP_int(i->docPartsCount), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl[todc]);
requestId = MTP::send(MTPupload_SaveBigFilePart(MTP_long(i->id()), MTP_int(i->docSentParts), MTP_int(i->docPartsCount), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl(todc));
} else {
requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(i->id()), MTP_int(i->docSentParts), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl[todc]);
requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(i->id()), MTP_int(i->docSentParts), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl(todc));
}
docRequestsSent.insert(requestId, i->docSentParts);
dcMap.insert(requestId, todc);
@ -200,7 +200,7 @@ void FileUploader::sendNext() {
} else {
UploadFileParts::iterator part = parts.begin();
mtpRequestId requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(partsOfId), MTP_int(part.key()), MTP_string(part.value())), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl[todc]);
mtpRequestId requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(partsOfId), MTP_int(part.key()), MTP_string(part.value())), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl(todc));
requestsSent.insert(requestId, part.value());
dcMap.insert(requestId, todc);
sentSize += part.value().size();
@ -246,7 +246,7 @@ void FileUploader::clear() {
dcMap.clear();
sentSize = 0;
for (int32 i = 0; i < MTPUploadSessionsCount; ++i) {
MTP::stopSession(MTP::upl[i]);
MTP::stopSession(MTP::upl(i));
sentSizes[i] = 0;
}
killSessionsTimer.stop();

View file

@ -627,20 +627,8 @@ namespace MTP {
const uint32 cfg = 1 * _mtp_internal::dcShift; // send(MTPhelp_GetConfig(), MTP::cfg + dc) - for dc enum
const uint32 lgt = 2 * _mtp_internal::dcShift; // send(MTPauth_LogOut(), MTP::lgt + dc) - for logout of guest dcs enum
const uint32 dld[MTPDownloadSessionsCount] = { // send(req, callbacks, MTP::dld[i] + dc) - for download
0x10 * _mtp_internal::dcShift,
0x11 * _mtp_internal::dcShift,
0x12 * _mtp_internal::dcShift,
0x13 * _mtp_internal::dcShift,
};
const uint32 upl[MTPUploadSessionsCount] = { // send(req, callbacks, MTP::upl[i] + dc) - for upload
0x20 * _mtp_internal::dcShift,
0x21 * _mtp_internal::dcShift,
0x22 * _mtp_internal::dcShift,
0x23 * _mtp_internal::dcShift,
};
const uint32 dldStart = dld[0], dldEnd = dld[(sizeof(dld) / sizeof(dld[0])) - 1] + _mtp_internal::dcShift;
const uint32 uplStart = upl[0], uplEnd = upl[(sizeof(upl) / sizeof(upl[0])) - 1] + _mtp_internal::dcShift;
const uint32 dldStart = dld(0), dldEnd = dld(MTPDownloadSessionsCount - 1) + _mtp_internal::dcShift;
const uint32 uplStart = upl(0), uplEnd = upl(MTPUploadSessionsCount - 1) + _mtp_internal::dcShift;
void start() {
if (started()) return;

View file

@ -70,8 +70,14 @@ namespace MTP {
extern const uint32 cfg; // send(MTPhelp_GetConfig(), MTP::cfg + dc) - for dc enum
extern const uint32 lgt; // send(MTPauth_LogOut(), MTP::lgt + dc) - for logout of guest dcs enum
extern const uint32 dld[MTPDownloadSessionsCount]; // send(req, callbacks, MTP::dld[i] + dc) - for download
extern const uint32 upl[MTPUploadSessionsCount]; // send(req, callbacks, MTP::upl[i] + dc) - for upload
inline const uint32 dld(int32 index) { // send(req, callbacks, MTP::dld(i) + dc) - for download
t_assert(index >= 0 && index < MTPDownloadSessionsCount);
return (0x10 + index) * _mtp_internal::dcShift;
};
inline const uint32 upl(int32 index) { // send(req, callbacks, MTP::upl[i] + dc) - for upload
t_assert(index >= 0 && index < MTPUploadSessionsCount);
return (0x20 + index) * _mtp_internal::dcShift;
};
extern const uint32 dldStart, dldEnd; // dc >= dldStart && dc < dldEnd => dc in dld
extern const uint32 uplStart, uplEnd; // dc >= uplStart && dc < uplEnd => dc in upl

View file

@ -2119,9 +2119,9 @@ void MTProtoConnectionPrivate::onSentSome(uint64 size) {
DEBUG_LOG(("Checking connect for request with size %1 bytes, delay will be %2").arg(size).arg(remain));
}
}
if (dc >= MTP::upl[0] && dc < MTP::upl[MTPUploadSessionsCount - 1] + _mtp_internal::dcShift) {
if (dc >= MTP::uplStart && dc < MTP::uplEnd) {
remain *= MTPUploadSessionsCount;
} else if (dc >= MTP::dld[0] && dc < MTP::dld[MTPDownloadSessionsCount - 1] + _mtp_internal::dcShift) {
} else if (dc >= MTP::dldStart && dc < MTP::dldEnd) {
remain *= MTPDownloadSessionsCount;
}
_waitForReceivedTimer.start(remain);

View file

@ -349,9 +349,9 @@ mtpFileLoader::mtpFileLoader(const StorageImageLocation *location, int32 size, L
, _location(location)
, _id(0)
, _access(0) {
LoaderQueues::iterator i = queues.find(MTP::dld[0] + _dc);
LoaderQueues::iterator i = queues.find(MTP::dld(0) + _dc);
if (i == queues.cend()) {
i = queues.insert(MTP::dld[0] + _dc, FileLoaderQueue(MaxFileQueries));
i = queues.insert(MTP::dld(0) + _dc, FileLoaderQueue(MaxFileQueries));
}
_queue = &i.value();
}
@ -365,9 +365,9 @@ mtpFileLoader::mtpFileLoader(int32 dc, const uint64 &id, const uint64 &access, L
, _location(0)
, _id(id)
, _access(access) {
LoaderQueues::iterator i = queues.find(MTP::dld[0] + _dc);
LoaderQueues::iterator i = queues.find(MTP::dld(0) + _dc);
if (i == queues.cend()) {
i = queues.insert(MTP::dld[0] + _dc, FileLoaderQueue(MaxFileQueries));
i = queues.insert(MTP::dld(0) + _dc, FileLoaderQueue(MaxFileQueries));
}
_queue = &i.value();
}
@ -405,7 +405,7 @@ bool mtpFileLoader::loadPart() {
App::app()->killDownloadSessionsStop(_dc);
mtpRequestId reqId = MTP::send(MTPupload_GetFile(MTPupload_getFile(loc, MTP_int(offset), MTP_int(limit))), rpcDone(&mtpFileLoader::partLoaded, offset), rpcFail(&mtpFileLoader::partFailed), MTP::dld[dcIndex] + _dc, 50);
mtpRequestId reqId = MTP::send(MTPupload_GetFile(MTPupload_getFile(loc, MTP_int(offset), MTP_int(limit))), rpcDone(&mtpFileLoader::partLoaded, offset), rpcFail(&mtpFileLoader::partFailed), MTP::dld(dcIndex) + _dc, 50);
++_queue->queries;
dr.v[dcIndex] += limit;