| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/socket/qudpsocket.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | class QUdpSocketPrivate : public QAbstractSocketPrivate | - | ||||||||||||
| 4 | { | - | ||||||||||||
| 5 | inline QUdpSocket* q_func() { return static_cast<QUdpSocket *>(q_ptr); } inline const QUdpSocket* q_func() const { return static_cast<const QUdpSocket *>(q_ptr); } friend class QUdpSocket; | - | ||||||||||||
| 6 | - | |||||||||||||
| 7 | bool doEnsureInitialized(const QHostAddress &bindAddress, quint16 bindPort, | - | ||||||||||||
| 8 | const QHostAddress &remoteAddress); | - | ||||||||||||
| 9 | public: | - | ||||||||||||
| 10 | inline bool ensureInitialized(const QHostAddress &bindAddress, quint16 bindPort) | - | ||||||||||||
| 11 | { return never executed: doEnsureInitialized(bindAddress, bindPort, QHostAddress());return doEnsureInitialized(bindAddress, bindPort, QHostAddress());never executed: }return doEnsureInitialized(bindAddress, bindPort, QHostAddress()); | 0 | ||||||||||||
| 12 | - | |||||||||||||
| 13 | inline bool ensureInitialized(const QHostAddress &remoteAddress) | - | ||||||||||||
| 14 | { return never executed: doEnsureInitialized(QHostAddress(), 0, remoteAddress);return doEnsureInitialized(QHostAddress(), 0, remoteAddress);never executed: }return doEnsureInitialized(QHostAddress(), 0, remoteAddress); | 0 | ||||||||||||
| 15 | }; | - | ||||||||||||
| 16 | - | |||||||||||||
| 17 | bool QUdpSocketPrivate::doEnsureInitialized(const QHostAddress &bindAddress, quint16 bindPort, | - | ||||||||||||
| 18 | const QHostAddress &remoteAddress) | - | ||||||||||||
| 19 | { | - | ||||||||||||
| 20 | const QHostAddress *address = &bindAddress; | - | ||||||||||||
| 21 | QAbstractSocket::NetworkLayerProtocol proto = address->protocol(); | - | ||||||||||||
| 22 | if (proto == QUdpSocket::UnknownNetworkLayerProtocol
| 0-635 | ||||||||||||
| 23 | address = &remoteAddress; | - | ||||||||||||
| 24 | proto = address->protocol(); | - | ||||||||||||
| 25 | } never executed: end of block | 0 | ||||||||||||
| 26 | - | |||||||||||||
| 27 | - | |||||||||||||
| 28 | if (!socketEngine
| 0-621 | ||||||||||||
| 29 | resolveProxy(remoteAddress.toString(), bindPort); | - | ||||||||||||
| 30 | if (!initSocketLayer(address->protocol())
| 0-14 | ||||||||||||
| 31 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 32 | } executed 14 times by 2 tests: end of blockExecuted by:
| 14 | ||||||||||||
| 33 | - | |||||||||||||
| 34 | return executed 635 times by 3 tests: true;return true;Executed by:
executed 635 times by 3 tests: return true;Executed by:
| 635 | ||||||||||||
| 35 | } | - | ||||||||||||
| 36 | QUdpSocket::QUdpSocket(QObject *parent) | - | ||||||||||||
| 37 | : QAbstractSocket(UdpSocket, *new QUdpSocketPrivate, parent) | - | ||||||||||||
| 38 | { | - | ||||||||||||
| 39 | d_func()->isBuffered = false; | - | ||||||||||||
| 40 | } executed 137 times by 3 tests: end of blockExecuted by:
| 137 | ||||||||||||
| 41 | - | |||||||||||||
| 42 | - | |||||||||||||
| 43 | - | |||||||||||||
| 44 | - | |||||||||||||
| 45 | - | |||||||||||||
| 46 | - | |||||||||||||
| 47 | QUdpSocket::~QUdpSocket() | - | ||||||||||||
| 48 | { | - | ||||||||||||
| 49 | } | - | ||||||||||||
| 50 | bool QUdpSocket::joinMulticastGroup(const QHostAddress &groupAddress) | - | ||||||||||||
| 51 | { | - | ||||||||||||
| 52 | return executed 13 times by 1 test: joinMulticastGroup(groupAddress, QNetworkInterface());return joinMulticastGroup(groupAddress, QNetworkInterface());Executed by:
executed 13 times by 1 test: return joinMulticastGroup(groupAddress, QNetworkInterface());Executed by:
| 13 | ||||||||||||
| 53 | } | - | ||||||||||||
| 54 | bool QUdpSocket::joinMulticastGroup(const QHostAddress &groupAddress, | - | ||||||||||||
| 55 | const QNetworkInterface &iface) | - | ||||||||||||
| 56 | { | - | ||||||||||||
| 57 | QUdpSocketPrivate * const d = d_func(); | - | ||||||||||||
| 58 | do { if (!isValid()
executed 4 times by 1 test: (false);return (false);Executed by:
executed 4 times by 1 test: } } while (0);return (false);Executed by:
| 4-9 | ||||||||||||
| 59 | return executed 9 times by 1 test: d->socketEngine->joinMulticastGroup(groupAddress, iface);return d->socketEngine->joinMulticastGroup(groupAddress, iface);Executed by:
executed 9 times by 1 test: return d->socketEngine->joinMulticastGroup(groupAddress, iface);Executed by:
| 9 | ||||||||||||
| 60 | } | - | ||||||||||||
| 61 | bool QUdpSocket::leaveMulticastGroup(const QHostAddress &groupAddress) | - | ||||||||||||
| 62 | { | - | ||||||||||||
| 63 | return executed 6 times by 1 test: leaveMulticastGroup(groupAddress, QNetworkInterface());return leaveMulticastGroup(groupAddress, QNetworkInterface());Executed by:
executed 6 times by 1 test: return leaveMulticastGroup(groupAddress, QNetworkInterface());Executed by:
| 6 | ||||||||||||
| 64 | } | - | ||||||||||||
| 65 | bool QUdpSocket::leaveMulticastGroup(const QHostAddress &groupAddress, | - | ||||||||||||
| 66 | const QNetworkInterface &iface) | - | ||||||||||||
| 67 | { | - | ||||||||||||
| 68 | do { if (!isValid()
executed 2 times by 1 test: (false);return (false);Executed by:
executed 2 times by 1 test: } } while (0);return (false);Executed by:
| 2-4 | ||||||||||||
| 69 | return executed 4 times by 1 test: d_func()->socketEngine->leaveMulticastGroup(groupAddress, iface);return d_func()->socketEngine->leaveMulticastGroup(groupAddress, iface);Executed by:
executed 4 times by 1 test: return d_func()->socketEngine->leaveMulticastGroup(groupAddress, iface);Executed by:
| 4 | ||||||||||||
| 70 | } | - | ||||||||||||
| 71 | QNetworkInterface QUdpSocket::multicastInterface() const | - | ||||||||||||
| 72 | { | - | ||||||||||||
| 73 | const QUdpSocketPrivate * const d = d_func(); | - | ||||||||||||
| 74 | do { if (!isValid()
never executed: (QNetworkInterface());return (QNetworkInterface());never executed: } } while (0);return (QNetworkInterface()); | 0-6 | ||||||||||||
| 75 | return executed 6 times by 1 test: d->socketEngine->multicastInterface();return d->socketEngine->multicastInterface();Executed by:
executed 6 times by 1 test: return d->socketEngine->multicastInterface();Executed by:
| 6 | ||||||||||||
| 76 | } | - | ||||||||||||
| 77 | void QUdpSocket::setMulticastInterface(const QNetworkInterface &iface) | - | ||||||||||||
| 78 | { | - | ||||||||||||
| 79 | QUdpSocketPrivate * const d = d_func(); | - | ||||||||||||
| 80 | if (!isValid()
| 0-6 | ||||||||||||
| 81 | QMessageLogger(__FILE__, 270, __PRETTY_FUNCTION__).warning("QUdpSocket::setMulticastInterface() called on a QUdpSocket when not in QUdpSocket::BoundState"); | - | ||||||||||||
| 82 | return; never executed: return; | 0 | ||||||||||||
| 83 | } | - | ||||||||||||
| 84 | d->socketEngine->setMulticastInterface(iface); | - | ||||||||||||
| 85 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||
| 86 | bool QUdpSocket::hasPendingDatagrams() const | - | ||||||||||||
| 87 | { | - | ||||||||||||
| 88 | do { if (!isValid()
never executed: (false);return (false);never executed: } } while (0);return (false); | 0-662403 | ||||||||||||
| 89 | return executed 662403 times by 2 tests: d_func()->socketEngine->hasPendingDatagrams();return d_func()->socketEngine->hasPendingDatagrams();Executed by:
executed 662403 times by 2 tests: return d_func()->socketEngine->hasPendingDatagrams();Executed by:
| 662403 | ||||||||||||
| 90 | } | - | ||||||||||||
| 91 | - | |||||||||||||
| 92 | - | |||||||||||||
| 93 | - | |||||||||||||
| 94 | - | |||||||||||||
| 95 | - | |||||||||||||
| 96 | - | |||||||||||||
| 97 | - | |||||||||||||
| 98 | qint64 QUdpSocket::pendingDatagramSize() const | - | ||||||||||||
| 99 | { | - | ||||||||||||
| 100 | do { if (!isValid()
never executed: (-1);return (-1);never executed: } } while (0);return (-1); | 0-592 | ||||||||||||
| 101 | return executed 592 times by 2 tests: d_func()->socketEngine->pendingDatagramSize();return d_func()->socketEngine->pendingDatagramSize();Executed by:
executed 592 times by 2 tests: return d_func()->socketEngine->pendingDatagramSize();Executed by:
| 592 | ||||||||||||
| 102 | } | - | ||||||||||||
| 103 | qint64 QUdpSocket::writeDatagram(const char *data, qint64 size, const QHostAddress &address, | - | ||||||||||||
| 104 | quint16 port) | - | ||||||||||||
| 105 | { | - | ||||||||||||
| 106 | QUdpSocketPrivate * const d = d_func(); | - | ||||||||||||
| 107 | - | |||||||||||||
| 108 | - | |||||||||||||
| 109 | - | |||||||||||||
| 110 | - | |||||||||||||
| 111 | if (!d->doEnsureInitialized(QHostAddress::Any, 0, address)
| 0-635 | ||||||||||||
| 112 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 113 | if (state() == UnconnectedState
| 14-621 | ||||||||||||
| 114 | bind(); executed 14 times by 2 tests: bind();Executed by:
| 14 | ||||||||||||
| 115 | - | |||||||||||||
| 116 | qint64 sent = d->socketEngine->writeDatagram(data, size, QIpPacketHeader(address, port)); | - | ||||||||||||
| 117 | d->cachedSocketDescriptor = d->socketEngine->socketDescriptor(); | - | ||||||||||||
| 118 | - | |||||||||||||
| 119 | if (sent >= 0
| 1-634 | ||||||||||||
| 120 | bytesWritten(sent); | - | ||||||||||||
| 121 | } executed 634 times by 3 tests: else {end of blockExecuted by:
| 634 | ||||||||||||
| 122 | d->setErrorAndEmit(d->socketEngine->error(), d->socketEngine->errorString()); | - | ||||||||||||
| 123 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 124 | return executed 635 times by 3 tests: sent;return sent;Executed by:
executed 635 times by 3 tests: return sent;Executed by:
| 635 | ||||||||||||
| 125 | } | - | ||||||||||||
| 126 | qint64 QUdpSocket::readDatagram(char *data, qint64 maxSize, QHostAddress *address, | - | ||||||||||||
| 127 | quint16 *port) | - | ||||||||||||
| 128 | { | - | ||||||||||||
| 129 | QUdpSocketPrivate * const d = d_func(); | - | ||||||||||||
| 130 | - | |||||||||||||
| 131 | - | |||||||||||||
| 132 | - | |||||||||||||
| 133 | - | |||||||||||||
| 134 | do { if (!isValid()
never executed: (-1);return (-1);never executed: } } while (0);return (-1); | 0-662427 | ||||||||||||
| 135 | - | |||||||||||||
| 136 | qint64 readBytes; | - | ||||||||||||
| 137 | if (address
| 0-661920 | ||||||||||||
| 138 | QIpPacketHeader header; | - | ||||||||||||
| 139 | readBytes = d->socketEngine->readDatagram(data, maxSize, &header, | - | ||||||||||||
| 140 | QAbstractSocketEngine::WantDatagramSender); | - | ||||||||||||
| 141 | if (address
| 0-507 | ||||||||||||
| 142 | * executed 507 times by 2 tests: address = header.senderAddress;*address = header.senderAddress;Executed by:
executed 507 times by 2 tests: *address = header.senderAddress;Executed by:
| 507 | ||||||||||||
| 143 | if (port
| 0-507 | ||||||||||||
| 144 | * executed 507 times by 2 tests: port = header.senderPort;*port = header.senderPort;Executed by:
executed 507 times by 2 tests: *port = header.senderPort;Executed by:
| 507 | ||||||||||||
| 145 | } executed 507 times by 2 tests: else {end of blockExecuted by:
| 507 | ||||||||||||
| 146 | readBytes = d->socketEngine->readDatagram(data, maxSize); | - | ||||||||||||
| 147 | } executed 661920 times by 2 tests: end of blockExecuted by:
| 661920 | ||||||||||||
| 148 | - | |||||||||||||
| 149 | d_func()->socketEngine->setReadNotificationEnabled(true); | - | ||||||||||||
| 150 | if (readBytes < 0
| 0-662427 | ||||||||||||
| 151 | d->setErrorAndEmit(d->socketEngine->error(), d->socketEngine->errorString()); never executed: d->setErrorAndEmit(d->socketEngine->error(), d->socketEngine->errorString()); | 0 | ||||||||||||
| 152 | return executed 662427 times by 3 tests: readBytes;return readBytes;Executed by:
executed 662427 times by 3 tests: return readBytes;Executed by:
| 662427 | ||||||||||||
| 153 | } | - | ||||||||||||
| 154 | - | |||||||||||||
| 155 | - | |||||||||||||
| 156 | - | |||||||||||||
| Switch to Source code | Preprocessed file |