Changeset 219:85d956e2f418 in SMSSender


Ignore:
Timestamp:
May 10, 2012 10:48:16 PM (7 years ago)
Author:
Sämy Zehnder <saemy.zehnder@…>
Branch:
default
Message:
  • Fixed some multithreading issues in SNetworkHelper.
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • .hgignore

    r133 r219  
    66*.tmp
    77ui_*.h
     8*.pro.user
    89deploy/win/*.exe
    910
  • gateways/Schoolnet/src/business/bchttphelper.cpp

    r218 r219  
    8888
    8989QByteArray BCHttpHelper::lastResponse() {
    90     QMutexLocker locker(&lastResponseLock_);
    91 
    9290    return lastResponse_.value(QThread::currentThread());
    9391}
    9492
    9593void BCHttpHelper::setLastResponse(const QByteArray& lastResponse) {
    96     QMutexLocker locker(&lastResponseLock_);
    97 
    9894    lastResponse_.insert(QThread::currentThread(), lastResponse);
    9995}
  • gateways/Schoolnet/src/business/bchttphelper.h

    r218 r219  
    4949
    5050private:
    51     QMutex                     lastResponseLock_;
    5251    QMap<QThread*, QByteArray> lastResponse_;
    5352};
  • lib/datatypes/src/snetworkhelper.cpp

    r218 r219  
    3939}
    4040
    41 
    42 QMap<QThread *, QNetworkAccessManager *> SNetworkHelper::networkAccessManager_ = QMap<QThread *, QNetworkAccessManager *>();
     41SNetworkHelper::~SNetworkHelper() {
     42    foreach (QThread* thread, networkAccessManager_.keys()) {
     43        networkAccessManager_.take(thread)->deleteLater();
     44    }
     45}
     46
    4347/**
    4448 * QNetworkAccessManager can not be accessed from different threads simultaneous. Therefore we create an own instance
     
    4751QNetworkAccessManager &SNetworkHelper::networkAccessManager() {
    4852    if (!networkAccessManager_.contains(QThread::currentThread())) {
    49         QNetworkAccessManager* nam = new QNetworkAccessManager(this);
     53        QNetworkAccessManager* nam = new QNetworkAccessManager;
    5054        nam->setCookieJar(sharedCookieJar_);
    5155        sharedCookieJar_->setParent(this); // setCookieJar takes ownership
    5256
    53         connect(QThread::currentThread(), SIGNAL(terminated()), this, SLOT(onThreadTerminated()), Qt::DirectConnection);
     57        connect(QThread::currentThread(), SIGNAL(terminated()), this, SLOT(onThreadTerminated()));
    5458        networkAccessManager_.insert(QThread::currentThread(), nam);
    5559
  • lib/datatypes/src/snetworkhelper.h

    r218 r219  
    5858public:
    5959    SNetworkHelper(QObject *parent);
     60    ~SNetworkHelper();
    6061
    6162    QNetworkAccessManager &networkAccessManager();
     
    111112    const QString MULTIPART_BOUNDARY;
    112113
    113     QNetworkCookieJar *                             sharedCookieJar_;
    114     static QMap<QThread *, QNetworkAccessManager *> networkAccessManager_;
    115     QMap<QNetworkAccessManager *, QUrl>             lastUrl_;
     114    QNetworkCookieJar *                      sharedCookieJar_;
     115    QMap<QThread *, QNetworkAccessManager *> networkAccessManager_;
     116    QMap<QNetworkAccessManager *, QUrl>      lastUrl_;
    116117
    117118    HeadersMap        defaultHeaders_;
Note: See TracChangeset for help on using the changeset viewer.