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
58 virtual bool canReadNotification();
59 bool canWriteNotification();
60 void canCloseNotification();
61
62 // slots
63 void _q_connectToNextAddress();
64 void _q_startConnecting(const QHostInfo &hostInfo);
65 void _q_testConnection();
66 void _q_abortConnectionAttempt();
67
68 bool emittedReadyRead = false;
69 bool emittedBytesWritten = false;
70
71 bool abortCalled = false;
72 bool pendingClose = false;
73
74 QAbstractSocket::PauseModes pauseMode = QAbstractSocket::PauseNever;
75
76 QString hostName;
77 quint16 port = 0;
78 QHostAddress host;
79 QList<QHostAddress> addresses;
80
81 quint16 localPort = 0;
82 quint16 peerPort = 0;
83 QHostAddress localAddress;
84 QHostAddress peerAddress;
85 QString peerName;
86
87 QAbstractSocketEngine *socketEngine = nullptr;
88 qintptr cachedSocketDescriptor = -1;
89
90#ifndef QT_NO_NETWORKPROXY
91 QNetworkProxy proxy;
92 QNetworkProxy proxyInUse;
93 QString protocolTag;
94 void resolveProxy(const QString &hostName, quint16 port);
95#else
96 inline void resolveProxy(const QString &, quint16) { }
97#endif
98 inline void resolveProxy(quint16 port) { resolveProxy(QString(), port); }
99
100 void resetSocketLayer();
101 virtual bool flush();
102
103 bool initSocketLayer(QAbstractSocket::NetworkLayerProtocol protocol);
104 virtual void configureCreatedSocket();
105 void startConnectingByName(const QString &host);
106 void fetchConnectionParameters();
107 bool readFromSocket();
108 virtual bool writeToSocket();
109 void emitReadyRead(int channel = 0);
110 void emitBytesWritten(qint64 bytes, int channel = 0);
111
112 void setError(QAbstractSocket::SocketError errorCode, const QString &errorString);
113 void setErrorAndEmit(QAbstractSocket::SocketError errorCode, const QString &errorString);
114
115 qint64 readBufferMaxSize = 0;
116 bool isBuffered = false;
117 bool hasPendingData = false;
118 bool hasPendingDatagram = false;
119
120 quint32 bytesWrittenEmissionCount = 0;
121
122 QTimer *connectTimer = nullptr;
123
124 int hostLookupId = -1;
125
126 QAbstractSocket::SocketType socketType = QAbstractSocket::UnknownSocketType;
127 QAbstractSocket::SocketState state = QAbstractSocket::UnconnectedState;
128
129 // Must be kept in sync with QIODevicePrivate::errorString.
130 QAbstractSocket::SocketError socketError = QAbstractSocket::UnknownSocketError;
131
132 QAbstractSocket::NetworkLayerProtocol preferredNetworkLayerProtocol =
133 QAbstractSocket::UnknownNetworkLayerProtocol;
134
135 bool prePauseReadSocketNotifierState = false;
136 bool prePauseWriteSocketNotifierState = false;
137 bool prePauseExceptionSocketNotifierState = false;
138 static void pauseSocketNotifiers(QAbstractSocket*);
139 static void resumeSocketNotifiers(QAbstractSocket*);
140 static QAbstractSocketEngine* getSocketEngine(QAbstractSocket*);
141};
142
143QT_END_NAMESPACE
144
145#endif // QABSTRACTSOCKET_P_H
Combined button and popup list for selecting options.
static bool isProxyError(QAbstractSocket::SocketError error)
#define QABSTRACTSOCKET_BUFFERSIZE