Subsonic: Make network replies timeout after 30 seconds

Fixes #754
This commit is contained in:
Jonas Kvinge 2021-09-05 21:47:00 +02:00
parent 2280a30ba9
commit e45e202c5e
2 changed files with 7 additions and 0 deletions

View File

@ -47,6 +47,7 @@
#include "core/song.h" #include "core/song.h"
#include "core/timeconstants.h" #include "core/timeconstants.h"
#include "core/imageutils.h" #include "core/imageutils.h"
#include "core/networktimeouts.h"
#include "covermanager/albumcoverloader.h" #include "covermanager/albumcoverloader.h"
#include "subsonicservice.h" #include "subsonicservice.h"
#include "subsonicurlhandler.h" #include "subsonicurlhandler.h"
@ -63,6 +64,7 @@ SubsonicRequest::SubsonicRequest(SubsonicService *service, SubsonicUrlHandler *u
url_handler_(url_handler), url_handler_(url_handler),
app_(app), app_(app),
network_(new QNetworkAccessManager), network_(new QNetworkAccessManager),
timeouts_(new NetworkTimeouts(30000, this)),
finished_(false), finished_(false),
albums_requests_active_(0), albums_requests_active_(0),
album_songs_requests_active_(0), album_songs_requests_active_(0),
@ -155,6 +157,7 @@ void SubsonicRequest::FlushAlbumsRequests() {
QNetworkReply *reply = CreateGetRequest(QString("getAlbumList2"), params); QNetworkReply *reply = CreateGetRequest(QString("getAlbumList2"), params);
replies_ << reply; replies_ << reply;
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, request]() { AlbumsReplyReceived(reply, request.offset, request.size); }); QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, request]() { AlbumsReplyReceived(reply, request.offset, request.size); });
timeouts_->AddReply(reply);
} }
@ -347,6 +350,7 @@ void SubsonicRequest::FlushAlbumSongsRequests() {
QNetworkReply *reply = CreateGetRequest(QString("getAlbum"), params); QNetworkReply *reply = CreateGetRequest(QString("getAlbum"), params);
replies_ << reply; replies_ << reply;
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, request]() { AlbumSongsReplyReceived(reply, request.artist_id, request.album_id, request.album_artist); }); QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, request]() { AlbumSongsReplyReceived(reply, request.artist_id, request.album_id, request.album_artist); });
timeouts_->AddReply(reply);
} }
@ -748,6 +752,7 @@ void SubsonicRequest::FlushAlbumCoverRequests() {
QNetworkReply *reply = network_->get(req); QNetworkReply *reply = network_->get(req);
album_cover_replies_ << reply; album_cover_replies_ << reply;
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, request]() { AlbumCoverReceived(reply, request.url, request.filename); }); QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, request]() { AlbumCoverReceived(reply, request.url, request.filename); });
timeouts_->AddReply(reply);
} }

View File

@ -47,6 +47,7 @@ class QNetworkReply;
class Application; class Application;
class SubsonicService; class SubsonicService;
class SubsonicUrlHandler; class SubsonicUrlHandler;
class NetworkTimeouts;
class SubsonicRequest : public SubsonicBaseRequest { class SubsonicRequest : public SubsonicBaseRequest {
Q_OBJECT Q_OBJECT
@ -118,6 +119,7 @@ class SubsonicRequest : public SubsonicBaseRequest {
SubsonicUrlHandler *url_handler_; SubsonicUrlHandler *url_handler_;
Application *app_; Application *app_;
std::unique_ptr<QNetworkAccessManager> network_; std::unique_ptr<QNetworkAccessManager> network_;
NetworkTimeouts *timeouts_;
bool finished_; bool finished_;