Changeset 1363 in ntrip


Ignore:
Timestamp:
Dec 27, 2008, 10:32:32 PM (15 years ago)
Author:
mervart
Message:

* empty log message *

Location:
trunk/BNC
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bncsocket.cpp

    r1362 r1363  
    3333  _socket    = 0;
    3434  _http      = 0;
    35   _buffer    = 0;
    36   _eventLoop = 0;
     35  connect(this, SIGNAL(quitEventLoop()), &_eventLoop, SLOT(quit()));
    3736}
    3837
     
    4342  delete _socket;
    4443  delete _http;
    45   delete _buffer;
    46   delete _eventLoop;
    4744}
    4845
     
    7067qint64 bncSocket::bytesAvailable() const {
    7168  if      (_http) {
    72     return _http->bytesAvailable();
     69    return _buffer.size();
    7370  }
    7471  else if (_socket) {
     
    8380////////////////////////////////////////////////////////////////////////////
    8481bool 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    }
    8790  }
    8891  else if (_socket) {
     
    97100////////////////////////////////////////////////////////////////////////////
    98101QByteArray bncSocket::readLine(qint64 maxlen) {
    99   if      (_buffer) {
    100     return _buffer->readLine(maxlen);
     102  if      (_http) {
     103    return "";
     104    ///    return _buffer->readLine(maxlen);
    101105  }
    102106  else if (_socket) {
     
    110114//
    111115////////////////////////////////////////////////////////////////////////////
    112 bool bncSocket::waitForReadyRead(int msecs) {
    113   if (_socket) {
    114     return _socket->waitForReadyRead(msecs);
    115   }
    116   else {
    117     return false;
     116void 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);
    118127  }
    119128}
     
    268277         << _http->errorString().toAscii().data() << endl;
    269278  }
    270   cout << _buffer->data().data();
    271 }
    272 
    273 //
    274 ////////////////////////////////////////////////////////////////////////////
    275 void bncSocket::slotReadyRead() {
    276   cout << "slotReadyRead " << _buffer->size() << endl;
     279}
     280
     281//
     282////////////////////////////////////////////////////////////////////////////
     283void 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();
    277289}
    278290
     
    285297         << _http->errorString().toAscii().data() << endl;
    286298  }
    287   emit quitEventLoop();
    288299}
    289300
     
    294305                         int timeOut, QString& msg) {
    295306
    296   _eventLoop = new QEventLoop();
    297   connect(this, SIGNAL(quitEventLoop()), _eventLoop, SLOT(quit()));
    298307
    299308  delete _http;
     
    322331  connect(_http, SIGNAL(requestFinished(int, bool)),
    323332          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);
    332337
    333338  cout << "before return" << endl;
  • trunk/BNC/bncsocket.h

    r1362 r1363  
    1616  bool       canReadLine() const;
    1717  QByteArray readLine(qint64 maxlen = 0);
    18   bool       waitForReadyRead(int msecs = 30000);
     18  void       waitForReadyRead(int msecs = 30000);
    1919  qint64     read(char *data, qint64 maxlen);
    2020  QAbstractSocket::SocketState state() const;
     
    3131  void slotDone(bool);
    3232  void slotRequestFinished(int, bool);
    33   void slotReadyRead();
     33  void slotReadyRead(const QHttpResponseHeader&);
    3434
    3535 private:
     
    4040  QTcpSocket* _socket;
    4141  QHttp*      _http;     
    42   QBuffer*    _buffer;
    43   QEventLoop* _eventLoop;
     42  QByteArray  _buffer;
     43  QEventLoop  _eventLoop;
    4444};
    4545
  • trunk/BNC/bnctabledlg.cpp

    r1358 r1363  
    3939 * -----------------------------------------------------------------------*/
    4040
     41#include <iostream>
     42
    4143#include "bnctabledlg.h"
    4244#include "bncgetthread.h"
    4345#include "bncsocket.h"
     46
     47using namespace std;
    4448
    4549// Constructor
     
    210214    }
    211215    else {
     216      cout << "before waitForReadyRead" << endl;
    212217      socket->waitForReadyRead(timeOut);
     218      cout << "after waitForReadyRead" << " "
     219           << socket->bytesAvailable() << endl;
    213220      if (socket->bytesAvailable() > 0) {
    214221        continue;
Note: See TracChangeset for help on using the changeset viewer.