Changeset 1363 in ntrip
- Timestamp:
- Dec 27, 2008, 10:32:32 PM (16 years ago)
- Location:
- trunk/BNC
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/bncsocket.cpp
r1362 r1363 33 33 _socket = 0; 34 34 _http = 0; 35 _buffer = 0; 36 _eventLoop = 0; 35 connect(this, SIGNAL(quitEventLoop()), &_eventLoop, SLOT(quit())); 37 36 } 38 37 … … 43 42 delete _socket; 44 43 delete _http; 45 delete _buffer;46 delete _eventLoop;47 44 } 48 45 … … 70 67 qint64 bncSocket::bytesAvailable() const { 71 68 if (_http) { 72 return _ http->bytesAvailable();69 return _buffer.size(); 73 70 } 74 71 else if (_socket) { … … 83 80 //////////////////////////////////////////////////////////////////////////// 84 81 bool bncSocket::canReadLine() const { 85 if (_buffer) { 86 return _buffer->canReadLine(); 82 if (_http) { 83 cout << "canReadLine " << _buffer.size() << endl; 84 if (_buffer.indexOf('\n') != -1) { 85 return true; 86 } 87 else { 88 return false; 89 } 87 90 } 88 91 else if (_socket) { … … 97 100 //////////////////////////////////////////////////////////////////////////// 98 101 QByteArray bncSocket::readLine(qint64 maxlen) { 99 if (_buffer) { 100 return _buffer->readLine(maxlen); 102 if (_http) { 103 return ""; 104 /// return _buffer->readLine(maxlen); 101 105 } 102 106 else if (_socket) { … … 110 114 // 111 115 //////////////////////////////////////////////////////////////////////////// 112 bool bncSocket::waitForReadyRead(int msecs) { 113 if (_socket) { 114 return _socket->waitForReadyRead(msecs); 115 } 116 else { 117 return false; 116 void bncSocket::waitForReadyRead(int msecs) { 117 if (_http) { 118 if (bytesAvailable() > 0) { 119 return; 120 } 121 else { 122 _eventLoop.exec(QEventLoop::ExcludeUserInputEvents); 123 } 124 } 125 else if (_socket) { 126 _socket->waitForReadyRead(msecs); 118 127 } 119 128 } … … 268 277 << _http->errorString().toAscii().data() << endl; 269 278 } 270 cout << _buffer->data().data(); 271 } 272 273 // 274 //////////////////////////////////////////////////////////////////////////// 275 void bncSocket::slotReadyRead() { 276 cout << "slotReadyRead " << _buffer->size() << endl; 279 } 280 281 // 282 //////////////////////////////////////////////////////////////////////////// 283 void bncSocket::slotReadyRead(const QHttpResponseHeader&) { 284 cout << "slotReadyRead " << _buffer.size() << " " 285 << _http->bytesAvailable() << endl; 286 _buffer.append(_http->readAll()); 287 cout << _buffer.data(); 288 emit quitEventLoop(); 277 289 } 278 290 … … 285 297 << _http->errorString().toAscii().data() << endl; 286 298 } 287 emit quitEventLoop();288 299 } 289 300 … … 294 305 int timeOut, QString& msg) { 295 306 296 _eventLoop = new QEventLoop();297 connect(this, SIGNAL(quitEventLoop()), _eventLoop, SLOT(quit()));298 307 299 308 delete _http; … … 322 331 connect(_http, SIGNAL(requestFinished(int, bool)), 323 332 this, SLOT(slotRequestFinished(int, bool))); 324 325 _buffer = new QBuffer(); 326 _buffer->open(QBuffer::ReadWrite); 327 connect(_buffer, SIGNAL(readyRead()), this, SLOT(slotReadyRead())); 328 329 _http->request(request, 0, _buffer); 330 331 /// _eventLoop->exec(QEventLoop::ExcludeUserInputEvents); 333 connect(_http, SIGNAL(readyRead(const QHttpResponseHeader&)), 334 this, SLOT(slotReadyRead(const QHttpResponseHeader&))); 335 336 _http->request(request); 332 337 333 338 cout << "before return" << endl; -
trunk/BNC/bncsocket.h
r1362 r1363 16 16 bool canReadLine() const; 17 17 QByteArray readLine(qint64 maxlen = 0); 18 boolwaitForReadyRead(int msecs = 30000);18 void waitForReadyRead(int msecs = 30000); 19 19 qint64 read(char *data, qint64 maxlen); 20 20 QAbstractSocket::SocketState state() const; … … 31 31 void slotDone(bool); 32 32 void slotRequestFinished(int, bool); 33 void slotReadyRead( );33 void slotReadyRead(const QHttpResponseHeader&); 34 34 35 35 private: … … 40 40 QTcpSocket* _socket; 41 41 QHttp* _http; 42 QB uffer*_buffer;43 QEventLoop *_eventLoop;42 QByteArray _buffer; 43 QEventLoop _eventLoop; 44 44 }; 45 45 -
trunk/BNC/bnctabledlg.cpp
r1358 r1363 39 39 * -----------------------------------------------------------------------*/ 40 40 41 #include <iostream> 42 41 43 #include "bnctabledlg.h" 42 44 #include "bncgetthread.h" 43 45 #include "bncsocket.h" 46 47 using namespace std; 44 48 45 49 // Constructor … … 210 214 } 211 215 else { 216 cout << "before waitForReadyRead" << endl; 212 217 socket->waitForReadyRead(timeOut); 218 cout << "after waitForReadyRead" << " " 219 << socket->bytesAvailable() << endl; 213 220 if (socket->bytesAvailable() > 0) { 214 221 continue;
Note:
See TracChangeset
for help on using the changeset viewer.