Changeset 1848 in ntrip
- Timestamp:
- Jun 29, 2009, 11:17:23 AM (15 years ago)
- Location:
- trunk/BNC
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/bncnetqueryv1.cpp
r1816 r1848 28 28 //////////////////////////////////////////////////////////////////////////// 29 29 bncNetQueryV1::bncNetQueryV1() { 30 _socket = 0; 31 _timeOut = 20000; 30 _socket = 0; 31 _eventLoop = new QEventLoop(this); 32 _timeOut = 20000; 32 33 } 33 34 … … 36 37 bncNetQueryV1::~bncNetQueryV1() { 37 38 delete _socket; 39 delete _eventLoop; 38 40 } 39 41 … … 41 43 //////////////////////////////////////////////////////////////////////////// 42 44 void bncNetQueryV1::stop() { 45 _eventLoop->quit(); 43 46 #ifndef sparc 44 47 if (_socket) { … … 49 52 } 50 53 54 // End of Request 55 //////////////////////////////////////////////////////////////////////////// 56 void bncNetQueryV1::slotFinished() { 57 _eventLoop->quit(); 58 if (_socket) { 59 _outData = _socket->readAll(); 60 _status = finished; 61 } 62 } 63 51 64 // 52 65 //////////////////////////////////////////////////////////////////////////// 53 void bncNetQueryV1::waitForRequestResult(const QUrl&, QByteArray&) { 66 void bncNetQueryV1::waitForRequestResult(const QUrl& url, QByteArray& outData){ 67 68 delete _socket; 69 _socket = new QTcpSocket(); 70 71 connect(_socket, SIGNAL(disconnected()), this, SLOT(slotFinished())); 72 73 startRequestPrivate(url, "", true); 74 75 _eventLoop->exec(); 76 77 delete _socket; _socket = 0; 78 79 outData = _outData; 80 _outData.clear(); 54 81 } 55 82 … … 83 110 //////////////////////////////////////////////////////////////////////////// 84 111 void bncNetQueryV1::startRequest(const QUrl& url, const QByteArray& gga) { 112 startRequestPrivate(url, gga, false); 113 } 114 115 // Connect to Caster, send the Request 116 //////////////////////////////////////////////////////////////////////////// 117 void bncNetQueryV1::startRequestPrivate(const QUrl& url, 118 const QByteArray& gga, 119 bool sendRequestOnly) { 85 120 86 121 _status = running; 87 122 88 delete _socket; 89 _socket = new QTcpSocket(); 123 if (!sendRequestOnly) { 124 delete _socket; 125 _socket = new QTcpSocket(); 126 } 90 127 91 128 // Default scheme and path … … 161 198 // Read Caster Response 162 199 // -------------------- 163 bool proxyResponse = false; 164 QStringList response; 165 while (true) { 166 if (_socket->canReadLine()) { 167 QString line = _socket->readLine(); 168 169 if (line.indexOf("ICY 200 OK") == -1 && 170 line.indexOf("HTTP") != -1 && 171 line.indexOf("200 OK") != -1 ) { 172 proxyResponse = true; 173 } 174 175 if (!proxyResponse && !line.trimmed().isEmpty()) { 176 response.push_back(line); 177 } 178 179 if (line.trimmed().isEmpty()) { 180 if (proxyResponse) { 181 proxyResponse = false; 182 } 183 else { 200 if (!sendRequestOnly) { 201 bool proxyResponse = false; 202 QStringList response; 203 while (true) { 204 if (_socket->canReadLine()) { 205 QString line = _socket->readLine(); 206 207 if (line.indexOf("ICY 200 OK") == -1 && 208 line.indexOf("HTTP") != -1 && 209 line.indexOf("200 OK") != -1 ) { 210 proxyResponse = true; 211 } 212 213 if (!proxyResponse && !line.trimmed().isEmpty()) { 214 response.push_back(line); 215 } 216 217 if (line.trimmed().isEmpty()) { 218 if (proxyResponse) { 219 proxyResponse = false; 220 } 221 else { 222 break; 223 } 224 } 225 226 if (line.indexOf("Unauthorized") != -1) { 184 227 break; 185 } 186 } 187 188 if (line.indexOf("Unauthorized") != -1) { 189 break; 190 } 191 192 if (!proxyResponse && 193 line.indexOf("200 OK") != -1 && 194 line.indexOf("SOURCETABLE") == -1) { 195 response.clear(); 196 if (_socket->canReadLine()) { 197 _socket->readLine(); 198 } 199 break; 228 } 229 230 if (!proxyResponse && 231 line.indexOf("200 OK") != -1 && 232 line.indexOf("SOURCETABLE") == -1) { 233 response.clear(); 234 if (_socket->canReadLine()) { 235 _socket->readLine(); 236 } 237 break; 238 } 239 } 240 else if (!_socket->waitForReadyRead(_timeOut)) { 241 delete _socket; 242 _socket = 0; 243 _status = error; 244 emit newMessage(_url.path().toAscii().replace(0,1,"") 245 + ": Response timeout", true); 246 return; 200 247 } 201 248 } 202 else if (!_socket->waitForReadyRead(_timeOut)) {249 if (response.size() > 0) { 203 250 delete _socket; 204 251 _socket = 0; 205 252 _status = error; 206 253 emit newMessage(_url.path().toAscii().replace(0,1,"") 207 + ": Response timeout", true);208 return;254 + ": Wrong caster response\n" 255 + response.join("").toAscii(), true); 209 256 } 210 257 } 211 if (response.size() > 0) { 212 delete _socket; 213 _socket = 0; 214 _status = error; 215 emit newMessage(_url.path().toAscii().replace(0,1,"") 216 + ": Wrong caster response\n" 217 + response.join("").toAscii(), true); 218 } 219 } 220 258 } 259 -
trunk/BNC/bncnetqueryv1.h
r1716 r1848 5 5 6 6 class bncNetQueryV1 : public bncNetQuery { 7 Q_OBJECT 8 7 9 public: 8 10 bncNetQueryV1(); … … 14 16 virtual void waitForReadyRead(QByteArray& outData); 15 17 18 private slots: 19 void slotFinished(); 20 16 21 private: 22 void startRequestPrivate(const QUrl& url, const QByteArray& gga, 23 bool sendRequestOnly); 24 QEventLoop* _eventLoop; 17 25 QTcpSocket* _socket; 26 QByteArray _outData; 18 27 }; 19 28 -
trunk/BNC/bncrinex.cpp
r1778 r1848 54 54 #include "bnctabledlg.h" 55 55 #include "bncgetthread.h" 56 #include "bncnetqueryv 2.h"56 #include "bncnetqueryv1.h" 57 57 #include "bncsettings.h" 58 58 #include "RTCM3/rtcm3torinex.h" … … 162 162 } 163 163 164 bncNetQueryV 2query;164 bncNetQueryV1 query; 165 165 QByteArray outData; 166 166 query.waitForRequestResult(url, outData); -
trunk/BNC/bnctabledlg.cpp
r1821 r1848 43 43 #include "bnctabledlg.h" 44 44 #include "bncgetthread.h" 45 #include "bncnetqueryv 2.h"45 #include "bncnetqueryv1.h" 46 46 #include "bncsettings.h" 47 47 … … 196 196 url.setPath("/"); 197 197 198 bncNetQueryV 2query;198 bncNetQueryV1 query; 199 199 QByteArray outData; 200 200 query.waitForRequestResult(url, outData); … … 448 448 url.setPath("/"); 449 449 450 bncNetQueryV 2query;450 bncNetQueryV1 query; 451 451 QByteArray outData; 452 452 query.waitForRequestResult(url, outData);
Note:
See TracChangeset
for help on using the changeset viewer.