Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qabstractsocket_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QABSTRACTSOCKET_P_H
6#define QABSTRACTSOCKET_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the QAbstractSocket class. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/private/qtnetworkglobal_p.h>
20#include "QtNetwork/qabstractsocket.h"
21#include "QtCore/qbytearray.h"
22#include "QtCore/qlist.h"
23#include "QtCore/qtimer.h"
24#include "private/qiodevice_p.h"
25#include "private/qabstractsocketenginereceiver_p.h"
26#include "qnetworkproxy.h"
27
28QT_BEGIN_NAMESPACE
29
30class QAbstractSocketEngine;
31class QHostInfo;
32class QNetworkInterface;
33
34class Q_NETWORK_EXPORT QAbstractSocketPrivate : public QIODevicePrivate,
35 public QAbstractSocketEngineReceiver
36{
37 Q_DECLARE_PUBLIC(QAbstractSocket)
38public:
39 QAbstractSocketPrivate(decltype(QObjectPrivateVersion) version = QObjectPrivateVersion);
40 virtual ~QAbstractSocketPrivate();
41
42 // from QAbstractSocketEngineReceiver
43 inline void readNotification() override { canReadNotification(); }
44 inline void writeNotification() override { canWriteNotification(); }
45 inline void exceptionNotification() override {}
46 inline void closeNotification() override { canCloseNotification(); }
47 void connectionNotification() override;
48#ifndef QT_NO_NETWORKPROXY
49 inline void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator) override {
50 Q_Q(QAbstractSocket);
51 emit q->proxyAuthenticationRequired(proxy, authenticator);
52 }
53#endif
54
55 virtual bool bind(const QHostAddress &address, quint16 port, QAbstractSocket::BindMode mode,
56 const QNetworkInterface *iface = nullptr);
57 bool waitForConnected(QDeadlineTimer timer);
58 bool waitForReadyRead(QDeadlineTimer timer);
59 bool waitForBytesWritten(QDeadlineTimer timer);
60 bool waitForDisconnected(QDeadlineTimer timer);
61
62 virtual bool canReadNotification();
63 bool canWriteNotification();
64 void canCloseNotification();
65
66 // slots
67 void _q_connectToNextAddress();
68 void _q_startConnecting(const QHostInfo &hostInfo);
69 void _q_testConnection();
70 void _q_abortConnectionAttempt();
71
72 bool emittedReadyRead = false;
73 bool emittedBytesWritten = false;
74
75 bool abortCalled = false;
76 bool pendingClose = false;
77
78 QAbstractSocket::PauseModes pauseMode = QAbstractSocket::PauseNever;
79
80 QString hostName;
81 quint16 port = 0;
82 QHostAddress host;
83 QList<QHostAddress> addresses;
84
85 quint16 localPort = 0;
86 quint16 peerPort = 0;
87 QHostAddress localAddress;
88 QHostAddress peerAddress;
89 QString peerName;
90
91 QAbstractSocketEngine *socketEngine = nullptr;
92 qintptr cachedSocketDescriptor = -1;
93
94#ifndef QT_NO_NETWORKPROXY
95 QNetworkProxy proxy;
96 QNetworkProxy proxyInUse;
97 QString protocolTag;
98 void resolveProxy(const QString &hostName, quint16 port);
99#else
100 inline void resolveProxy(const QString &, quint16) { }
101#endif
102 inline void resolveProxy(quint16 port) { resolveProxy(QString(), port); }
103
104 void resetSocketLayer();
105 virtual bool flush();
106
107 bool initSocketLayer(QAbstractSocket::NetworkLayerProtocol protocol);
108 virtual void configureCreatedSocket();
109 void startConnectingByName(const QString &host);
110 void fetchConnectionParameters();
111 bool readFromSocket();
112 virtual bool writeToSocket();
113 void emitReadyRead(int channel = 0);
114 void emitBytesWritten(qint64 bytes, int channel = 0);
115
116 void setError(QAbstractSocket::SocketError errorCode, const QString &errorString);
117 void setErrorAndEmit(QAbstractSocket::SocketError errorCode, const QString &errorString);
118
119 qint64 readBufferMaxSize = 0;
120 bool isBuffered = false;
121 bool hasPendingData = false;
122 bool hasPendingDatagram = false;
123
124 quint32 bytesWrittenEmissionCount = 0;
125
126 QTimer *connectTimer = nullptr;
127
128 int hostLookupId = -1;
129
130 QAbstractSocket::SocketType socketType = QAbstractSocket::UnknownSocketType;
131 QAbstractSocket::SocketState state = QAbstractSocket::UnconnectedState;
132
133 // Must be kept in sync with QIODevicePrivate::errorString.
134 QAbstractSocket::SocketError socketError = QAbstractSocket::UnknownSocketError;
135
136 QAbstractSocket::NetworkLayerProtocol preferredNetworkLayerProtocol =
137 QAbstractSocket::UnknownNetworkLayerProtocol;
138
139 bool prePauseReadSocketNotifierState = false;
140 bool prePauseWriteSocketNotifierState = false;
141 bool prePauseExceptionSocketNotifierState = false;
142 static void pauseSocketNotifiers(QAbstractSocket*);
143 static void resumeSocketNotifiers(QAbstractSocket*);
144 static QAbstractSocketEngine* getSocketEngine(QAbstractSocket*);
145};
146
147QT_END_NAMESPACE
148
149#endif // QABSTRACTSOCKET_P_H
Combined button and popup list for selecting options.
static bool isProxyError(QAbstractSocket::SocketError error)
#define QABSTRACTSOCKET_BUFFERSIZE