source: ntrip/trunk/BNC/bncnetqueryudp0.cpp@ 1784

Last change on this file since 1784 was 1784, checked in by mervart, 15 years ago

* empty log message *

File size: 2.2 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: bncNetQueryUdp0
6 *
7 * Purpose: Blocking Network Requests (plain UDP, no NTRIP)
8 *
9 * Author: L. Mervart
10 *
11 * Created: 04-Feb-2009
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include "bncnetqueryudp0.h"
18
19using namespace std;
20
21// Constructor
22////////////////////////////////////////////////////////////////////////////
23bncNetQueryUdp0::bncNetQueryUdp0() {
24 _udpSocket = 0;
25}
26
27// Destructor
28////////////////////////////////////////////////////////////////////////////
29bncNetQueryUdp0::~bncNetQueryUdp0() {
30 delete _udpSocket;
31}
32
33//
34////////////////////////////////////////////////////////////////////////////
35void bncNetQueryUdp0::stop() {
36#ifndef sparc
37 if (_udpSocket) {
38 _udpSocket->abort();
39 }
40#endif
41 _status = finished;
42}
43
44//
45////////////////////////////////////////////////////////////////////////////
46void bncNetQueryUdp0::waitForRequestResult(const QUrl&, QByteArray&) {
47}
48
49//
50////////////////////////////////////////////////////////////////////////////
51void 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 }
67 }
68}
69
70// Connect to Caster, send the Request
71////////////////////////////////////////////////////////////////////////////
72void bncNetQueryUdp0::startRequest(const QUrl& url, const QByteArray& /* gga */) {
73
74 _status = running;
75
76 // Default scheme and path
77 // -----------------------
78 _url = url;
79 if (_url.scheme().isEmpty()) {
80 _url.setScheme("http");
81 }
82 if (_url.path().isEmpty()) {
83 _url.setPath("/");
84 }
85
86 delete _udpSocket;
87 _udpSocket = new QUdpSocket();
88 _udpSocket->connectToHost(_url.host(), _url.port());
89}
90
Note: See TracBrowser for help on using the repository browser.