Changeset 1785 in ntrip
- Timestamp:
- Apr 8, 2009, 2:51:36 PM (16 years ago)
- Location:
- trunk/BNC
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/bncnetqueryudp0.cpp
r1784 r1785 15 15 * -----------------------------------------------------------------------*/ 16 16 17 #include <iostream> 18 17 19 #include "bncnetqueryudp0.h" 18 20 … … 23 25 bncNetQueryUdp0::bncNetQueryUdp0() { 24 26 _udpSocket = 0; 27 _eventLoop = new QEventLoop(this); 28 29 _keepAlive[ 0] = 128; 30 _keepAlive[ 1] = 96; 31 for (int ii = 2; ii <=11; ii++) { 32 _keepAlive[ii] = 0; 33 } 25 34 } 26 35 … … 28 37 //////////////////////////////////////////////////////////////////////////// 29 38 bncNetQueryUdp0::~bncNetQueryUdp0() { 39 delete _eventLoop; 30 40 delete _udpSocket; 31 41 } … … 34 44 //////////////////////////////////////////////////////////////////////////// 35 45 void bncNetQueryUdp0::stop() { 36 #ifndef sparc 37 if (_udpSocket) { 38 _udpSocket->abort(); 39 } 40 #endif 46 _eventLoop->quit(); 41 47 _status = finished; 42 48 } … … 50 56 //////////////////////////////////////////////////////////////////////////// 51 57 void bncNetQueryUdp0::waitForReadyRead(QByteArray& outData) { 52 if (_udpSocket) { 53 while (true) {54 int nBytes = _udpSocket->bytesAvailable();55 if (nBytes > 0) {56 outData = _udpSocket->readAll();57 return;58 } 59 else if (!_udpSocket->waitForReadyRead(_timeOut)) {60 delete _udpSocket;61 _udpSocket = 0;62 _status = error;63 emit newMessage(_url.path().toAscii() + " read timeout", true);64 return; 65 }66 }58 59 // Wait Loop 60 // --------- 61 if (!_udpSocket->hasPendingDatagrams()) { 62 _eventLoop->exec(); 63 } 64 65 // Append Data 66 // ----------- 67 QByteArray datagram; 68 datagram.resize(_udpSocket->pendingDatagramSize()); 69 _udpSocket->readDatagram(datagram.data(), datagram.size()); 70 71 if (datagram.size() > 0) { 72 outData.append(datagram); 67 73 } 68 74 } … … 84 90 } 85 91 86 delete _udpSocket; 87 _udpSocket = new QUdpSocket(); 88 _udpSocket->connectToHost(_url.host(), _url.port()); 92 delete _udpSocket; _udpSocket = 0; 93 94 QHostInfo hInfo = QHostInfo::fromName(_url.host()); 95 if (!hInfo.addresses().isEmpty()) { 96 _address = hInfo.addresses().first(); 97 _udpSocket = new QUdpSocket(); 98 _udpSocket->bind(0); 99 connect(_udpSocket, SIGNAL(readyRead()), _eventLoop, SLOT(quit())); 100 101 _udpSocket->writeDatagram(_keepAlive, 12, _address, _url.port()); 102 } 89 103 } 90 104 -
trunk/BNC/bncnetqueryudp0.h
r1783 r1785 16 16 private: 17 17 QUdpSocket* _udpSocket; 18 QEventLoop* _eventLoop; 19 QHostAddress _address; 20 char _keepAlive[12]; 18 21 }; 19 22
Note:
See TracChangeset
for help on using the changeset viewer.