Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qnativesocketengine.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5//#define QNATIVESOCKETENGINE_DEBUG
6
82
84#include <qsocketnotifier.h>
85#include <qnetworkinterface.h>
86
87#include <private/qthread_p.h>
88#include <private/qobject_p.h>
89
90#if !defined(QT_NO_NETWORKPROXY)
91# include "qnetworkproxy.h"
92# include "qabstractsocket.h"
93# include "qtcpserver.h"
94#endif
95
96#if !defined(QT_NO_SCTP)
97# include "qsctpserver.h"
98#endif
99
101
102using namespace Qt::StringLiterals;
103
104//#define QNATIVESOCKETENGINE_DEBUG
105
106#define Q_VOID
107
108// Common constructs
109#define Q_CHECK_VALID_SOCKETLAYER(function, returnValue) do { \
110 if (!isValid()) { \
111 qWarning(""#function" was called on an uninitialized socket device"); \
112 return returnValue; \
113 } } while (0)
114#define Q_CHECK_INVALID_SOCKETLAYER(function, returnValue) do { \
115 if (isValid()) { \
116 qWarning(""#function" was called on an already initialized socket device"); \
117 return returnValue; \
118 } } while (0)
119#define Q_CHECK_STATE(function, checkState, returnValue) do { \
120 if (d->socketState != (checkState)) { \
121 qWarning(""#function" was not called in "#checkState); \
122 return (returnValue); \
123 } } while (0)
124#define Q_CHECK_NOT_STATE(function, checkState, returnValue) do { \
125 if (d->socketState == (checkState)) { \
126 qWarning(""#function" was called in "#checkState); \
127 return (returnValue); \
128 } } while (0)
129#define Q_CHECK_STATES(function, state1, state2, returnValue) do { \
130 if (d->socketState != (state1) && d->socketState != (state2)) { \
131 qWarning(""#function" was called" \
132 " not in "#state1" or "#state2); \
133 return (returnValue); \
134 } } while (0)
135#define Q_CHECK_STATES3(function, state1, state2, state3, returnValue) do { \
136 if (d->socketState != (state1) && d->socketState != (state2) && d->socketState != (state3)) { \
137 qWarning(""#function" was called" \
138 " not in "#state1" or "#state2); \
139 return (returnValue); \
140 } } while (0)
141#define Q_CHECK_TYPE(function, type, returnValue) do { \
142 if (d->socketType != (type)) { \
143 qWarning(#function" was called by a" \
144 " socket other than "#type""); \
145 return (returnValue); \
146 } } while (0)
147#define Q_CHECK_TYPES(function, type1, type2, returnValue) do { \
148 if (d->socketType != (type1) && d->socketType != (type2)) { \
149 qWarning(#function" was called by a" \
150 " socket other than "#type1" or "#type2); \
151 return (returnValue); \
152 } } while (0)
153#define Q_TR(a) QT_TRANSLATE_NOOP(QNativeSocketEngine, a)
154
159 socketDescriptor(-1),
160 readNotifier(nullptr),
161 writeNotifier(nullptr),
162 exceptNotifier(nullptr)
163{
164#if defined(Q_OS_WIN)
165 QSysInfo::machineHostName(); // this initializes ws2_32.dll
166#endif
167}
168
175
183{
184 if (hasSetSocketError) {
185 // Only set socket errors once for one engine; expect the
186 // socket to recreate its engine after an error. Note: There's
187 // one exception: SocketError(11) bypasses this as it's purely
188 // a temporary internal error condition.
189 // Another exception is the way the waitFor*() functions set
190 // an error when a timeout occurs. After the call to setError()
191 // they reset the hasSetSocketError to false
192 return;
193 }
195 hasSetSocketError = true;
196
198
199 switch (errorString) {
201 socketErrorString = QNativeSocketEngine::tr("Unable to initialize non-blocking socket");
202 break;
204 socketErrorString = QNativeSocketEngine::tr("Unable to initialize broadcast socket");
205 break;
206 // should not happen anymore
208 socketErrorString = QNativeSocketEngine::tr("Attempt to use IPv6 socket on a platform with no IPv6 support");
209 break;
211 socketErrorString = QNativeSocketEngine::tr("The remote host closed the connection");
212 break;
214 socketErrorString = QNativeSocketEngine::tr("Network operation timed out");
215 break;
217 socketErrorString = QNativeSocketEngine::tr("Out of resources");
218 break;
220 socketErrorString = QNativeSocketEngine::tr("Unsupported socket operation");
221 break;
223 socketErrorString = QNativeSocketEngine::tr("Protocol type not supported");
224 break;
226 socketErrorString = QNativeSocketEngine::tr("Invalid socket descriptor");
227 break;
229 socketErrorString = QNativeSocketEngine::tr("Host unreachable");
230 break;
232 socketErrorString = QNativeSocketEngine::tr("Network unreachable");
233 break;
235 socketErrorString = QNativeSocketEngine::tr("Permission denied");
236 break;
238 socketErrorString = QNativeSocketEngine::tr("Connection timed out");
239 break;
241 socketErrorString = QNativeSocketEngine::tr("Connection refused");
242 break;
244 socketErrorString = QNativeSocketEngine::tr("The bound address is already in use");
245 break;
247 socketErrorString = QNativeSocketEngine::tr("The address is not available");
248 break;
250 socketErrorString = QNativeSocketEngine::tr("The address is protected");
251 break;
253 socketErrorString = QNativeSocketEngine::tr("Datagram was too large to send");
254 break;
256 socketErrorString = QNativeSocketEngine::tr("Unable to send a message");
257 break;
259 socketErrorString = QNativeSocketEngine::tr("Unable to receive a message");
260 break;
261 case WriteErrorString:
262 socketErrorString = QNativeSocketEngine::tr("Unable to write");
263 break;
264 case ReadErrorString:
265 socketErrorString = QNativeSocketEngine::tr("Network error");
266 break;
268 socketErrorString = QNativeSocketEngine::tr("Another socket is already listening on the same port");
269 break;
271 socketErrorString = QNativeSocketEngine::tr("Operation on non-socket");
272 break;
274 socketErrorString = QNativeSocketEngine::tr("The proxy type is invalid for this operation");
275 break;
277 socketErrorString = QNativeSocketEngine::tr("Temporary error");
278 break;
280 socketErrorString = QNativeSocketEngine::tr("Network dropped connection on reset");
281 break;
283 socketErrorString = QNativeSocketEngine::tr("Connection reset by peer");
284 break;
286 socketErrorString = QNativeSocketEngine::tr("Unknown error");
287 break;
288 }
289}
290
299{
302 return address;
303
304 QAbstractSocket::NetworkLayerProtocol sourceProtocol = address.protocol();
305
306 if (targetProtocol == QAbstractSocket::AnyIPProtocol)
307 targetProtocol = QAbstractSocket::IPv6Protocol;
308 if (targetProtocol == QAbstractSocket::IPv6Protocol && sourceProtocol == QAbstractSocket::IPv4Protocol) {
309 // convert to IPv6 v4-mapped address. This always works
310 return QHostAddress(address.toIPv6Address());
311 }
312
313 if (targetProtocol == QAbstractSocket::IPv4Protocol && sourceProtocol == QAbstractSocket::IPv6Protocol) {
314 // convert to IPv4 if the source is a v4-mapped address
315 quint32 ip4 = address.toIPv4Address();
316 if (ip4)
317 return QHostAddress(ip4);
318 }
319
320 return address;
321}
322
324{
325 if (address.isLoopback())
326 return true;
327
328#if !defined(QT_NO_NETWORKPROXY)
329 QObject *parent = q_func()->parent();
332 if (QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(parent)) {
333 proxy = socket->proxy();
334 switch (socket->socketType()) {
337 break;
340 break;
344 }
345 } else if (QTcpServer *server = qobject_cast<QTcpServer *>(parent)) {
346 proxy = server->proxy();
348#ifndef QT_NO_SCTP
349 if (qobject_cast<QSctpServer *>(server))
351#endif
352 } else {
353 // no parent -> no proxy
354 return true;
355 }
356
358 // This is similar to what we have in QNetworkProxy::applicationProxy,
359 // the only difference is that we provide the correct query type instead of
360 // always using TcpSocket unconditionally (this is the default type for
361 // QNetworkProxyQuery).
363 query.setQueryType(queryType);
365 }
366
369 // QNativeSocketEngine doesn't do proxies
372 return false;
373 }
374#endif
375
376 return true;
377}
378
388
396
409{
411 if (isValid())
412 close();
413
414 // Create the socket
415 if (!d->createNewSocket(socketType, protocol)) {
416#if defined (QNATIVESOCKETENGINE_DEBUG)
417 QString typeStr = "UnknownSocketType"_L1;
418 if (socketType == QAbstractSocket::TcpSocket) typeStr = "TcpSocket"_L1;
419 else if (socketType == QAbstractSocket::UdpSocket) typeStr = "UdpSocket"_L1;
420 else if (socketType == QAbstractSocket::SctpSocket) typeStr = "SctpSocket"_L1;
421 QString protocolStr = "UnknownProtocol"_L1;
422 if (protocol == QAbstractSocket::IPv4Protocol) protocolStr = "IPv4Protocol"_L1;
423 else if (protocol == QAbstractSocket::IPv6Protocol) protocolStr = "IPv6Protocol"_L1;
424 qDebug("QNativeSocketEngine::initialize(type == %s, protocol == %s) failed: %s",
425 typeStr.toLatin1().constData(), protocolStr.toLatin1().constData(), d->socketErrorString.toLatin1().constData());
426#endif
427 return false;
428 }
429
431 // Set the broadcasting flag if it's a UDP socket.
435 close();
436 return false;
437 }
438
439 // Set some extra flags that are interesting to us, but accept failure
442 }
443
444
445#ifndef Q_OS_WASM
446 // Make sure we receive out-of-band data
449 qWarning("QNativeSocketEngine::initialize unable to inline out-of-band data");
450 }
451#endif
452
453 // Before Qt 4.6, we always set the send and receive buffer size to 49152 as
454 // this was found to be an optimal value. However, modern OS
455 // all have some kind of auto tuning for this and we therefore don't set
456 // this explicitly anymore.
457 // If it introduces any performance regressions for Qt 4.6.x (x > 0) then
458 // it will be put back in.
459 //
460 // You can use tests/manual/qhttpnetworkconnection to test HTTP download speed
461 // with this.
462 //
463 // pre-4.6:
464 // setReceiveBufferSize(49152);
465 // setSendBufferSize(49152);
466
467 return true;
468}
469
481{
483
484 if (isValid())
485 close();
486
487 d->socketDescriptor = socketDescriptor;
488
489 // determine socket type and protocol
490 if (!d->fetchConnectionParameters()) {
491#if defined (QNATIVESOCKETENGINE_DEBUG)
492 qDebug() << "QNativeSocketEngine::initialize(socketDescriptor) failed:"
493 << socketDescriptor << d->socketErrorString;
494#endif
495 d->socketDescriptor = -1;
496 return false;
497 }
498
499 if (d->socketType != QAbstractSocket::UnknownSocketType) {
500 // Make the socket nonblocking.
504 close();
505 return false;
506 }
507
508 // Set the broadcasting flag if it's a UDP socket.
509 if (d->socketType == QAbstractSocket::UdpSocket
513 close();
514 return false;
515 }
516 }
517
518 d->socketState = socketState;
519 return true;
520}
521
528{
529 Q_D(const QNativeSocketEngine);
530 return d->socketDescriptor != -1;
531}
532
538{
539 Q_D(const QNativeSocketEngine);
540 return d->socketDescriptor;
541}
542
566{
569
570 if (!d->checkProxy(address))
571 return false;
572
575
576 d->peerAddress = address;
577 d->peerPort = port;
578 bool connected = d->nativeConnect(d->adjustAddressProtocol(address), port);
579 if (connected)
580 d->fetchConnectionParameters();
581
582 return connected;
583}
584
600
618
629{
632
633 if (!d->checkProxy(address))
634 return false;
635
637
638 if (!d->nativeBind(d->adjustAddressProtocol(address), port))
639 return false;
640
641 d->fetchConnectionParameters();
642 return true;
643}
644
674
696
713
714#ifndef QT_NO_UDPSOCKET
715#ifndef QT_NO_NETWORKINTERFACE
716
721 const QNetworkInterface &iface)
722{
727
728 // if the user binds a socket to an IPv6 address (or QHostAddress::Any) and
729 // then attempts to join an IPv4 multicast group, this won't work on
730 // Windows. In order to make this cross-platform, we warn & fail on all
731 // platforms.
732 if (groupAddress.protocol() == QAbstractSocket::IPv4Protocol &&
733 (d->socketProtocol == QAbstractSocket::IPv6Protocol ||
734 d->socketProtocol == QAbstractSocket::AnyIPProtocol)) {
735 qWarning("QAbstractSocket: cannot bind to QHostAddress::Any (or an IPv6 address) and join an IPv4 multicast group;"
736 " bind to QHostAddress::AnyIPv4 instead if you want to do this");
737 return false;
738 }
739
740 return d->nativeJoinMulticastGroup(groupAddress, iface);
741}
742
755
766
777
778#endif // QT_NO_NETWORKINTERFACE
779
794
809#endif // QT_NO_UDPSOCKET
810
836
868
884
885
887{
888 return 0;
889}
890
896{
900
901 qint64 readBytes = d->nativeRead(data, maxSize);
902
903 // Handle remote close
904 if (readBytes == 0 && (d->socketType == QAbstractSocket::TcpSocket
905#ifndef QT_NO_SCTP
906 || d->socketType == QAbstractSocket::SctpSocket
907#endif
908 )) {
911 close();
912 return -1;
913 } else if (readBytes == -1) {
914 if (!d->hasSetSocketError) {
915 d->hasSetSocketError = true;
916 d->socketError = QAbstractSocket::NetworkError;
917 d->socketErrorString = qt_error_string();
918 }
919 close();
920 return -1;
921 }
922 return readBytes;
923}
924
930{
932 if (d->readNotifier)
933 d->readNotifier->setEnabled(false);
934 if (d->writeNotifier)
935 d->writeNotifier->setEnabled(false);
936 if (d->exceptNotifier)
937 d->exceptNotifier->setEnabled(false);
938
939 if (d->socketDescriptor != -1) {
940 d->nativeClose();
941 d->socketDescriptor = -1;
942 }
944 d->hasSetSocketError = false;
945 d->localPort = 0;
946 d->localAddress.clear();
947 d->peerPort = 0;
948 d->peerAddress.clear();
949 d->inboundStreamCount = d->outboundStreamCount = 0;
950 if (d->readNotifier) {
951 delete d->readNotifier;
952 d->readNotifier = nullptr;
953 }
954 if (d->writeNotifier) {
955 delete d->writeNotifier;
956 d->writeNotifier = nullptr;
957 }
958 if (d->exceptNotifier) {
959 delete d->exceptNotifier;
960 d->exceptNotifier = nullptr;
961 }
962}
963
980{
981 Q_D(const QNativeSocketEngine);
985
986 if (timedOut)
987 *timedOut = false;
988
989 int ret = d->nativeSelect(deadline, true);
990 if (ret == 0) {
991 if (timedOut)
992 *timedOut = true;
995 d->hasSetSocketError = false; // A timeout error is temporary in waitFor functions
996 return false;
997 } else if (state() == QAbstractSocket::ConnectingState) {
998 connectToHost(d->peerAddress, d->peerPort);
999 }
1000
1001 return ret > 0;
1002}
1003
1020{
1025
1026 if (timedOut)
1027 *timedOut = false;
1028
1029 int ret = d->nativeSelect(deadline, false);
1030 // On Windows, the socket is in connected state if a call to
1031 // select(writable) is successful. In this case we should not
1032 // issue a second call to WSAConnect()
1033#if defined (Q_OS_WIN)
1035 if (ret > 0) {
1037 d_func()->fetchConnectionParameters();
1038 return true;
1039 } else {
1040 int value = 0;
1041 int valueSize = sizeof(value);
1042 if (::getsockopt(d->socketDescriptor, SOL_SOCKET, SO_ERROR, (char *) &value, &valueSize) == 0) {
1043 if (value == WSAECONNREFUSED) {
1045 d->socketState = QAbstractSocket::UnconnectedState;
1046 return false;
1047 } else if (value == WSAETIMEDOUT) {
1049 d->socketState = QAbstractSocket::UnconnectedState;
1050 return false;
1051 } else if (value == WSAEHOSTUNREACH) {
1053 d->socketState = QAbstractSocket::UnconnectedState;
1054 return false;
1055 }
1056 }
1057 }
1058 }
1059#endif
1060
1061 if (ret == 0) {
1062 if (timedOut)
1063 *timedOut = true;
1066 d->hasSetSocketError = false; // A timeout error is temporary in waitFor functions
1067 return false;
1068 } else if (state() == QAbstractSocket::ConnectingState || (state() == QAbstractSocket::BoundState && d->socketDescriptor != -1)) {
1069 connectToHost(d->peerAddress, d->peerPort);
1070 }
1071
1072 return ret > 0;
1073}
1074
1075bool QNativeSocketEngine::waitForReadOrWrite(bool *readyToRead, bool *readyToWrite,
1076 bool checkRead, bool checkWrite,
1077 QDeadlineTimer deadline, bool *timedOut)
1078{
1083
1084 int ret = d->nativeSelect(deadline, checkRead, checkWrite, readyToRead, readyToWrite);
1085 // On Windows, the socket is in connected state if a call to
1086 // select(writable) is successful. In this case we should not
1087 // issue a second call to WSAConnect()
1088#if defined (Q_OS_WIN)
1090 if (checkWrite && ((readyToWrite && *readyToWrite) || !readyToWrite) && ret > 0) {
1092 d_func()->fetchConnectionParameters();
1093 return true;
1094 } else {
1095 int value = 0;
1096 int valueSize = sizeof(value);
1097 if (::getsockopt(d->socketDescriptor, SOL_SOCKET, SO_ERROR, (char *) &value, &valueSize) == 0) {
1098 if (value == WSAECONNREFUSED) {
1100 d->socketState = QAbstractSocket::UnconnectedState;
1101 return false;
1102 } else if (value == WSAETIMEDOUT) {
1104 d->socketState = QAbstractSocket::UnconnectedState;
1105 return false;
1106 } else if (value == WSAEHOSTUNREACH) {
1108 d->socketState = QAbstractSocket::UnconnectedState;
1109 return false;
1110 }
1111 }
1112 }
1113 }
1114#endif
1115 if (ret == 0) {
1116 if (timedOut)
1117 *timedOut = true;
1120 d->hasSetSocketError = false; // A timeout error is temporary in waitFor functions
1121 return false;
1122 } else if (state() == QAbstractSocket::ConnectingState) {
1123 connectToHost(d->peerAddress, d->peerPort);
1124 }
1125
1126 return ret > 0;
1127}
1128
1129#if 0 // currently unused
1130/*
1131 Returns the size of the operating system's socket receive
1132 buffer. Depending on the operating system, this size may be
1133 different from what has been set earlier with
1134 setReceiveBufferSize().
1135*/
1136qint64 QNativeSocketEngine::receiveBufferSize() const
1137{
1138 Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::receiveBufferSize(), -1);
1140}
1141
1142/*
1143 Sets the size of the operating system receive buffer to \a size.
1144
1145 For clients, this should be set before connectToHost() is called;
1146 otherwise it will have no effect. For servers, it should be called
1147 before listen().
1148
1149 The operating system receive buffer size effectively limits two
1150 things: how much data can be in transit at any one moment, and how
1151 much data can be received in one iteration of the main event loop.
1152 Setting the size of the receive buffer may have an impact on the
1153 socket's performance.
1154
1155 The default value is operating system-dependent.
1156*/
1157void QNativeSocketEngine::setReceiveBufferSize(qint64 size)
1158{
1159 Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::setReceiveBufferSize(), Q_VOID);
1161}
1162
1163/*
1164 Returns the size of the operating system send buffer. Depending on
1165 the operating system, this size may be different from what has
1166 been set earlier with setSendBufferSize().
1167*/
1168qint64 QNativeSocketEngine::sendBufferSize() const
1169{
1170 Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::setSendBufferSize(), -1);
1172}
1173
1174/*
1175 Sets the size of the operating system send buffer to \a size.
1176
1177 The operating system send buffer size effectively limits how much
1178 data can be in transit at any one moment. Setting the size of the
1179 send buffer may have an impact on the socket's performance.
1180
1181 The default value is operating system-dependent.
1182*/
1183void QNativeSocketEngine::setSendBufferSize(qint64 size)
1184{
1185 Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::setSendBufferSize(), Q_VOID);
1187}
1188#endif
1189
1194{
1196 return d->setOption(option, value);
1197}
1198
1203{
1204 Q_D(const QNativeSocketEngine);
1205 return d->option(socketOption);
1206}
1207
1209{
1210 Q_D(const QNativeSocketEngine);
1211 return d->readNotifier && d->readNotifier->isEnabled();
1212}
1213
1214/*
1215 \internal
1216 \class QReadNotifier
1217 \brief The QReadNotifer class is used to improve performance.
1218
1219 QReadNotifier is a private class used for performance reasons vs
1220 connecting to the QSocketNotifier activated() signal.
1221 */
1223{
1224public:
1228
1229protected:
1230 bool event(QEvent *) override;
1231
1233};
1234
1236{
1237 if (e->type() == QEvent::SockAct) {
1239 return true;
1240 } else if (e->type() == QEvent::SockClose) {
1242 return true;
1243 }
1244 return QSocketNotifier::event(e);
1245}
1246
1247/*
1248 \internal
1249 \class QWriteNotifier
1250 \brief The QWriteNotifer class is used to improve performance.
1251
1252 QWriteNotifier is a private class used for performance reasons vs
1253 connecting to the QSocketNotifier activated() signal.
1254 */
1256{
1257public:
1260
1261protected:
1262 bool event(QEvent *) override;
1263
1265};
1266
1268{
1269 if (e->type() == QEvent::SockAct) {
1272 else
1274 return true;
1275 }
1276 return QSocketNotifier::event(e);
1277}
1278
1290
1292{
1293 if (e->type() == QEvent::SockAct) {
1296 else
1298 return true;
1299 }
1300 return QSocketNotifier::event(e);
1301}
1302
1304{
1306 if (d->readNotifier) {
1307 d->readNotifier->setEnabled(enable);
1308 } else if (enable && d->threadData.loadRelaxed()->hasEventDispatcher()) {
1309 d->readNotifier = new QReadNotifier(d->socketDescriptor, this);
1310 d->readNotifier->setEnabled(true);
1311 }
1312}
1313
1315{
1316 Q_D(const QNativeSocketEngine);
1317 return d->writeNotifier && d->writeNotifier->isEnabled();
1318}
1319
1321{
1323 if (d->writeNotifier) {
1324 d->writeNotifier->setEnabled(enable);
1325 } else if (enable && d->threadData.loadRelaxed()->hasEventDispatcher()) {
1326 d->writeNotifier = new QWriteNotifier(d->socketDescriptor, this);
1327 d->writeNotifier->setEnabled(true);
1328 }
1329}
1330
1332{
1333 Q_D(const QNativeSocketEngine);
1334 return d->exceptNotifier && d->exceptNotifier->isEnabled();
1335}
1336
1338{
1340 if (d->exceptNotifier) {
1341 d->exceptNotifier->setEnabled(enable);
1342 } else if (enable && d->threadData.loadRelaxed()->hasEventDispatcher()) {
1343 d->exceptNotifier = new QExceptionNotifier(d->socketDescriptor, this);
1344 d->exceptNotifier->setEnabled(true);
1345 }
1346}
1347
1349
1350#include "moc_qnativesocketengine_p.cpp"
bool connected
QAbstractSocket::NetworkLayerProtocol socketProtocol
QAbstractSocket::SocketError socketError
QAbstractSocket::NetworkLayerProtocol protocol() const
void setState(QAbstractSocket::SocketState state)
QAbstractSocket::SocketType socketType() const
QAbstractSocket::SocketState state() const
The QAbstractSocket class provides the base functionality common to all socket types.
SocketState
This enum describes the different states in which a socket can be.
static constexpr auto IPv4Protocol
QNetworkProxy proxy() const
static constexpr auto UnknownNetworkLayerProtocol
static constexpr auto AnyIPProtocol
SocketType socketType() const
Returns the socket type (TCP, UDP, or other).
SocketError
This enum describes the socket errors that can occur.
static constexpr auto IPv6Protocol
SocketType
This enum describes the transport layer protocol.
\inmodule QtCore
\inmodule QtCore
Definition qcoreevent.h:45
@ SockClose
Definition qcoreevent.h:268
@ SockAct
Definition qcoreevent.h:98
Type type() const
Returns the event type.
Definition qcoreevent.h:304
QNativeSocketEngine * engine
bool event(QEvent *) override
This virtual function receives events to an object and should return true if the event e was recogniz...
QExceptionNotifier(qintptr fd, QNativeSocketEngine *parent)
The QHostAddress class provides an IP address.
void setError(QAbstractSocket::SocketError error, ErrorString errorString) const
bool checkProxy(const QHostAddress &address)
QHostAddress adjustAddressProtocol(const QHostAddress &address) const
The QNativeSocketEngine class provides low level access to a socket.
void connectionNotification()
If there's a connection activity on the socket, process it.
bool isReadNotificationEnabled() const override
bool isWriteNotificationEnabled() const override
void close() override
Closes the socket.
qint64 readDatagram(char *data, qint64 maxlen, QIpPacketHeader *=nullptr, PacketHeaderOptions=WantNone) override
Reads up to maxSize bytes of a datagram from the socket, stores it in data and returns the number of ...
qintptr accept() override
Accepts a pending connection from the socket, which must be in ListeningState, and returns its socket...
bool listen(int backlog) override
Prepares a TCP server for accepting incoming connections.
bool waitForRead(QDeadlineTimer deadline=QDeadlineTimer{DefaultTimeout}, bool *timedOut=nullptr) override
Waits until deadline has expired or until the socket is ready for reading.
QNativeSocketEngine(QObject *parent=nullptr)
Constructs a QNativeSocketEngine.
qintptr socketDescriptor() const override
Returns the native socket descriptor.
bool connectToHost(const QHostAddress &address, quint16 port) override
Connects to the IP address and port specified by address and port.
bool setOption(SocketOption option, int value) override
Sets the option option to the value value.
qint64 bytesAvailable() const override
Returns the number of bytes that are currently available for reading.
int option(SocketOption option) const override
Returns the value of the option socketOption.
bool leaveMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface) override
void setExceptionNotificationEnabled(bool enable) override
bool hasPendingDatagrams() const override
Returns true if there is at least one datagram pending.
qint64 writeDatagram(const char *data, qint64 len, const QIpPacketHeader &) override
Writes a datagram of size size bytes to the socket from data to the destination contained in header,...
~QNativeSocketEngine()
Destructs a QNativeSocketEngine.
bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite, bool checkRead, bool checkWrite, QDeadlineTimer deadline=QDeadlineTimer{DefaultTimeout}, bool *timedOut=nullptr) override
bool isValid() const override
Returns true if the socket is valid; otherwise returns false.
bool bind(const QHostAddress &address, quint16 port) override
Binds the socket to the address address and port port.
qint64 pendingDatagramSize() const override
Returns the size of the pending datagram, or -1 if no datagram is pending.
qint64 write(const char *data, qint64 len) override
Writes a block of size bytes from data to the socket.
bool joinMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface) override
bool isExceptionNotificationEnabled() const override
qint64 bytesToWrite() const override
bool setMulticastInterface(const QNetworkInterface &iface) override
QNetworkInterface multicastInterface() const override
bool connectToHostByName(const QString &name, quint16 port) override
Connects to the remote host name given by name on port port.
bool waitForWrite(QDeadlineTimer deadline=QDeadlineTimer{DefaultTimeout}, bool *timedOut=nullptr) override
Waits until deadline has expired or until the socket is ready for writing.
qint64 read(char *data, qint64 maxlen) override
Reads up to maxSize bytes into data from the socket.
bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol=QAbstractSocket::IPv4Protocol) override
Initializes a QNativeSocketEngine by creating a new socket of type socketType and network layer proto...
void setReadNotificationEnabled(bool enable) override
void setWriteNotificationEnabled(bool enable) override
The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces.
static QList< QNetworkProxy > proxyForQuery(const QNetworkProxyQuery &query)
This function takes the query request, query, examines the details of the type of socket or request a...
The QNetworkProxyQuery class is used to query the proxy settings for a socket.
QueryType
Describes the type of one QNetworkProxyQuery query.
void setQueryType(QueryType type)
Sets the query type of this object to be type.
The QNetworkProxy class provides a network layer proxy.
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
QObject * parent
Definition qobject.h:73
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
QNativeSocketEngine * engine
bool event(QEvent *) override
This virtual function receives events to an object and should return true if the event e was recogniz...
QReadNotifier(qintptr fd, QNativeSocketEngine *parent)
\inmodule QtCore
bool event(QEvent *) override
\reimp
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString machineHostName()
Definition qsysinfo.cpp:929
The QTcpServer class provides a TCP-based server.
Definition qtcpserver.h:22
QNativeSocketEngine * engine
QWriteNotifier(qintptr fd, QNativeSocketEngine *parent)
bool event(QEvent *) override
\reimp
Definition lalr.h:268
Combined button and popup list for selecting options.
#define Q_LIKELY(x)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage return DBusPendingCall DBusPendingCall return DBusPendingCall return dbus_int32_t return DBusServer * server
DBusConnection const char DBusError * error
static QString header(const QString &name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
EGLOutputPortEXT port
static QT_BEGIN_NAMESPACE const char * socketType(QSocketNotifier::Type type)
#define Q_VOID
Definition qiodevice.cpp:45
Q_DECL_COLD_FUNCTION Q_CORE_EXPORT QString qt_error_string(int errorCode=-1)
#define qDebug
[1]
Definition qlogging.h:164
#define qWarning
Definition qlogging.h:166
return ret
#define Q_CHECK_STATES3(function, state1, state2, state3, returnValue)
#define Q_CHECK_STATES(function, state1, state2, returnValue)
#define Q_CHECK_TYPES(function, type1, type2, returnValue)
#define Q_CHECK_VALID_SOCKETLAYER(function, returnValue)
#define Q_CHECK_NOT_STATE(function, checkState, returnValue)
#define Q_CHECK_TYPE(function, type, returnValue)
#define Q_CHECK_STATE(function, checkState, returnValue)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLboolean enable
GLuint64 GLenum GLint fd
GLuint name
struct _cl_event * event
GLenum query
GLuint GLuint64EXT address
GLuint GLenum option
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
static QLatin1StringView typeStr(QShaderDescription::VariableType t)
#define Q_UNUSED(x)
unsigned int quint32
Definition qtypes.h:50
unsigned short quint16
Definition qtypes.h:48
long long qint64
Definition qtypes.h:60
ptrdiff_t qintptr
Definition qtypes.h:166
QDeadlineTimer deadline(30s)
QObject::connect nullptr
QTcpSocket * socket
[1]
QNetworkProxy proxy
[0]