comparison data/fileio/FileSource.cpp @ 497:b6dc6c7f402c

Various fixes: * Fix handling of HTTP redirects (avoiding crashes... I hope) * Fix failure to delete FFT models when a feature extraction model transformer was abandoned (also a cause of crashes in the past) * Fix deadlock when said transform was abandoned before its source model was ready because the session was being cleared (and so the source model would never be ready)
author Chris Cannam
date Fri, 28 Nov 2008 13:36:13 +0000
parents 05383ee78f3e
children bd7c46636bd0
comparison
equal deleted inserted replaced
496:05383ee78f3e 497:b6dc6c7f402c
27 #include <QHttpResponseHeader> 27 #include <QHttpResponseHeader>
28 28
29 #include <iostream> 29 #include <iostream>
30 #include <cstdlib> 30 #include <cstdlib>
31 31
32 #define DEBUG_FILE_SOURCE 1 32 //#define DEBUG_FILE_SOURCE 1
33 33
34 int 34 int
35 FileSource::m_count = 0; 35 FileSource::m_count = 0;
36 36
37 QMutex 37 QMutex
106 106
107 if (!isRemote()) { 107 if (!isRemote()) {
108 emit statusAvailable(); 108 emit statusAvailable();
109 emit ready(); 109 emit ready();
110 } 110 }
111
112 std::cerr << "FileSource::FileSource(string) exiting" << std::endl;
111 } 113 }
112 114
113 FileSource::FileSource(QUrl url, ProgressReporter *reporter) : 115 FileSource::FileSource(QUrl url, ProgressReporter *reporter) :
114 m_url(url), 116 m_url(url),
115 m_ftp(0), 117 m_ftp(0),
132 m_errorString = tr("Unsupported scheme in URL"); 134 m_errorString = tr("Unsupported scheme in URL");
133 return; 135 return;
134 } 136 }
135 137
136 init(); 138 init();
139
140 std::cerr << "FileSource::FileSource(url) exiting" << std::endl;
137 } 141 }
138 142
139 FileSource::FileSource(const FileSource &rf) : 143 FileSource::FileSource(const FileSource &rf) :
140 QObject(), 144 QObject(),
141 m_url(rf.m_url), 145 m_url(rf.m_url),
180 m_lastStatus = 404; 184 m_lastStatus = 404;
181 } 185 }
182 } 186 }
183 187
184 m_done = true; 188 m_done = true;
189
190 std::cerr << "FileSource::FileSource(copy ctor) exiting" << std::endl;
185 } 191 }
186 192
187 FileSource::~FileSource() 193 FileSource::~FileSource()
188 { 194 {
189 #ifdef DEBUG_FILE_SOURCE 195 #ifdef DEBUG_FILE_SOURCE
309 315
310 void 316 void
311 FileSource::initHttp() 317 FileSource::initHttp()
312 { 318 {
313 m_ok = true; 319 m_ok = true;
314 m_http = new QHttp(m_url.host(), m_url.port(80)); 320 int port = m_url.port();
321 m_http = new QHttp(m_url.host(), port < 0 ? 80 : port);
315 connect(m_http, SIGNAL(done(bool)), this, SLOT(done(bool))); 322 connect(m_http, SIGNAL(done(bool)), this, SLOT(done(bool)));
316 connect(m_http, SIGNAL(dataReadProgress(int, int)), 323 connect(m_http, SIGNAL(dataReadProgress(int, int)),
317 this, SLOT(dataReadProgress(int, int))); 324 this, SLOT(dataReadProgress(int, int)));
318 connect(m_http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), 325 connect(m_http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
319 this, SLOT(httpResponseHeaderReceived(const QHttpResponseHeader &))); 326 this, SLOT(httpResponseHeaderReceived(const QHttpResponseHeader &)));
473 FileSource::waitForData() 480 FileSource::waitForData()
474 { 481 {
475 while (m_ok && !m_done) { 482 while (m_ok && !m_done) {
476 // std::cerr << "FileSource::waitForData: calling QApplication::processEvents" << std::endl; 483 // std::cerr << "FileSource::waitForData: calling QApplication::processEvents" << std::endl;
477 QCoreApplication::processEvents(); 484 QCoreApplication::processEvents();
485 usleep(10000);
478 } 486 }
479 } 487 }
480 488
481 void 489 void
482 FileSource::setLeaveLocalFile(bool leave) 490 FileSource::setLeaveLocalFile(bool leave)
543 } 551 }
544 552
545 void 553 void
546 FileSource::httpResponseHeaderReceived(const QHttpResponseHeader &resp) 554 FileSource::httpResponseHeaderReceived(const QHttpResponseHeader &resp)
547 { 555 {
548 m_lastStatus = resp.statusCode(); 556 std::cerr << "FileSource::httpResponseHeaderReceived" << std::endl;
549 if (m_lastStatus / 100 == 3) { 557
558 if (resp.statusCode() / 100 == 3) {
550 QString location = resp.value("Location"); 559 QString location = resp.value("Location");
551 #ifdef DEBUG_FILE_SOURCE 560 #ifdef DEBUG_FILE_SOURCE
552 std::cerr << "FileSource::responseHeaderReceived: redirect to \"" 561 std::cerr << "FileSource::responseHeaderReceived: redirect to \""
553 << location.toStdString() << "\" received" << std::endl; 562 << location.toStdString() << "\" received" << std::endl;
554 #endif 563 #endif
555 if (location != "") { 564 if (location != "") {
556 QUrl newUrl(location); 565 QUrl newUrl(location);
557 if (newUrl != m_url) { 566 if (newUrl != m_url) {
567 cleanup();
568 deleteCacheFile();
558 m_url = newUrl; 569 m_url = newUrl;
570 m_localFile = 0;
559 m_lastStatus = 0; 571 m_lastStatus = 0;
560 disconnect(m_http, SIGNAL(done(bool)), this, SLOT(done(bool))); 572 m_done = false;
561 disconnect(m_http, SIGNAL(dataReadProgress(int, int)), 573 m_refCounted = false;
562 this, SLOT(dataReadProgress(int, int)));
563 m_http->abort();
564 m_http->deleteLater();
565 m_http = 0;
566 init(); 574 init();
567 return; 575 return;
568 } 576 }
569 } 577 }
570 } 578 }
579
580 m_lastStatus = resp.statusCode();
571 if (m_lastStatus / 100 >= 4) { 581 if (m_lastStatus / 100 >= 4) {
572 m_errorString = QString("%1 %2") 582 m_errorString = QString("%1 %2")
573 .arg(resp.statusCode()).arg(resp.reasonPhrase()); 583 .arg(resp.statusCode()).arg(resp.reasonPhrase());
574 #ifdef DEBUG_FILE_SOURCE 584 #ifdef DEBUG_FILE_SOURCE
575 std::cerr << "FileSource::responseHeaderReceived: " 585 std::cerr << "FileSource::responseHeaderReceived: "